Hi, The more I study flex/bison, the more confused I got about when to use what actions and what to put in lexer and what to put in grammar.
For example, for an assignment, x=10 it can be processed by the lexer, [[:alpha:]_][[:alnum:]_]=[[:digit:]+] { /* parse yytext to get the name and value, then do the assignment */ } or use these lex rules %x ASSIGNMENT %% [[:alpha:]_][[:alnum:]_]= { BEGIN(ASSIGNMENT); /*save varaible name*/ } <ASSIGNMENT>[[:digit:]]+ { /* get the value and assign to the saved variable name*/ BEGIN(INITIAL); } Alternatively, the lexer can just do [[:alpha:]_][[:alnum:]_] { /*save name somewhere for bison use */ return TOK_NAME; } = { return '='; } [[:digit:]+] { /*save value somwhere for bison use*/ return TOK_VALUE; } Then, bison grammar can be something like this. assignment: TOK_NAME '=' TOK_VALUE { /*do the assignment */} There just seem to be too many possible ways of implementations. Could anybody let me know how to decide which implementation to use in practical scenarios? -- Regards, Peng _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison