help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why flex uses y.tab.h?


From: Akim Demaille
Subject: Re: Why flex uses y.tab.h?
Date: Tue, 12 Feb 2019 06:44:38 +0100


> Le 11 févr. 2019 à 22:23, Peng Yu <address@hidden> 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).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]