Re: Parsing / Lexing question & P-code

Keith Thompson <kst@cts.com>
25 Apr 2000 02:25:49 -0400

          From comp.compilers

Related articles
Parsing / Lexing question & P-code lojedaortiz@interlink.com.ar (Nicolás) (2000-04-14)
Re: Parsing / Lexing question & P-code Herwig.Huener@pgtm0035.mch.sni.de (Herwig Huener) (2000-04-21)
Re: Parsing / Lexing question & P-code kst@cts.com (Keith Thompson) (2000-04-25)
Re: Parsing / Lexing question & P-code sebmol@gmx.net (Sebastian Moleski) (2000-04-25)
| List of all articles for this month |

From: Keith Thompson <kst@cts.com>
Newsgroups: comp.compilers
Date: 25 Apr 2000 02:25:49 -0400
Organization: CTS Network Services
References: 00-04-100 00-04-154
Keywords: parse, Pascal

Herwig Huener <Herwig.Huener@pgtm0035.mch.sni.de> writes:
Nicolás wrote:
[...]
> But recently I came up with another idea: instead of returning an ID
> for any identifier, I looked up the identifier in the lexer, and
> returned ID_UNKNOWN, ID_FUNCTION, etc ... This allowed me to have much
> less error checking and no conflicts in the bison grammar.


How does this handle redeclarations in an inner scope? For example
(my Pascal syntax is a bit rusty, so this may not be entirely
correct):


function foo: integer;
      function inner: integer;
            foo: integer;
      begin
            ...
      end;
begin
      ...
end;


If the lexer thinks "foo" is a function name, the parser probably
isn't going to be happy about using it as the name of a variable.


On the other hand, if you write the grammar so that any kind of
identifier can be used in a new declaration, but the identifier in a
function call, for example, can only be an ID_FUNCTION, it might work.


--
Keith Thompson (The_Other_Keith) kst@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>


Post a followup to this message

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