> Le 11 févr. 2019 à 22:23, Peng Yu <[email protected]> a écrit : > > Hi, > > Since flex does lexical analysis which is before parsing, logically, > it should be that bison includes output from flex. > > But the reality is flex using y.tab.h generated by bison which > reverses the dependency relation. This looks weird. > > Why is it so?
Because bison (the program, not the generated parsers) knows things the scanner needs: the enum of the tokens, the type of locations, the type of the semantics values. Bison needs them. Flex needs nothing. Actually, you could just as well use Flex as a powerful sed: the concept of token is not required in Flex. Then, the scanner of course needs the bits about the tokens. So the *.y file is the primary repository about your grammar (rules, but also declaration of tokens, nonterminals and types), which passes this to the scanner (not to Flex). Of course there's one pain point: the parser needs the declaration of the scanner (yylex). _______________________________________________ [email protected] https://lists.gnu.org/mailman/listinfo/help-bison
