Related articles |
---|
[9 earlier articles] |
Re: Lookahead vs. Scanner Feedback bliss@sp64.csrd.uiuc.edu (1992-01-08) |
Re: Lookahead vs. Scanner Feedback nigelh@sol.UVic.CA (1992-01-08) |
Re: Lookahead vs. Scanner Feedback dww@inf.fu-berlin.de (1992-01-08) |
Re: Lookahead vs. Scanner Feedback jwoods@convex.com (1992-01-09) |
Re: Lookahead vs. Scanner Feedback jwoods@convex.com (1992-01-10) |
Re: Lookahead vs. Scanner Feedback bliss@sp64.csrd.uiuc.edu (1992-01-13) |
Re: Lookahead vs. Scanner Feedback megatest!djones@decwrl.dec.com (1992-01-13) |
Newsgroups: | comp.compilers |
From: | megatest!djones@decwrl.dec.com (Dave Jones) |
Keywords: | parse, C |
Organization: | Megatest Corporation, San Jose, Ca |
References: | 92-01-042 |
Date: | 13 Jan 92 22:51:05 GMT |
>From article <92-01-042@comp.compilers), by jwoods@convex.com (Jeff Woods):
) hjelm+@cs.cmu.edu (Mark Hjelm) writes:
) Something like this might be in order:
)
) parser code:
)
) typedefRecognition = ON ;
) status = yyparse() ;
)
...
) grammar file:
)
) type-specifier:
) tVoid typedefRecOn
) | tChar typedefRecOn
) .
) .
) .
) | tTypedefName typedefRecOn
) ;
)
) typedefRecOn:
) {
) typedefRecognition = ON ;
) }
) ;
)
) Hope this is helpful,
)
) Jeff
Yes, something *like* that is possible, but it is rather tricky. The
switches in grammar rules that toggle typedef- recognition must be
situated very carefully, and in places that some may find
counter-intuitive. In the example above, "typedefRecOn" should be located
*after* "tTypedefName" and "tVoid", not before. (!)
Also (for purposes of maintainability if for no other reason), you want to
be sure that the scanner is always "eager" to do lookahead, not "lazy" in
states where a lookahead is not urgently needed to select a state-change.
A few months ago I posted a YACC/LEX program which, to the best of my
knowledge, does everything correctly, although given the trickiness of the
problem, I would not be astonished to hear otherwise.
Also I was under the false impression that ANSI C was meant to be a strict
extension of C, and therefore implemented some features of C-Classic which
ANSI C dropped, thinking the formal grammar I started from was "buggy".
Thus my statement that I thought the parser was "ANSI C" was technically
incorrect, although probably not enough so to cause any problems. It is
"ANSI C with C-Classic Extensions", I guess.
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.