[patch 8/8] Replace Yacc parser with recursive descent parser
Ian Lance Taylor
iant@google.com
Wed Mar 21 05:24:00 GMT 2007
Zack Weinberg <zackw@panix.com> writes:
> * gengtype-parse.c: New file.
> * gengtype-yacc.y: Delete.
> * gengtype-lex.l: Don't include gengtype-yacc.h.
> Define YY_DECL and yyterminate appropriately for recursive
> descent parser. yylval is now a string out-parameter to yylex.
> (HWS, EOID): New shorthand.
> (IWORD): Add a couple more types.
> (yylex): Add a setup stanza. Remove the complex rules for
> detecting GTY'ed types and typedefs; replace with simple
> keyword detectors. Adjust everything for the changed
> definition of yylval. Ignore all pp-directives, not just #define.
> (yyerror): Delete.
> (parse_file): Rename yybegin; do not call yyparse.
> (yyend): New.
> * gengtype.c (xasprintf): Export again.
> (this_file): New. Use everywhere __FILE__ was being used.
> (get_lang_bitmap): Special case types defined in gengtype.c.
> (do_typedef, new_structure): Suppress definition of certain types.
> (new_structure): Improve diagnostics of duplicate definitions.
> Make sure location_s is associated with input.h.
> (nreverse_pairs, define_location_structures): New functions.
> (main): Improve tagging of kludge types. Remove old kludges
> for input.h types; use define_location_structures.
> * gengtype.h: Update prototypes. Define token codes here.
> * Makefile.in: Remove all references to gengtype-yacc.
> Add rules for gengtype-parse.o. Adjust rules for gengtype-lex.o
> and gengtype.
>
> * bitmap.h (struct bitmap_head_def): Coalesce definitions,
> add GTY((skip)) to the field that's only conditionally there.
Several functions in gentype-parse.c need comments.
> +static const char *
> +print_token (int code, const char *value)
The comment on this function should mention that it is a space leak,
and that it doesn't matter.
> +#ifdef USE_MAPPED_LOCATION
> + fields = create_field (0, &scalar_nonchar, "column");
> + fields = create_field (fields, &scalar_nonchar, "line");
> + fields = create_field (fields, &string_type, "file");
> + locs = new_structure ("anon:expanded_location", 0, &pos, fields, 0);
> +
> + do_typedef ("expanded_location", locs, &pos);
> + do_scalar_typedef ("location_t", &pos);
> + do_scalar_typedef ("source_locus", &pos);
> +#else
> + fields = create_field (0, &scalar_nonchar, "line");
> + fields = create_field (fields, &string_type, "file");
> + locs = new_structure ("location_s", 0, &pos, fields, 0);
> +
> + do_typedef ("expanded_location", locs, &pos);
> + do_typedef ("location_t", locs, &pos);
> + do_typedef ("source_locus", create_pointer (locs), &pos);
> +#endif
Please add a comment where these structures are defined indicating
that any change to them requires a change to this file.
OK with those changes.
Thanks for tackling this.
Ian
More information about the Gcc-patches
mailing list