Re: [QUERY] A "ignorant newbie" question about compiler-writing.

kanze@gabi-soft.fr (J. Kanze)
14 Mar 1997 00:33:08 -0500

          From comp.compilers

Related articles
[12 earlier articles]
Re: [QUERY] A "ignorant newbie" question about compiler-writing. dennis@netcom.com (1997-02-16)
Re: [QUERY] A "ignorant newbie" question about compiler-writing. kanze@gabi-soft.fr (1997-02-16)
Re: [QUERY] A "ignorant newbie" question about compiler-writing. nr@adder.cs.virginia.edu (Norman Ramsey) (1997-02-20)
Re: [QUERY] A "ignorant newbie" question about compiler-writing. cfc@world.std.com (1997-02-22)
Re: [QUERY] A "ignorant newbie" question about compiler-writing. fjh@mundook.cs.mu.OZ.AU (1997-02-23)
Re: [QUERY] A "ignorant newbie" question about compiler-writing. cartegw@humsci.auburn.edu (1997-02-27)
Re: [QUERY] A "ignorant newbie" question about compiler-writing. kanze@gabi-soft.fr (1997-03-14)
| List of all articles for this month |

From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.compilers
Date: 14 Mar 1997 00:33:08 -0500
Organization: GABI Software
References: 97-01-013 97-01-236 97-02-038 97-02-095 97-02-150
Keywords: Pascal, parse

cartegw@humsci.auburn.edu (Gerald W. Carter) writes:


|> > > > even Pascal requires some hacks.
|> >
|> > > In my recollection, only in parsing (0.1 vs 0..1), though "with"
|> > > clauses can be a bit tricky regarding sematic analysis. (though I may
|> > > be wrong, as I haven't worked on a pascal compiler for about 7 years).
|>
|> > Actually, the specific case I was thinking about was the distinction
|> > between an assignment statement and a procedure call. I actually think
|> > that you could write an LR grammar which would work even if the scanner
|> > returned user symbol in both cases, but it would be complicated. The
|> > usual solution is for the scanner to do a symbol table lookup, and
|> > return a different token if the symbol is defined as a procedure. In
|> > short, a hack.
|>
|> I don't believe that the symbol table lookup is neccessary. For example
|>
|> ----------------------------------------
|> statement : assignment
|> | procedure_call
|> ;
|>
|> assignment : variable BECOMES expression /* must test for func_ident */
|> ;
|>
|> procedure_call : ident actual_params
|> ;
|> ----------------------------------------


It's certainly doable (I think), but it is definitly more complicated
than this. Consider that the left hand side of an assignment is not
just a variable. It can be any arbitrary expression, including a call
to a function which returns a pointer, e.g.:


        fnc( arg1 , arg2 )^ := someValue ;


So you will have to develop the grammar so that things like "ident '('
... ')'" reduce to a commun term legal both on the left side of
assignment *and* as a procedure call.


This seems a bit artificial to me, and while theoretically, it is nice,
I think that I'd go with the hack myself, as being easier to maintain
and to understand.
--
James Kanze +33 (0)1 39 55 85 62 email: kanze@gabi-soft.fr
GABI Software, Sarl., 22 rue Jacques-Lemercier, 78000 Versailles, France
--


Post a followup to this message

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