Re: Lexers in YACC?

Michael K. Gschwind <vlsivie!mike@relay.EU.net>
Mon, 10 Sep 90 15:44:06 MST

          From comp.compilers

Related articles
Lexers in YACC? cowan@marob.masa.com (1990-09-05)
Re: Lexers in YACC? vlsivie!mike@relay.EU.net (Michael K. Gschwind) (1990-09-10)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Michael K. Gschwind <vlsivie!mike@relay.EU.net>
In-Reply-To: <26E50E36.34BE@marob.masa.com>
Keywords: yacc, lex
Organization: none
Date: Mon, 10 Sep 90 15:44:06 MST

In article <26E50E36.34BE@marob.masa.com> you write:
>What I don't understand is how to make the generated parser of the first
>stage "return" tokens to its caller. It seems to require generalized
>co-routines, which of course C does not provide. The operating system is
>Unix System V.


No, you don't want to do this. Rather, I would queue the tokens, insert
magic tokens (which make the grammar LALR(1)) and after the first stage
call the second. Sequence works fine as long as there is no interaction.
In the above scenario, there is no need for interaction.


BTW, in many cases, lex is powerful enough to make a grammar lalr(1)
with right context rules. You want to look into these. If these aren't
sufficient, you could use start states as well.
E.g., if you have to differentiate between function definitions,
function declarations and variable dfinitions in C, you could use:


%%
{identifier}/\([^)]\) return FUNCTION_DEFINITION;
{identifier}/\([^)]\); return FUNCTION_DECLARATION;
{identifier} return VARIABLE;


%%


bye,
mike


Michael K. Gschwind mike@vlsivie.at
Institute for VLSI-Design mike@vlsivie.uucp
Technical University, Vienna e182202@awituw01.bitnet
Voice: (++43).1.58801 8144 Fax: (++43).1.569697
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.