Commit Graph

238 Commits

Author SHA1 Message Date
Akim Demaille
5f5a90dff6 Coding style changes.
* data/lalr1.cc (b4_symbol_constructor_declaration_)
	(b4_symbol_constructor_declarations)
	(b4_symbol_constructor_definition_)
	(b4_symbol_constructor_definitions)
	(b4_yytranslate_definition): Rename as...
	(b4_symbol_constructor_declare_)
	(b4_symbol_constructor_declare)
	(b4_symbol_constructor_define_)
	(b4_symbol_constructor_define)
	(b4_yytranslate_define): these.
	* data/variant.hh (b4_variant_definition): Rename as...
	(b4_variant_define): this.
2009-03-02 16:24:21 +01:00
Akim Demaille
b47b6ff7fd Factor b4_assert_if, b4_lex_symbol_if, and b4_variant_if.
* data/bison.m4 (b4_percent_define_if_define): New.
	* data/c++.m4 (b4_variant_if): Move to...
	* data/bison.m4: Here, using b4_percent_define_if_define.
	* data/lalr1.cc (b4_assert_if, b4_lex_symbol_if): Move to...
	* data/bison.m4: Here, using b4_percent_define_if_define.
2009-03-02 16:20:26 +01:00
Akim Demaille
1d6b689b26 Dub symbol_type_base as a public type.
* data/c++.m4 (b4_public_types_declare): Now define
	symbol_type_base and symbol_type.
	(b4_public_types_define): New.
	In both cases, the definitions are taken verbatim from lalr1.cc.
	* data/lalr1.cc: Adjust.
2009-03-02 16:15:28 +01:00
Akim Demaille
4f84717d23 b4_public_types_declare.
* data/c++.m4 (b4_public_types_declare): New.
	* data/glr.cc, data/lalr1.cc: Use it.
2009-03-02 16:12:11 +01:00
Akim Demaille
b9e4eb5b72 b4_semantic_type_declare.
* data/c++.m4 (b4_semantic_type_declare): New.
	Factors and generalizes what was in glr.cc and lalr1.cc.
	* data/variant.hh (b4_semantic_type_declare): Redefine it for
	variants.
	* data/lalr1.cc, data/glr.cc: Use it.
2009-03-02 16:08:07 +01:00
Akim Demaille
3eead995a4 Comment changes.
* data/lalr1.cc: here.
2009-02-25 23:41:40 +01:00
Akim Demaille
33c78bd23e Comment change.
* data/lalr1.cc: here.
2009-02-25 23:28:15 +01:00
Akim Demaille
49572920dd Make yyparser::error public.
* data/lalr1.cc: here.
	There is no good reason to keep it private (and it is convenient
	to use it from the scanner for instance).  It is already public in
	glr.cc.
2009-02-19 22:16:19 +01:00
Akim Demaille
9c6a89660e Comment changes.
* data/lalr1.cc: here.
2009-02-19 21:58:13 +01:00
Akim Demaille
507aa0e2a8 Extract variant.hh
* data/variant.hh: New, extracted from...
	* data/lalr1.cc: here.
	Adjust.
	* data/local.mk: Adjust.
2009-02-19 21:53:58 +01:00
Akim Demaille
51bacae6b5 Extract stack.hh from lalr1.cc.
* data/stack.hh: New.
	* data/lalr1.cc: Extract from here.
	* data/local.mk: Adjust.
2009-02-19 21:49:46 +01:00
Samuel Tardieu
253192e69a Force a large alignment of a variant structure.
This is a temporary band-aid until Bison gets proper alignment handling.
We need it on ARM.

	* data/lalr1.cc (variant): Declare the buffer as a union to force
	the same alignment as "long double".
2009-01-28 15:46:05 +01:00
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
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
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
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
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
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
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
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
Akim Demaille
a0ffc1751e Support i18n of the parse error messages.
* TODO (lalr1.cc/I18n): Remove.
	* data/lalr1.cc (yysyntax_error_): Support the translation of the
	error messages, as done in yacc.c.
	Stay within the yy* pseudo namespace.
2008-11-11 15:55:54 +01:00
Akim Demaille
0927787504 Make it possible to return a symbol_type from yylex.
* data/lalr1.cc (b4_lex_symbol_if): New.
	(parse): When lex_symbol is defined, expected yylex to return the
	complete lookahead.
	* etc/bench.pl.in (generate_grammar_list): Extend to support this
	yylex interface.
	(bench_variant_parser): Exercise it.
2008-11-11 15:48:52 +01:00
Akim Demaille
39be90223b Replace yychar with a Boolean.
* data/lalr1.cc (parse::yychar): Replace by...
	(parse::yyempty): this.
2008-11-11 15:36:23 +01:00
Akim Demaille
aba12ad162 Let yytranslate handle the eof case.
* data/lalr1.cc (yytranslate_): Handle the EOF case.
	Adjust callers.
	No longer expect yychar to be equal to yyeof_, rather, test the
	lookahead's (translated) kind.
2008-11-11 15:29:39 +01:00
Akim Demaille
27cb5b5901 yychar cannot be empty in yyerrlab.
* TODO (yychar == yyempty_): New.
	* data/lalr1.cc: Remove the handling of this case.
	This eases forthcoming changes related to yychar and yytranslate.
2008-11-11 15:26:17 +01:00
Akim Demaille
2873fdf8b1 Introduce make_symbol.
make_symbol provides a means to construct a full symbol (kind, value,
location) in a single shot.  It is meant to be a Symbol constructor,
parameterized by the symbol kind so that overloading would prevent
incorrect kind/value pairs.  Unfortunately parameterized constructors do
not work well in C++ (unless the parameter also appears as an argument,
which is not acceptable), hence the use of a function instead of a
constructor.

	* data/lalr1.cc (b4_symbol_constructor_declaration_)
	(b4_symbol_constructor_declarations)
	(b4_symbol_constructor_specialization_)
	(b4_symbol_constructor_specializations)
	(b4_symbol_constructor_definition_)
	(b4_symbol_constructor_definitions): New.
	Use them where appropriate to generate declaration, declaration of
	the specializations, and implementations of the templated
	overloaded function "make_symbol".
	(variant::variant): Always define a default ctor.
	Also provide a copy ctor.
	(symbol_base_type, symbol_type): New ctor overloads for value-less
	symbols.
	(symbol_type): Now public, so that functions such as yylex can use
	it.
2008-11-11 15:16:53 +01:00
Akim Demaille
247efe346c Formatting changes. 2008-11-10 12:01:19 +01:00
Akim Demaille
5d73144067 More information about the symbols.
* src/output.c (type_names_output): Document all the symbols,
	including those that don't have a type-name.
	(symbol_definitions_output): Define "is_token" and
	"has_type_name".
	* data/lalr1.cc (b4_type_action_): Skip symbols that have an empty
	type-name, now that they are defined too in b4_type_names.
2008-11-10 11:58:01 +01:00