Related articles |
---|
dumb: make yacc tolerate "extra" stuff in a file tdeckard@vitalimages.com (1999-08-22) |
Re: dumb: make yacc tolerate "extra" stuff in a file scinar@my-deja.com (1999-08-27) |
From: | tdeckard@vitalimages.com |
Newsgroups: | comp.compilers |
Date: | 22 Aug 1999 14:45:04 -0400 |
Organization: | Compilers Central |
Keywords: | yacc, comment |
Dumb question:
How do I convince yacc to overlook elements in the file for which
it lacks patterns? My file to be parsed contains
fred
{
lots of stuff
}
barney
{
lots of stuff
}
flinstone.yacc:
...
%%
my_file :
barneyToken '{' myfilestuff '}' { }
;
...
I'd like to ignore everything but barney, or at least ignore the
stuff in fred { }?
I've tried patterns of the form
my_file :
| fredToken '{' ... '}' {}
| barneyToken '{' ... '}' {}
;
Thanks!
Todd
[You don't, yacc insists on matching everything it sees. I'd do a lexical
hack, e.g. instead of the invalid ... put something like this:
| fredToken '{' { munchmode(); } '}' { /* whatever*/ }
where munchmode() tells the lexer to skip everything up to the close brace.
This is easy to do in flex with start states. Don't forget to count
matching braces, flex can't do that for you. -John]
Return to the
comp.compilers page.
Search the
comp.compilers archives again.