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

cartegw@humsci.auburn.edu (Gerald W. Carter)
27 Feb 1997 00:38:03 -0500

          From comp.compilers

Related articles
[11 earlier articles]
Re: [QUERY] A "ignorant newbie" question about compiler-writing. mff@research.att.com (Mary Fernandez) (1997-02-11)
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: cartegw@humsci.auburn.edu (Gerald W. Carter)
Newsgroups: comp.compilers
Date: 27 Feb 1997 00:38:03 -0500
Organization: Compilers Central
References: 97-01-013 97-01-236 97-02-038 97-02-095
Keywords: parse, Pascal, comment

> > > 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
;
----------------------------------------


I won't bore you with the rest of the grammar details ( you may notice
that this is part of the grammar from the comp.compilers ftp site ).


I agree that the ability to call procedures without args ( ie not ()'s
) can make it difficult to distinguish between procedure calls and
variables, but I think that the above grammar should be able to tell
the difference.


As a side note, I found that the Pascal grammar on the ftp site does
allow procedures to be called as rvlaues. Since a procedure does not
return a value, this should not be allowed. The differentiating
between procedures and functions removes several shift/reduce
conflicts in bison. It was about a year ago when I downloaded the
grammar so someone else could have already fixed it by now.


(to moderator...) John, if the grammar stills contains this bug, I can
send you the patched version if you want it.


Jerry
------------------------------------------------------------------------
| Gerald ( Jerry ) Carter |
| System / Network Admin ( 334 ) 844 - 3788 |
| School of Human Sciences cartegw@humsci.auburn.edu |
| Auburn University http://www.humsci.auburn.edu/~cartegw |
[It hasn't changed in ages. -John]
--


Post a followup to this message

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