how does one pass args to yyparse and yylex?
Martin Weitzel
martin at mwtech.UUCP
Fri Feb 1 10:47:45 AEST 1991
In article <1991Jan25.172631.15595 at cs.mcgill.ca> dean at cs.mcgill.ca (Dean NEWTON) writes:
>Two questions regarding yacc and lex:
>
>1) How does one pass args to yyparse and yylex from a C program?
If you are the only user on your development, i.e. you use a
workstation, you may be able to change the scanner/parser sceletton
(you'll find them in "/usr/lib/lex/ncform" and "/usr/lib/yaccpar")
>2) How can one declare local variables in yyparse and yylex?
This is only feasable for lex. Right at the start of the second part
(i.e. after the first %%-line) you can place arbitrary C-source between
two lines containing %{ and %}. This source makes it right into yylex,
at the point AFTER its own local declarations and BEFORE its first statement.
Hence you can declare your own local variables there AND you can put
some statements here which are executed once every time yylex() is
called. (I sometimes use this to save and reset start conditions.)
For yacc I have still to find an easy way. (Good designed programs/grammars
may be able to avoid the need for many locals by making clever use of the
value stack.)
--
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83
More information about the Comp.lang.c
mailing list