Re: Lookahead vs. Scanner Feedback

bliss@sp64.csrd.uiuc.edu (Brian Bliss)
Mon, 13 Jan 92 17:00:35 GMT

          From comp.compilers

Related articles
[8 earlier articles]
Re: Lookahead vs. Scanner Feedback bill@twwells.com (1992-01-08)
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)
| List of all articles for this month |
Newsgroups: comp.compilers
From: bliss@sp64.csrd.uiuc.edu (Brian Bliss)
Keywords: yacc, parse
Organization: UIUC Center for Supercomputing Research and Development
References: 92-01-012 92-01-042
Date: Mon, 13 Jan 92 17:00:35 GMT

jwoods@convex.com writes:


>Instantiate a flag, such as "typedefRecognition," and initialize it to
>"ON" prior to parser invocation, after completed declarations and "OFF"
>after recognition of typedef names. The scanner will consult the setting
>of this flag after recognizing the lexeme as an "identifier" but before
>returning the token ID. If "typedefRecognition" is "ON," the scanner
>searching the name space for a symbol with an attribute matching
>"typedefName."


again, consider the two code fragments




typedef int foo;
main () {
      long foo;
}




and


typedef int foo;
main () {
      long foo x;
}




in the latter, we definitely want to return T_TYPEDEF_NAME as the token
for foo. in the former, we want to return T_IDENT for foo, as it is being
redecalred as an identifier in an inner scope. The two programs are
identical up to "foo", so there is no amount flag twiddling that we can do
to resolve the problem correctly; we must use some sort of lookahead.


The lookahead can either be done by the lexical analyzer, as I've been
attempting to do, or by the parser, which means we return the same token
for both typedef names and other identifiers. The latter introduces many
ambiguities in the grammar in K&RII, in declaration statements, in
expression in the form of a single identifier appearing after declarations
and before the executable statements within a block, and within function
prototypes, and probably other places as well.


bb
--


Post a followup to this message

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