Frans Englich wrote: > On Tuesday 14 June 2005 11:36, Akim Demaille wrote: > >>>>>"Frans" == Frans Englich <[EMAIL PROTECTED]> writes: >> >> > >> > I would prefer to do this at the Bison/Parser level because it is >> > convenient: I have access to various information passed to the >> > parse function, >> >>You can easily make them available to the scanner. And in fact, you >>probably should, to have a clean, pure, interface bw the two. > > > Ok, not fully following here, what you mean with "make them available to the > scanner". > [snip] > Hm, then have error handling been placed in the scanner, which confuses me > with respect to "You can easily make them available to the scanner. And in > fact, you probably should, to have a clean, pure, interface bw the > two."(assuming my interpretation is correct).
What Akim meant is that whatever information you pass to the parser should also be passed down to the lexer. Example: => in parserctx.h: struct my_parse_context { bool comments_allowed; }; => parser invocation: ... struct my_parse_context pc; fooparse(&pc); ... => in foo.y: %{ ... #include "parserctx.h" ... %} %parse-param {my_parse_context* context} %lex-param {my_parse_context* context} ... => in foo.l: %{ ... #include "parserctx.h" #define YY_DECL int yylex(my_parse_context* context) ... %} ... %% {COMMENT} { if (!context->comments_allowed) { /* alternative: yyerror() and exit() if this is a fatal problem */ REJECT; } } This way it becomes easy to pass information from the caller to parser & lexer, and/or between lexer and parser. It also avoids using global variables for such purposes, which keeps things thread-safe. _______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison