Commit Graph

658 Commits

Author SHA1 Message Date
Akim Demaille
eeb2942237 Simplify the i18n of the error messages.
* data/lalr1.cc: Comment changes.
	* data/yacc.c (yysyntax_error): Rewrite, using a switch as in
	lalr1.cc instead of building dynamically the format string.
2008-12-11 10:45:52 +01:00
Akim Demaille
2ca1136c7c Update data/README.
* data/README: Document glr.cc, lalr1.java, m4sugar and xslt.
2008-12-08 09:47:35 +01:00
Akim Demaille
6c63b895fb Install autoconf as a submodule to get m4sugar.
* .gitmodules: Add submodules/autoconf.
	* data/m4sugar/foreach.m4, data/m4sugar/m4sugar.m4: Now links into
	submodules/autoconf.
2008-12-08 09:47:31 +01:00
Akim Demaille
417e31d2c3 Test token.prefix in all the skeletons.
* data/java.m4 (b4_token_enum): Use the token.prefix.
	* tests/local.at (AT_BISON_OPTION_PUSHDEFS): Define AT_TOKEN_PREFIX.
	* tests/calc.at (_AT_DATA_CALC_Y): Use it.
	Add checks for yacc.c, glr.c, lalr1.cc and glr.cc.
	* tests/java.at: Comment changes.
	(AT_CHECK_JAVA_MINIMAL): Define the END token.
	(Java parser class and package names): Add token.prefix check.
2008-12-08 09:47:26 +01:00
Akim Demaille
3bb211139b Use b4_symbol for printers and destructors everywhere.
* data/bison.m4 (b4_symbol_action_location): New.
	* data/c.m4 (b4_symbol_actions): Remove.
	Adjust all callers to use by b4_symbol_foreach and the corresponding
	b4_symbol_printer/destructor macro.
	* data/glr.cc: Adjust.
	* data/lalr1.java: Adjust the %destructor sanity check.
	* src/output.c (symbol_code_props_output): Remove, we no longer
	need the b4_symbol_printers/destructors tables.
2008-12-01 22:32:33 +01:00
Akim Demaille
fb7c5b1f23 Use b4_symbol_case_.
* data/lalr1.cc, data/bison.m4 (b4_symbol_action): Use
	b4_symbol_case_.
2008-12-01 22:29:20 +01:00
Akim Demaille
cf6fb2226d Move b4_symbol based macro to bison.m4.
* data/lalr1.cc (b4_symbol_, b4_symbol, b4_symbol_if)
	(b4_symbol_action, b4_symbol_destructor, b4_symbol_printer)
	(b4_symbol_case_, b4_symbol_foreach, b4_type_action_)
	(b4_type_foreach): Move to...
	* data/bison.m4: Here.
	* data/lalr1.cc (b4_symbol_action): Specialize for C++: use
	b4_symbol_value_template instead of b4_symbol_value.

s b4_symbols in bison.m4
2008-12-01 22:25:51 +01:00
Akim Demaille
e3c52a6362 b4_symbol/type_foreach.
* data/lalr1.cc (b4_symbol_foreach, b4_type_foreach): New.
	Use them.
2008-12-01 22:22:35 +01:00
Akim Demaille
2bde91138d Use the symbol properties to output the printer/destructor for lalr1.cc.
Instead of defining complex list of tuples to define various properties of
the symbols, we now prefer to define symbols as "structs" in m4: using the
symbol key (its number), and the property name, b4_symbol gives it value.
Use this to handle destructors and printers.

	* src/output.c (CODE_PROP): New.
	(prepare_symbol_definitions): Use it to define the printer and
	destructor related attributes of the symbols.
	* data/lalr1.cc (b4_symbol_actions): Rename as...
	(b4_symbol_action): this.
	Use b4_symbol instead of 6 arguments.
	(b4_symbol_printer, b4_symbol_destructor): New.
	Use them instead of b4_symbol_actions.
2008-12-01 22:19:11 +01:00
Akim Demaille
fad814bd0c Remove spurious empty line before syncline.
* data/bison.m4 (b4_syncline): Don't output an empty line before
	the output.
2008-12-01 22:11:50 +01:00
Akim Demaille
728e89a09b Use b4_parser_tables_define in glr.cc.
* data/glr.c: Use b4_parser_tables_define instead of defining the
	(deterministic integral) tables by hand.
2008-11-26 10:11:46 +01:00
Akim Demaille
2c1bf9bd68 Use b4_parser_tables_define in Java.
* data/java.m4 (b4_typed_parser_table): Rename as...
	(b4_typed_parser_table_define): this, for consistency.
	Accept a comment as $4.
	Move $2 into yy*_.
	(b4_integral_parser_table): Rename as...
	(b4_integral_parser_table_define): this.
	* data/lalr1.java: Adjust all uses.
	Use b4_parser_tables_define instead of generation by hand.
2008-11-26 10:08:41 +01:00
Akim Demaille
ba206cf40a Prepare the convergence bw C style and Java table generation.
* data/bison.m4 (b4_tables_map, b4_tables_declare)
	(b4_tables_define): Rename as...
	(b4_integral_parser_tables_map, b4_parser_tables_declare)
	(b4_parser_tables_define): these.
	* data/c.m4 (b4_table_define): Rename as...
	(b4_integral_parser_table_define): this.
	* data/lalr1.cc: Adjust.
	(b4_table_define, b4_table_declare): Rename as...
	(b4_integral_parser_table_define)
	(b4_integral_parser_table_declare): these.
	(yyrline_): Move the comment where it is actually used.
	* data/yacc.c: Adjust.
	(yyrline): Use b4_integral_parser_table_define.
2008-11-26 10:05:20 +01:00
Akim Demaille
0991e29b75 Factor the generation of the (integral) tables bw yacc.c and lalr1.cc.
* data/lalr1.cc (b4_tables_map): Move to...
	* data/bison.m4: here.
	Update the comment for yytable during the flight.
	(b4_tables_declare, b4_tables_define): New.
	* data/lalr1.cc: Use them.
	* data/c.m4 (b4_table_define): New.
	* data/yacc.c: Use b4_tables_define instead of output the tables
	by hand.
	* tests/regression.at (Web2c Actions): Adjust the expected output,
	the order of the tables changed.
2008-11-26 09:58:50 +01:00
Akim Demaille
932b0c960a Get rid of lalr1-split.cc.
It was no longer maintainer.

	* data/lalr1-split.cc: Remove.
	* etc/bench.pl.in (bench_fusion_parser): Remove.
	Adjust.
2008-11-26 09:48:24 +01:00
Akim Demaille
8452c667e6 Use yy* consistently.
* data/glr.c: Now that yyrhs no longer exists as a global
	variable, rename local "rhs" variables into "yyrhs" for
	consistency.
2008-11-26 09:44:21 +01:00
Akim Demaille
783aa653f4 Get rid of yyrhs and yyprhs in glr.c.
* data/glr.c (yyrhs, yyprhs): Remove.
	Instead, use the state stack and yystos.
2008-11-25 23:11:34 +01:00
Akim Demaille
b4f1840114 Get rid of yyrhs and yyprhs in larl1.java.
* data/lalr1.java (yyrhs_, yyprhs_): Remove.
	(yy_reduce_print): Rather, use yystos_ and the state stack.
2008-11-25 22:50:10 +01:00
Akim Demaille
68dbdee86a Get rid of yyrhs and yyprhs in yacc.c.
They were used to get the symbol types, given a rule number,  when
displaying the top of the stack before a reduction.  But the symbol type
is available from the state stack.  This has two be benefits: two tables
less in the parser (making it smaller), and a more consistent use of the
three stacks which will help to fuse them.

	* data/yacc.c (yyprhs, yyrhs): Remove.
	(YY_REDUCE_PRINT): Pass yyssp to yy_reduce_print.
	(yy_reduce_print): Take yyssp as argument.
	Use it, together with yystos, to get the symbol type.
	* tests/regression.at (Web2c Report): Remove these tables from the
	expected output.
2008-11-25 22:21:24 +01:00
Akim Demaille
6ab1adbe1e b4_tables_map.
The point is to factor the generation of the tables across skeletons.
This is language dependant.

	* data/c.m4 (b4_comment_): New.
	Should be usable to define how to generate tables independently of
	the language.
	(b4_c_comment): New.
	(b4_comment): Bounce to b4_c_comment.
	Now support $2 = [PREFIX] for indentation.
	* data/lalr1.cc (b4_table_declare): Don't output a comment if
	there is no comment.
	Indent it properly when there is one.
	Output the ending semicolon.
	(b4_table_define): Space changes.
	Output the ending semicolon.
	(b4_tables_map): New.
	Use it twice instead of declaring and defining the (integral)
	tables by hand.
2008-11-25 22:18:09 +01:00
Akim Demaille
0fddb3d59f b4_table_declare.
* data/lalr1.cc (b4_table_declare): New.
	Use it to declare the tables defined with b4_table_define.
	(b4_table_define): Declare a third arg to match b4_table_declare
	signature.
	Move all the comments around invocations of b4_table_define into
	the invocations itselves.
	Move things around to have the order for declarations and
	definitions.
2008-11-25 22:14:39 +01:00
Akim Demaille
c4ddc0fb0b Formatting changes.
* data/lalr1.java: here.
2008-11-25 22:11:09 +01:00
Akim Demaille
e0c653e7e6 b4_args is more general than only C++.
* data/lalr1.cc (b4_args, _b4_args): Move to...
	* data/bison.m4: here.
2008-11-25 22:07:23 +01:00
Joel E. Denny
6c88b51e83 Fix unexpanded macros in GLR defines file.
Reported by Csaba Raduly at
<http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00048.html>.
* THANKS (Csaba Raduly): Add.
* data/glr.c: Fix overquoting on b4_prefix for yylval and yylloc.
* tests/calc.at (_AT_DATA_CALC_Y): If %defines is specified, generate
lexer in a separate module that includes the defines file.
(AT_CHECK_CALC): From AT_FULL_COMPILE, request compilation of lexer
source.
* tests/local.at (_AT_BISON_OPTION_PUSHDEFS): Push AT_DEFINES_IF.
Adjust AT_LOC and AT_VAL to use AT_NAME_PREFIX.
(AT_BISON_OPTION_POPDEFS): Pop AT_DEFINES_IF.
(AT_DATA_SOURCE_PROLOGUE): New.
(AT_DATA_GRAMMAR_PROLOGUE): Use AT_DATA_SOURCE_PROLOGUE.
(AT_DATA_SOURCE): New.
(AT_FULL_COMPILE): Extend to support an additional source file.
2008-11-19 00:24:34 -05:00
Akim Demaille
bd187d7b65 Use b4_subtract where possible.
* data/lalr1.cc (b4_subtract): Move to...
	* data/bison.m4: here.
	* data/glr.c (b4_rhs_data): Use it.
	* data/yacc.c (b4_rhs_value, b4_rhs_location): Use it.
2008-11-18 20:57:26 +01:00
Akim Demaille
6085ab0d78 Remove incorrect mode specification.
* data/glr.cc: Don't pretend it's C code.
2008-11-18 20:53:21 +01:00
Akim Demaille
c5fc95d688 Update ignores.
* data/.cvsignore, data/.gitignore, examples/.cvsignore,
	* examples/.gitignore:
	Remove.
	* build-aux/.cvsignore, build-aux/.gitignore, doc/.cvsignore,
	* doc/.gitignore, etc/.cvsignore, etc/.gitignore, src/.cvsignore,
	* src/.gitignore, tests/.cvsignore, tests/.gitignore:
	Remove MAkefile and Makefile.in.
2008-11-16 19:46:16 +01:00
Akim Demaille
cb823b6f0c Support parametric types.
There are two issues to handle: first scanning nested angle bracket pairs
to support types such as std::pair< std::string, std::list<std::string> > >.

Another issue is to address idiosyncracies of C++: do not glue two closing
angle brackets together (otherwise it's operator>>), and avoid sticking
blindly a TYPE to the opening <, as it can result in '<:' which is a
digraph for '['.

	* src/scan-gram.l (brace_level): Rename as...
	(nesting): this.
	(SC_TAG): New.
	Implement support for complex tags.
	(tag): Accept \n, but not <.
	* data/lalr1.cc (b4_symbol_value, b4_symbol_value_template)
	(b4_symbol_variant): Leave space around types as parameters.
	* examples/variant.yy: Use nested template types and leading ::.
	* src/parse-gram.y (TYPE, TYPE_TAG_ANY, TYPE_TAG_NONE, type.opt):
	Rename as...
	(TAG, TAG_ANY, TAG_NONE, tag.opt): these.
	* tests/c++.at: Test parametric types.
2008-11-15 14:30:05 +01:00
Akim Demaille
7d3e21ba7b Formatting change. 2008-11-15 14:20:28 +01:00
Akim Demaille
b0d79ec65d Comment changes.
* data/local.mk, etc/local.mk, examples/local.mk: Use Automake
	comments for the license.
2008-11-15 11:23:53 +01:00
Akim Demaille
6a5aa0cdbb Remove data/Makefile.am.
* data/Makefile.am: Rename as...
	* data/local.mk: this.
	Adjust paths.
	* Makefile.am, configure.ac: Adjust.
2008-11-15 10:39:38 +01:00
Akim Demaille
0634493cdd Provide convenience constructors for locations and positions.
* data/location.cc (position::position): Accept file, line and
	column as arguments with default values.
	Always qualify initial line and column literals as unsigned.
	(location::location): Provide convenience constructors.
2008-11-15 10:23:51 +01:00
Akim Demaille
fe1b448ada Instead of using make_symbol<TOK_FOO>, generate make_FOO for each token type.
Using template buys us nothing, and makes it uselessly complex to
construct a symbol.  Besides, it could not be generalized to other
languages, while make_FOO would work in C/Java etc.

	* data/lalr1.cc (b4_symbol_): New.
	(b4_symbol): Use it.
	(b4_symbol_constructor_declaration_)
	(b4_symbol_constructor_definition_): Instead of generating
	specializations of an overloaded template function, just generate
	several functions whose names are forged from the token names
	without the token.prefix.
	(b4_symbol_constructor_declarations): Generate them for all the
	symbols, not just by class of symbol type, now that instead of
	specializing a function template by the token, we generate a
	function named after the token.
	(b4_symbol_constructor_specialization_)
	(b4_symbol_constructor_specializations): Remove.
	* etc/bench.pl.in: Adjust to this new API.
2008-11-15 10:20:02 +01:00
Akim Demaille
5679f31101 %define token.prefix.
Provide a means to add a prefix to the name of the tokens as output in the
generated files.  Because of name clashes, it is good to have such a
prefix such as TOK_ that protects from names such as EOF, FILE etc.
But it clutters the grammar itself.

	* data/bison.m4 (token.prefix): Empty by default.
	* data/c.m4 (b4_token_enum, b4_token_define): Use it.
	* data/lalr1.cc (b4_symbol): Ditto.
2008-11-13 07:08:24 +01:00
Akim Demaille
3204049e31 Compute at M4 time some of the subtractions.
* data/lalr1.cc (b4_substract): New.
	(b4_rhs_data): Use it.
2008-11-13 07:04:47 +01:00
Akim Demaille
202598d3ab symbol::token.
This is allows the user to get the type of a token return by
yylex.

	* data/lalr1.cc (symbol::token): New.
	(yytoknum_): Define when %define lex_symbol, independently of
	%debug.
	(yytoken_number_): Move into...
	(symbol::token): here, since that's the only use.
	The other one is YYPRINT which was not officially supported
	by lalr1.cc, and anyway it did not work since YYPRINT uses this
	array under a different name (yytoknum).
2008-11-13 07:01:41 +01:00
Akim Demaille
cb0b136a63 Comment changes.
* data/lalr1.cc, data/yacc.c: Fix the description of the
	yytranslate and yytoknum tables.
2008-11-13 06:52:05 +01:00
Akim Demaille
2c086d2959 Define make_symbol in the header.
To reach good performances these functions should be inlined (yet this is
to measure precisely).  To this end they must be available to the caller.

	* data/lalr1.cc (b4_symbol_constructor_definition_): Qualify
	location_type with the class name.
	Since will now be output in the header, declare "inline".
	No longer use b4_symbol_constructor_specializations, but
	b4_symbol_constructor_definitions in the header.
	Don't call it in the *.cc file.
2008-11-13 06:48:22 +01:00
Akim Demaille
1c4af3813e Define yytranslate in the header for lex_symbol.
* data/lalr1.cc: Move the invocation of b4_yytranslate_definition
	into the header file when using %define lex_symbol.
	(yytranslate_): Declare inline.
2008-11-13 06:44:50 +01:00
Akim Demaille
e51b0a82be Define the constructors of symbol_type in b4_symbol_constructor_definitions.
The constructors are called by the make_symbol functions, which a
forthcoming patch will move elsewhere.  Hence the interest of putting them
together.

The stack_symbol_type does not need to be moved, it is used only by the
parser.

	* data/lalr1.cc: Move symbol_type and symbol_base_type
	constructors into...
	(b4_symbol_constructor_definitions): here.
	Adjust.
2008-11-13 06:41:42 +01:00
Akim Demaille
788355718f Make it easier to move the definition of yytranslate_.
Forthcoming changes will make it possible to use yytranslate_
from outside the parser implementation file.

	* data/lalr1.cc (b4_yytranslate_definition): New.
	Use it.
2008-11-13 06:36:51 +01:00
Akim Demaille
c1e6c88ca3 Remove useless class specification.
* data/lalr1.cc (b4_symbol_constructor_specialization_): No need
	to refer to the class name to use a type defined by the class for
	arguments of member functions.
2008-11-13 06:33:51 +01:00
Akim Demaille
4654b0c0a8 Finer input type for yytranslate.
This patch is debatable: the tradition expects yylex to return an int
which happens to correspond to token_number (which is an enum).  This
allows for instance to return characters (such as '*' etc.).  But this
goes against the stronger typing I am trying to have with the new
lex interface which return a symbol_type.  So in this case, feed
yytranslate_ with a token_type.

	* data/lalr1.cc (yytranslate_): When in %define lex-symbol,
	expect a token_type.
2008-11-13 06:30:35 +01:00
Akim Demaille
dd735e4ee6 Honor lex-params in %define lex_symbol mode.
* data/lalr1.cc: Use b4_lex_param.
2008-11-13 06:27:15 +01:00
Akim Demaille
6659366cda Simplify names.
* src/output.c (symbol_definitions_output): Rename symbol
	attributes type_name and has_type_name as type and has_type.
	* data/lalr1.cc: Adjust uses.
2008-11-13 06:24:01 +01:00
Akim Demaille
e9805e5743 Use b4_type_names for the union type.
The union used to compute the size of the variant used to iterate over the
type of all the symbols, with a lot of redundancy.  Now iterate over the
lists of symbols having the same type-name.

	* data/lalr1.cc (b4_char_sizeof_): New.
	(b4_char_sizeof): Use it.
	Adjust to be called with a list of numbers instead of a single
	number.
	Adjust its caller for new-line issues.
2008-11-13 06:20:59 +01:00
Akim Demaille
aea10ef46f Define the "identifier" of a symbol.
Symbols may have several string representations, for instance if they
have an alias.  What I call its "id" is a string that can be used as
an identifier.  May not exist.

Currently the symbols which have the "tag_is_id" flag set are those that
don't have an alias.  Look harder for the id.

	* src/output.c (is_identifier): Move to...
	* src/symtab.c (is_identifier): here.
	* src/symtab.h, src/symtab.c (symbol_id_get): New.
	* src/output.c (symbol_definitions_output): Use it to define "id"
	and "has_id".
	Remove the definition of "tag_is_id".
	* data/lalr1.cc: Use the "id" and "has_id" whereever "tag" and
	"tag_is_id" were used to produce code.
	We still use "tag" for documentation.
2008-11-13 06:17:09 +01:00
Akim Demaille
2ea7730c56 Locations are no longer required by lalr1.cc.
* data/lalr1.cc (_b4_args, b4_args): New.
	Adjust all uses of locations to make them optional.
	* tests/c++.at (AT_CHECK_VARIANTS): No longer use the locations.
	(AT_CHECK_NAMESPACE): Check the use of locations.
	* tests/calc.at (_AT_DATA_CALC_Y): Adjust to be usable with or
	without locations with lalr1.cc.
	Test these cases.
	* tests/output.at: Check lalr1.cc with and without location
	support.
	* tests/regression.at (_AT_DATA_EXPECT2_Y, _AT_DATA_DANCER_Y):
	Don't use locations.
2008-11-11 16:38:10 +01:00
Akim Demaille
c944f7f22d Simplify lalr1.cc since %defines is mandatory.
* data/lalr1.cc: Remove useless calls to b4_defines_if.
2008-11-11 16:05:29 +01:00
Akim Demaille
422c18f48d Prefer M4 to CPP.
* data/lalr1.cc: Use b4_error_verbose_if instead of #if
	YYERROR_VERBOSE.
2008-11-11 15:59:05 +01:00