Prototype support of %lex-param and %parse-param.

* src/parse-gram.y: Add the definition of the %lex-param and
%parse-param tokens, plus their rules.
Drop the `_' version of %glr-parser.
Add the "," token.
* src/scan-gram.l (INITIAL): Scan them.
* src/muscle_tab.c: Comment changes.
(muscle_insert, muscle_find): Rename `pair' as `probe'.
* src/muscle_tab.h (MUSCLE_INSERT_PREFIX): Remove unused.
(muscle_entry_s): The `value' member is no longer const.
Adjust all dependencies.
* src/muscle_tab.c (muscle_init): Adjust: use
MUSCLE_INSERT_STRING.
Initialize the obstack earlier.
* src/muscle_tab.h, src/muscle_tab.c (muscle_grow)
(muscle_pair_list_grow): New.
* data/c.m4 (b4_c_function_call, b4_c_args): New.
* data/yacc.c (YYLEX): Use b4_c_function_call to honor %lex-param.
* tests/calc.at: Use %locations, not --locations.
(AT_CHECK_CALC_GLR): Use %glr-parser, not %glr_parser.
This commit is contained in:
Akim Demaille
2002-10-19 14:38:06 +00:00
parent 0e57572183
commit ae7453f2ba
13 changed files with 1322 additions and 1140 deletions

View File

@@ -1,3 +1,27 @@
2002-10-19 Akim Demaille <akim@epita.fr>
Prototype support of %lex-param and %parse-param.
* src/parse-gram.y: Add the definition of the %lex-param and
%parse-param tokens, plus their rules.
Drop the `_' version of %glr-parser.
Add the "," token.
* src/scan-gram.l (INITIAL): Scan them.
* src/muscle_tab.c: Comment changes.
(muscle_insert, muscle_find): Rename `pair' as `probe'.
* src/muscle_tab.h (MUSCLE_INSERT_PREFIX): Remove unused.
(muscle_entry_s): The `value' member is no longer const.
Adjust all dependencies.
* src/muscle_tab.c (muscle_init): Adjust: use
MUSCLE_INSERT_STRING.
Initialize the obstack earlier.
* src/muscle_tab.h, src/muscle_tab.c (muscle_grow)
(muscle_pair_list_grow): New.
* data/c.m4 (b4_c_function_call, b4_c_args): New.
* data/yacc.c (YYLEX): Use b4_c_function_call to honor %lex-param.
* tests/calc.at: Use %locations, not --locations.
(AT_CHECK_CALC_GLR): Use %glr-parser, not %glr_parser.
2002-10-19 Akim Demaille <akim@epita.fr> 2002-10-19 Akim Demaille <akim@epita.fr>
* src/getargs.c (usage): Take status as argument and exit * src/getargs.c (usage): Take status as argument and exit

12
TODO
View File

@@ -5,6 +5,18 @@
From Franc,ois: should we keep the directory part in the CPP guard? From Franc,ois: should we keep the directory part in the CPP guard?
* readpipe
It should be replaced to avoid tmp files and to improve portability.
Also, as it is it does not call error () when execve fails, and
therefore, running M4='m4 --version' bison will silently fail instead
of:
bison: cannot run m4 --version: No such file or directory
BTW: I would really like to be able to pass arguments to m4...
* URGENT: Documenting C++ output * URGENT: Documenting C++ output
Write a first documentation for C++ output. Write a first documentation for C++ output.

View File

@@ -1,4 +1,4 @@
m4_divert(-1) -*- C -*- m4_divert(-1) *- Autoconf -*-
# C M4 Macros for Bison. # C M4 Macros for Bison.
# Copyright (C) 2002 Free Software Foundation, Inc. # Copyright (C) 2002 Free Software Foundation, Inc.
@@ -122,13 +122,36 @@ m4_map([b4_token_define], [$@])
]) ])
## --------------------- ##
## Calling C functions. ##
## --------------------- ##
# b4_c_function_call(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
# -----------------------------------------------------------
# Call the function NAME with arguments NAME1, NAME2 etc.
m4_define([b4_c_function_call],
[$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
])
# b4_c_args([TYPE1, NAME1], ...)
# ------------------------------
# Output the arguments NAME1, NAME2...
m4_define([b4_c_args],
[m4_map_sep([b4_c_arg], [, ], [$@])])
m4_define([b4_c_arg],
[$2])
## ---------------------------------------------- ## ## ---------------------------------------------- ##
## Declaring C functions in both K&R and ANSI-C. ## ## Declaring C functions in both K&R and ANSI-C. ##
## ---------------------------------------------- ## ## ---------------------------------------------- ##
# b4_c_function(NAME, RETURN-VALUE, [TYPE1, NAME1], ...) # b4_c_function(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
# ------------------------------------------------ # ------------------------------------------------------
# Declare the function NAME. # Declare the function NAME.
m4_define([b4_c_function], m4_define([b4_c_function],
[$2 [$2

View File

@@ -506,13 +506,14 @@ while (0)
/* YYLEX -- calling `yylex' with the right arguments. */ /* YYLEX -- calling `yylex' with the right arguments. */
b4_pure_if( #ifdef YYLEX_PARAM
[#ifdef YYLEX_PARAM # define YYLEX yylex (b4_pure_if([&yylval[]b4_location_if([, &yylloc]), ])YYLEX_PARAM)
# define YYLEX yylex (&yylval[]b4_location_if([, &yylloc]), YYLEX_PARAM)
#else #else
# define YYLEX yylex (&yylval[]b4_location_if([, &yylloc])) # define YYLEX b4_c_function_call([yylex],
#endif], b4_pure_if([[[[]], [[&yylval]]],
[#define YYLEX yylex ()]) b4_location_if([[[], [&yylloc]],])])
m4_fst(b4_lex_param))
#endif
/* Enable debugging if requested. */ /* Enable debugging if requested. */
#if YYDEBUG #if YYDEBUG

View File

@@ -1,4 +1,4 @@
/* Macro table manager for Bison, /* Muscle table manager for Bison,
Copyright (C) 2001, 2002 Free Software Foundation, Inc. Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -56,31 +56,31 @@ hash_muscle (const void *x, unsigned int tablesize)
void void
muscle_init (void) muscle_init (void)
{ {
/* Initialize the muscle obstack. */
obstack_init (&muscle_obstack);
muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
hash_compare_muscles, free); hash_compare_muscles, free);
/* Version and input file. */ /* Version and input file. */
muscle_insert ("version", VERSION); MUSCLE_INSERT_STRING ("version", VERSION);
muscle_insert ("filename", infile); MUSCLE_INSERT_STRING ("filename", infile);
/* FIXME: there should probably be no default here, only in the /* FIXME: there should probably be no default here, only in the
skeletons. */ skeletons. */
/* Types. */ /* Types. */
muscle_insert ("ltype", "yyltype"); MUSCLE_INSERT_STRING ("ltype", "yyltype");
/* Default #line formatting. */ /* Default #line formatting. */
muscle_insert ("linef", "#line %d %s\n"); MUSCLE_INSERT_STRING ("linef", "#line %d %s\n");
/* Stack parameters. */ /* Stack parameters. */
muscle_insert ("maxdepth", "10000"); MUSCLE_INSERT_STRING ("maxdepth", "10000");
muscle_insert ("initdepth", "200"); MUSCLE_INSERT_STRING ("initdepth", "200");
/* C++ macros. */ /* C++ macros. */
muscle_insert ("name", "Parser"); MUSCLE_INSERT_STRING ("name", "Parser");
/* Initialize the muscle obstack. */
obstack_init (&muscle_obstack);
} }
@@ -97,14 +97,19 @@ muscle_free (void)
/*------------------------------------------------------------.
| Insert (KEY, VALUE). If KEY already existed, overwrite the |
| previous value. |
`------------------------------------------------------------*/
void void
muscle_insert (const char *key, const char *value) muscle_insert (const char *key, char *value)
{ {
muscle_entry_t pair; muscle_entry_t probe;
muscle_entry_t *entry = NULL; muscle_entry_t *entry = NULL;
pair.key = key; probe.key = key;
entry = hash_lookup (muscle_table, &pair); entry = hash_lookup (muscle_table, &probe);
if (!entry) if (!entry)
{ {
@@ -116,32 +121,99 @@ muscle_insert (const char *key, const char *value)
entry->value = value; entry->value = value;
} }
const char*
/*-------------------------------------------------------------------.
| Insert (KEY, VALUE). If KEY already existed, overwrite the |
| previous value. Uses MUSCLE_OBSTACK. De-allocates the previously |
| associated value. VALUE and SEPARATOR are copied. |
`-------------------------------------------------------------------*/
void
muscle_grow (const char *key, const char *val, const char *separator)
{
muscle_entry_t probe;
muscle_entry_t *entry = NULL;
probe.key = key;
entry = hash_lookup (muscle_table, &probe);
if (!entry)
{
/* First insertion in the hash. */
entry = XMALLOC (muscle_entry_t, 1);
entry->key = key;
hash_insert (muscle_table, entry);
entry->value = xstrdup (val);
}
else
{
/* Grow the current value. */
char *new_val;
fprintf (stderr, "<= %s + %s\n", entry->value, val);
obstack_sgrow (&muscle_obstack, entry->value);
free (entry->value);
obstack_sgrow (&muscle_obstack, separator);
obstack_sgrow (&muscle_obstack, val);
obstack_1grow (&muscle_obstack, 0);
new_val = obstack_finish (&muscle_obstack);
entry->value = xstrdup (new_val);
fprintf (stderr, "=> %s\n", new_val);
obstack_free (&muscle_obstack, new_val);
}
}
/*-------------------------------------------------------------------.
| MUSCLE is an M4 list of pairs. Create or extend it with the pair |
| (A1, A2). Note that because the muscle values are output *double* |
| quoted, one needs to strip the first level of quotes to reach the |
| list itself. |
`-------------------------------------------------------------------*/
void muscle_pair_list_grow (const char *muscle,
const char *a1, const char *a2)
{
char *value;
obstack_fgrow2 (&muscle_obstack, "[[[%s]], [[%s]]]", a1, a2);
obstack_1grow (&muscle_obstack, 0);
value = obstack_finish (&muscle_obstack);
muscle_grow (muscle, value, ",\n");
obstack_free (&muscle_obstack, value);
}
/*-------------------------------.
| Find the value of muscle KEY. |
`-------------------------------*/
char*
muscle_find (const char *key) muscle_find (const char *key)
{ {
muscle_entry_t pair; muscle_entry_t probe;
muscle_entry_t *result = NULL; muscle_entry_t *result = NULL;
pair.key = key; probe.key = key;
result = hash_lookup (muscle_table, &pair); result = hash_lookup (muscle_table, &probe);
return result ? result->value : NULL; return result ? result->value : NULL;
} }
/* Output the definition of all the current muscles into a list of /*------------------------------------------------.
m4_defines. */ | Output the definition of ENTRY as a m4_define. |
`------------------------------------------------*/
static int static int
muscle_m4_output (muscle_entry_t *entry, FILE *out) muscle_m4_output (muscle_entry_t *entry, FILE *out)
{ {
fprintf (out, "m4_define([b4_%s],\n", entry->key); fprintf (out, "m4_define([b4_%s],\n", entry->key);
fprintf (out, " [[%s]])\n\n\n", entry->value); fprintf (out, "[[%s]])\n\n\n", entry->value);
return 1; return 1;
} }
/* Output the definition of all the current muscles into a list of /*----------------------------------------------------------------.
m4_defines. */ | Output the definition of all the current muscles into a list of |
| m4_defines. |
`----------------------------------------------------------------*/
void void
muscles_m4_output (FILE *out) muscles_m4_output (FILE *out)

View File

@@ -1,4 +1,4 @@
/* Definitions for macrotab.c and callers, part of bison, /* Muscle table manager for Bison,
Copyright (C) 2001, 2002 Free Software Foundation, Inc. Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler. This file is part of Bison, the GNU Compiler Compiler.
@@ -21,17 +21,15 @@
#ifndef MUSCLE_TAB_H_ #ifndef MUSCLE_TAB_H_
# define MUSCLE_TAB_H_ # define MUSCLE_TAB_H_
# define MTABSIZE 101
typedef struct muscle_entry_s typedef struct muscle_entry_s
{ {
const char *key; const char *key;
const char *value; char *value;
} muscle_entry_t; } muscle_entry_t;
void muscle_init PARAMS ((void)); void muscle_init PARAMS ((void));
void muscle_insert PARAMS ((const char *key, const char *value)); void muscle_insert PARAMS ((const char *key, char *value));
const char *muscle_find PARAMS ((const char *key)); char *muscle_find PARAMS ((const char *key));
void muscle_free PARAMS ((void)); void muscle_free PARAMS ((void));
@@ -59,14 +57,27 @@ extern struct obstack muscle_obstack;
muscle_insert (Key, obstack_finish (&muscle_obstack)); \ muscle_insert (Key, obstack_finish (&muscle_obstack)); \
} }
#define MUSCLE_INSERT_PREFIX(Key, Value) \ #define MUSCLE_GROW_STRING_PAIR(Key, Value1, Value2) \
{ \ { \
obstack_fgrow2 (&muscle_obstack, "%s%s", \ obstack_sgrow (&muscle_obstack, Value1); \
spec_name_prefix ? spec_name_prefix : "yy", Value); \ obstack_1grow (&muscle_obstack, 0); \
obstack_1grow (&muscle_obstack, 0); \ muscle_insert (Key, obstack_finish (&muscle_obstack)); \
muscle_insert (Key, obstack_finish (&muscle_obstack)); \
} }
/* Insert (KEY, VALUE). If KEY already existed, overwrite the
previous value. Uses MUSCLE_OBSTACK. De-allocates the previously
associated value. VALUE and SEPARATOR are copied. */
void muscle_grow PARAMS ((const char *key,
const char *value, const char *separator));
/* MUSCLE is an M4 list of pairs. Create or extend it with the pair
(A1, A2). Note that because the muscle values are output *double*
quoted, one needs to strip the first level of quotes to reach the
list itself. */
void muscle_pair_list_grow PARAMS ((const char *muscle,
const char *a1, const char *a2));
void muscles_m4_output PARAMS ((FILE *out)); void muscles_m4_output PARAMS ((FILE *out));

View File

@@ -355,9 +355,9 @@ merger_output (FILE *out)
fputs ("]])\n\n", out); fputs ("]])\n\n", out);
} }
/*---------------------------------------. /*--------------------------------------.
| Output the tokens definition to OOUT. | | Output the tokens definition to OUT. |
`---------------------------------------*/ `--------------------------------------*/
static void static void
token_definitions_output (FILE *out) token_definitions_output (FILE *out)
@@ -405,9 +405,9 @@ token_definitions_output (FILE *out)
} }
/*----------------------------------------. /*---------------------------------------.
| Output the symbol destructors to OOUT. | | Output the symbol destructors to OUT. |
`----------------------------------------*/ `---------------------------------------*/
static void static void
symbol_destructors_output (FILE *out) symbol_destructors_output (FILE *out)
@@ -438,9 +438,9 @@ symbol_destructors_output (FILE *out)
} }
/*-------------------------------------. /*------------------------------------.
| Output the symbol printers to OOUT. | | Output the symbol printers to OUT. |
`-------------------------------------*/ `------------------------------------*/
static void static void
symbol_printers_output (FILE *out) symbol_printers_output (FILE *out)
@@ -456,7 +456,7 @@ symbol_printers_output (FILE *out)
/* Filename, lineno, /* Filename, lineno,
Symbol-name, Symbol-number, Symbol-name, Symbol-number,
destructor, typename. */ printer, typename. */
fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]", fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
first ? "" : ",\n", first ? "" : ",\n",
infile, symbol->printer_location.first_line, infile, symbol->printer_location.first_line,

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
/* A Bison parser, made from parse-gram.y, by GNU bison 1.49c. */ /* A Bison parser, made from parse-gram.y, by GNU bison 1.75a. */
/* Skeleton parser for Yacc-like parsing with Bison, /* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
@@ -28,7 +28,7 @@
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
# if defined (__STDC__) || defined (__cplusplus) # define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers /* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */ know about them. */
enum yytokentype { enum yytokentype {
@@ -45,41 +45,41 @@
PERCENT_LEFT = 267, PERCENT_LEFT = 267,
PERCENT_RIGHT = 268, PERCENT_RIGHT = 268,
PERCENT_NONASSOC = 269, PERCENT_NONASSOC = 269,
PERCENT_EXPECT = 270, PERCENT_PREC = 270,
PERCENT_START = 271, PERCENT_DPREC = 271,
PERCENT_PREC = 272, PERCENT_MERGE = 272,
PERCENT_DPREC = 273, PERCENT_DEBUG = 273,
PERCENT_MERGE = 274, PERCENT_DEFINE = 274,
PERCENT_VERBOSE = 275, PERCENT_DEFINES = 275,
PERCENT_ERROR_VERBOSE = 276, PERCENT_ERROR_VERBOSE = 276,
PERCENT_OUTPUT = 277, PERCENT_EXPECT = 277,
PERCENT_FILE_PREFIX = 278, PERCENT_FILE_PREFIX = 278,
PERCENT_NAME_PREFIX = 279, PERCENT_GLR_PARSER = 279,
PERCENT_DEFINE = 280, PERCENT_LEX_PARAM = 280,
PERCENT_PURE_PARSER = 281, PERCENT_LOCATIONS = 281,
PERCENT_GLR_PARSER = 282, PERCENT_NAME_PREFIX = 282,
PERCENT_DEFINES = 283, PERCENT_NO_LINES = 283,
PERCENT_YACC = 284, PERCENT_OUTPUT = 284,
PERCENT_DEBUG = 285, PERCENT_PARSE_PARAM = 285,
PERCENT_LOCATIONS = 286, PERCENT_PURE_PARSER = 286,
PERCENT_NO_LINES = 287, PERCENT_SKELETON = 287,
PERCENT_SKELETON = 288, PERCENT_START = 288,
PERCENT_TOKEN_TABLE = 289, PERCENT_TOKEN_TABLE = 289,
TYPE = 290, PERCENT_VERBOSE = 290,
EQUAL = 291, PERCENT_YACC = 291,
SEMICOLON = 292, TYPE = 292,
COLON = 293, EQUAL = 293,
PIPE = 294, SEMICOLON = 294,
ID = 295, COLON = 295,
PERCENT_PERCENT = 296, COMMA = 296,
PROLOGUE = 297, PIPE = 297,
EPILOGUE = 298, ID = 298,
BRACED_CODE = 299 PERCENT_PERCENT = 299,
PROLOGUE = 300,
EPILOGUE = 301,
BRACED_CODE = 302
}; };
# endif #endif
/* POSIX requires `int' for tokens in interfaces. */
# define YYTOKENTYPE int
#endif /* !YYTOKENTYPE */
#define GRAM_EOF 0 #define GRAM_EOF 0
#define STRING 258 #define STRING 258
#define CHARACTER 259 #define CHARACTER 259
@@ -93,36 +93,39 @@
#define PERCENT_LEFT 267 #define PERCENT_LEFT 267
#define PERCENT_RIGHT 268 #define PERCENT_RIGHT 268
#define PERCENT_NONASSOC 269 #define PERCENT_NONASSOC 269
#define PERCENT_EXPECT 270 #define PERCENT_PREC 270
#define PERCENT_START 271 #define PERCENT_DPREC 271
#define PERCENT_PREC 272 #define PERCENT_MERGE 272
#define PERCENT_DPREC 273 #define PERCENT_DEBUG 273
#define PERCENT_MERGE 274 #define PERCENT_DEFINE 274
#define PERCENT_VERBOSE 275 #define PERCENT_DEFINES 275
#define PERCENT_ERROR_VERBOSE 276 #define PERCENT_ERROR_VERBOSE 276
#define PERCENT_OUTPUT 277 #define PERCENT_EXPECT 277
#define PERCENT_FILE_PREFIX 278 #define PERCENT_FILE_PREFIX 278
#define PERCENT_NAME_PREFIX 279 #define PERCENT_GLR_PARSER 279
#define PERCENT_DEFINE 280 #define PERCENT_LEX_PARAM 280
#define PERCENT_PURE_PARSER 281 #define PERCENT_LOCATIONS 281
#define PERCENT_GLR_PARSER 282 #define PERCENT_NAME_PREFIX 282
#define PERCENT_DEFINES 283 #define PERCENT_NO_LINES 283
#define PERCENT_YACC 284 #define PERCENT_OUTPUT 284
#define PERCENT_DEBUG 285 #define PERCENT_PARSE_PARAM 285
#define PERCENT_LOCATIONS 286 #define PERCENT_PURE_PARSER 286
#define PERCENT_NO_LINES 287 #define PERCENT_SKELETON 287
#define PERCENT_SKELETON 288 #define PERCENT_START 288
#define PERCENT_TOKEN_TABLE 289 #define PERCENT_TOKEN_TABLE 289
#define TYPE 290 #define PERCENT_VERBOSE 290
#define EQUAL 291 #define PERCENT_YACC 291
#define SEMICOLON 292 #define TYPE 292
#define COLON 293 #define EQUAL 293
#define PIPE 294 #define SEMICOLON 294
#define ID 295 #define COLON 295
#define PERCENT_PERCENT 296 #define COMMA 296
#define PROLOGUE 297 #define PIPE 297
#define EPILOGUE 298 #define ID 298
#define BRACED_CODE 299 #define PERCENT_PERCENT 299
#define PROLOGUE 300
#define EPILOGUE 301
#define BRACED_CODE 302
@@ -136,8 +139,8 @@ typedef union {
char *string; char *string;
assoc_t assoc; assoc_t assoc;
} yystype; } yystype;
/* Line 1294 of /usr/local/share/bison/yacc.c. */ /* Line 1281 of /usr/local/share/bison/yacc.c. */
#line 141 "y.tab.h" #line 144 "y.tab.h"
# define YYSTYPE yystype # define YYSTYPE yystype
#endif #endif

View File

@@ -113,36 +113,42 @@ braced_code_t current_braced_code = action_braced_code;
%token PERCENT_RIGHT "%right" %token PERCENT_RIGHT "%right"
%token PERCENT_NONASSOC "%nonassoc" %token PERCENT_NONASSOC "%nonassoc"
%token PERCENT_EXPECT "%expect"
%token PERCENT_START "%start"
%token PERCENT_PREC "%prec" %token PERCENT_PREC "%prec"
%token PERCENT_DPREC "%dprec" %token PERCENT_DPREC "%dprec"
%token PERCENT_MERGE "%merge" %token PERCENT_MERGE "%merge"
%token PERCENT_VERBOSE "%verbose"
%token PERCENT_ERROR_VERBOSE "%error-verbose"
%token PERCENT_OUTPUT "%output"
%token PERCENT_FILE_PREFIX "%file-prefix"
%token PERCENT_NAME_PREFIX "%name-prefix"
%token PERCENT_DEFINE "%define" /*----------------------.
%token PERCENT_PURE_PARSER "%pure-parser" | Global Declarations. |
%token PERCENT_GLR_PARSER "%glr-parser" `----------------------*/
%token PERCENT_DEFINES "%defines" %token
PERCENT_DEBUG "%debug"
%token PERCENT_YACC "%yacc" PERCENT_DEFINE "%define"
PERCENT_DEFINES "%defines"
%token PERCENT_DEBUG "%debug" PERCENT_ERROR_VERBOSE "%error-verbose"
%token PERCENT_LOCATIONS "%locations" PERCENT_EXPECT "%expect"
%token PERCENT_NO_LINES "%no-lines" PERCENT_FILE_PREFIX "%file-prefix"
%token PERCENT_SKELETON "%skeleton" PERCENT_GLR_PARSER "%glr-parser"
%token PERCENT_TOKEN_TABLE "%token-table" PERCENT_LEX_PARAM "%lex-param"
PERCENT_LOCATIONS "%locations"
PERCENT_NAME_PREFIX "%name-prefix"
PERCENT_NO_LINES "%no-lines"
PERCENT_OUTPUT "%output"
PERCENT_PARSE_PARAM "%parse-param"
PERCENT_PURE_PARSER "%pure-parser"
PERCENT_SKELETON "%skeleton"
PERCENT_START "%start"
PERCENT_TOKEN_TABLE "%token-table"
PERCENT_VERBOSE "%verbose"
PERCENT_YACC "%yacc"
;
%token TYPE "type" %token TYPE "type"
%token EQUAL "=" %token EQUAL "="
%token SEMICOLON ";" %token SEMICOLON ";"
%token COLON ":" %token COLON ":"
%token COMMA ","
%token PIPE "|" %token PIPE "|"
%token ID "identifier" %token ID "identifier"
%token PERCENT_PERCENT "%%" %token PERCENT_PERCENT "%%"
@@ -186,12 +192,16 @@ declaration:
| "%error-verbose" { error_verbose = 1; } | "%error-verbose" { error_verbose = 1; }
| "%expect" INT { expected_conflicts = $2; } | "%expect" INT { expected_conflicts = $2; }
| "%file-prefix" "=" string_content { spec_file_prefix = $3; } | "%file-prefix" "=" string_content { spec_file_prefix = $3; }
| "%glr-parser" { glr_parser = 1; }
| "%lex-param" string_content "," string_content
{ muscle_pair_list_grow ("lex_param", $2, $4); }
| "%locations" { locations_flag = 1; } | "%locations" { locations_flag = 1; }
| "%name-prefix" "=" string_content { spec_name_prefix = $3; } | "%name-prefix" "=" string_content { spec_name_prefix = $3; }
| "%no-lines" { no_lines_flag = 1; } | "%no-lines" { no_lines_flag = 1; }
| "%output" "=" string_content { spec_outfile = $3; } | "%output" "=" string_content { spec_outfile = $3; }
| "%parse-param" string_content "," string_content
{ muscle_pair_list_grow ("parse_param", $2, $4); }
| "%pure-parser" { pure_parser = 1; } | "%pure-parser" { pure_parser = 1; }
| "%glr-parser" { glr_parser = 1; }
| "%skeleton" string_content { skeleton = $2; } | "%skeleton" string_content { skeleton = $2; }
| "%token-table" { token_table_flag = 1; } | "%token-table" { token_table_flag = 1; }
| "%verbose" { report_flag = 1; } | "%verbose" { report_flag = 1; }

File diff suppressed because it is too large Load Diff

View File

@@ -126,7 +126,7 @@ blanks [ \t\f]+
"%expect" return PERCENT_EXPECT; "%expect" return PERCENT_EXPECT;
"%file-prefix" return PERCENT_FILE_PREFIX; "%file-prefix" return PERCENT_FILE_PREFIX;
"%fixed"[-_]"output"[-_]"files" return PERCENT_YACC; "%fixed"[-_]"output"[-_]"files" return PERCENT_YACC;
"%glr"[-_]"parser" return PERCENT_GLR_PARSER; "%glr-parser" return PERCENT_GLR_PARSER;
"%left" return PERCENT_LEFT; "%left" return PERCENT_LEFT;
"%locations" return PERCENT_LOCATIONS; "%locations" return PERCENT_LOCATIONS;
"%merge" return PERCENT_MERGE; "%merge" return PERCENT_MERGE;
@@ -135,10 +135,12 @@ blanks [ \t\f]+
"%nonassoc" return PERCENT_NONASSOC; "%nonassoc" return PERCENT_NONASSOC;
"%nterm" return PERCENT_NTERM; "%nterm" return PERCENT_NTERM;
"%output" return PERCENT_OUTPUT; "%output" return PERCENT_OUTPUT;
"%parse-param" return PERCENT_PARSE_PARAM;
"%prec" { rule_length--; return PERCENT_PREC; } "%prec" { rule_length--; return PERCENT_PREC; }
"%printer" return PERCENT_PRINTER; "%printer" return PERCENT_PRINTER;
"%pure"[-_]"parser" return PERCENT_PURE_PARSER; "%pure"[-_]"parser" return PERCENT_PURE_PARSER;
"%right" return PERCENT_RIGHT; "%right" return PERCENT_RIGHT;
"%lex-param" return PERCENT_LEX_PARAM;
"%skeleton" return PERCENT_SKELETON; "%skeleton" return PERCENT_SKELETON;
"%start" return PERCENT_START; "%start" return PERCENT_START;
"%term" return PERCENT_TOKEN; "%term" return PERCENT_TOKEN;
@@ -152,6 +154,7 @@ blanks [ \t\f]+
"=" return EQUAL; "=" return EQUAL;
":" { rule_length = 0; return COLON; } ":" { rule_length = 0; return COLON; }
"|" { rule_length = 0; return PIPE; } "|" { rule_length = 0; return PIPE; }
"," return COMMA;
";" return SEMICOLON; ";" return SEMICOLON;
{eols} YY_LINES; YY_STEP; {eols} YY_LINES; YY_STEP;

View File

@@ -354,7 +354,7 @@ AT_DATA([[expout]],
[$4 [$4
]) ])
# 3. If locations are not used, remove them. # 3. If locations are not used, remove them.
m4_bmatch([$1], [--location], [], m4_bmatch([$1], [%locations], [],
[[sed 's/^[-0-9.]*: //' expout >at-expout [[sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout]]) mv at-expout expout]])
# 4. If error-verbose is not used, strip the`, unexpected....' part. # 4. If error-verbose is not used, strip the`, unexpected....' part.
@@ -451,18 +451,18 @@ m4_define([AT_CHECK_CALC_LALR],
AT_CHECK_CALC_LALR() AT_CHECK_CALC_LALR()
AT_CHECK_CALC_LALR([--defines]) AT_CHECK_CALC_LALR([--defines])
AT_CHECK_CALC_LALR([--locations]) AT_CHECK_CALC_LALR([%locations])
AT_CHECK_CALC_LALR([--name-prefix=calc]) AT_CHECK_CALC_LALR([--name-prefix=calc])
AT_CHECK_CALC_LALR([--verbose]) AT_CHECK_CALC_LALR([--verbose])
AT_CHECK_CALC_LALR([--yacc]) AT_CHECK_CALC_LALR([--yacc])
AT_CHECK_CALC_LALR([%error-verbose]) AT_CHECK_CALC_LALR([%error-verbose])
AT_CHECK_CALC_LALR([%error-verbose --locations]) AT_CHECK_CALC_LALR([%error-verbose %locations])
AT_CHECK_CALC_LALR([%error-verbose --defines --locations --name-prefix=calc --verbose --yacc]) AT_CHECK_CALC_LALR([%error-verbose --defines %locations --name-prefix=calc --verbose --yacc])
AT_CHECK_CALC_LALR([%debug]) AT_CHECK_CALC_LALR([%debug])
AT_CHECK_CALC_LALR([%error-verbose %debug --defines --locations --name-prefix=calc --verbose --yacc]) AT_CHECK_CALC_LALR([%error-verbose %debug --defines %locations --name-prefix=calc --verbose --yacc])
# ----------------------- # # ----------------------- #
@@ -476,21 +476,21 @@ AT_BANNER([[Simple GLR Calculator.]])
# Start a testing chunk which compiles `calc' grammar with # Start a testing chunk which compiles `calc' grammar with
# BISON-OPTIONS and %glr-parser, and performs several tests over the parser. # BISON-OPTIONS and %glr-parser, and performs several tests over the parser.
m4_define([AT_CHECK_CALC_GLR], m4_define([AT_CHECK_CALC_GLR],
[AT_CHECK_CALC([%glr_parser] $@)]) [AT_CHECK_CALC([%glr-parser] $@)])
AT_CHECK_CALC_GLR() AT_CHECK_CALC_GLR()
AT_CHECK_CALC_GLR([--defines]) AT_CHECK_CALC_GLR([--defines])
AT_CHECK_CALC_GLR([--locations]) AT_CHECK_CALC_GLR([%locations])
AT_CHECK_CALC_GLR([--name-prefix=calc]) AT_CHECK_CALC_GLR([--name-prefix=calc])
AT_CHECK_CALC_GLR([--verbose]) AT_CHECK_CALC_GLR([--verbose])
AT_CHECK_CALC_GLR([--yacc]) AT_CHECK_CALC_GLR([--yacc])
AT_CHECK_CALC_GLR([%error-verbose]) AT_CHECK_CALC_GLR([%error-verbose])
AT_CHECK_CALC_GLR([%error-verbose --locations]) AT_CHECK_CALC_GLR([%error-verbose %locations])
AT_CHECK_CALC_GLR([%error-verbose --defines --locations --name-prefix=calc --verbose --yacc]) AT_CHECK_CALC_GLR([%error-verbose --defines %locations --name-prefix=calc --verbose --yacc])
AT_CHECK_CALC_GLR([%debug]) AT_CHECK_CALC_GLR([%debug])
AT_CHECK_CALC_GLR([%error-verbose %debug --defines --locations --name-prefix=calc --verbose --yacc]) AT_CHECK_CALC_GLR([%error-verbose %debug --defines %locations --name-prefix=calc --verbose --yacc])