I'm currently writing some lex/yacc code to interpret somebodies
"made up" langugage, in which much source code has already been written.
This "language" features a primitive type of scope on a "per file" basis.
This is to say that the language specification allows source files
to include other source files. A variable is valid in the source file in
which it is declared and in any child source files included by it.
I intended to utilize the yywrap() function in lex to detect when I
hit EOF upon a source file and using a primitive form of stack, redirect
input to the file which included the source file that we have just run out of.
This would have meant that yacc just got one stream of tokens and was
blissfully oblivious to which source files the input tokens were actually
However, upon EOF of an included file, I wish to rid myself of those symbols
within a symbol table ( well, list of defined variables anyway ;-) ) which
had been declared within that source file ( the symbol table is to be
stored and manipulated in yacc ).
I had hoped to "sort of" insert a "END_OF_BLOCK" token into the
stream of input tokens from lex to yacc each time that I returned from an
included file to it's parent file.
To my understanding, yacc calls lex ( yyparse() ) for each token it wishes
to process, so my question is "Can I force-feed yacc() extra tokens from
Is there another way around this problem that my lack of experience with
lex and yacc hasn't revealed to me yet? Can I simulate putting extra
characters into the source input character stream upon hitting EOF of
an included file ( these extra characters being some special token I can
recognise and then inform lex that I have found )?
I'd like to avoid "messy" solutions such as preprocessing the source files
to place extra text at the end of the input source files. I'm really aiming
to implement this entirely in lex adn yacc if possible.
Any help would be appreciated, please keep in mind that I'm no expert on
this subject. I don't have much access to network news ( I'm actually
telnetting to a machine in Perth, Australia to send you this ), so could you
is a non-trivial problem, maybe you'd like to post a response to this
newsgroup as well.
Comsys Int'l, Australia
| David Young, Software engineer, Comsys, Perth, Western Australia |