Parsing / Lexing question & P-code

"Nicolás" <lojedaortiz@interlink.com.ar>
14 Apr 2000 23:43:14 -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: "Nicolás" <lojedaortiz@interlink.com.ar>
Newsgroups: comp.compilers
Date: 14 Apr 2000 23:43:14 -0400
Organization: Compilers Central
Keywords: Pascal, question, comment

Hi,


I am writing a translator/interpreter for the Pascal lang in C++/Bison.


First of all, I don't know how to differentiate when an identifier is
acting as a variable in an assignment, or it is just a func call with
no params. What I was doing up to now was to recognize something like
this ...


assignment: ID = expr;
expr = variable opt_parameter_list
| ...;
variable: ID | variable '.' ID | variable '[' expr ']' ;


And then I did error checking after parsing (since this allows for
things like foo [ bar ](1) and foo.bar(1)).


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.


I would appreciate any opinions as to which one is better.


Second, I am considering the option of emitting P-code for the
programs ... Does anybody know where can I get info on anything
related to this ?


Thanks a lot,
Nicolás
[I've seen compilers that work either way. I prefer the lexer lookup
since it permits earlier error reporting. -John]


Post a followup to this message

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