Related articles |
---|
Simple yacc translator kanagala@Cadence.COM (Raja Kanagala) (1999-11-19) |
Re: Simple yacc translator adonovan@imerge.co.uk (Alan Donovan) (1999-11-23) |
Re: Simple yacc translator zalman@netcom11.netcom.com (Zalman Stern) (1999-11-28) |
From: | Alan Donovan <adonovan@imerge.co.uk> |
Newsgroups: | comp.compilers |
Date: | 23 Nov 1999 00:35:33 -0500 |
Organization: | Imerge Ltd. |
References: | 99-11-110 |
Keywords: | yacc, parse |
Raja Kanagala wrote:
> *begin
> A and B and C
> D and E and f
> *end
> A and B and C
> D and E and f
>
> I would like it to translate to:
> A*B*C
> D*E*F
> (A and B and C)
> (D and E and f)
>
> How can I set rules for the yacc parser to do a set of actions when
> enclosed by "*begin" and "*end". Kind of a state machine.
>
> [Set a flag in the begin and end rules in your lexer or parser, test
> it in the action code for the "A and B" rules and do one thing or the
> other. -John]
If you want the actual syntax to change during begin/end, you should
use start states. You will find examples of these on how to parse
C-style comments from within lex. So, you would enter a different
start state at "begin", enter the normal start state at "end" and have
different lexical rules during your new start state.
alan
------------------------------------------------------------------------
Alan Donovan adonovan@imerge.co.uk http://www.imerge.co.uk
Imerge Ltd. +44 1223 875265
[Uh, lex has start states, yacc doesn't. But you can certainly use lex
start states to make the lexer return different tokens that will match
different parser rules. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.