[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lookahead implementation



Maybe I don't understand this well enough or I did a poor job explaining it.  
It seems to me the issue is that "DIR" can be any legal identifer.  In my case, an identifier is given by
LETTER (LETTER|DIGIT)+

and the expressions can contain variables... such as
 ABC = 3*DIR + 5*2
where the identifiers might also be used as commands (such as the DIR in the example above)  That is, command directives are not reserved words (in general, they are not even known ahead of time - they are loaded into a hashtable at execution time).  
When I have tried to write a grammar that encompasses all of the possiblities, it seems like I always get shift/reduce or reduce/reduce errors.  On the other hand if I write a grammar to simply parse into more general tokens, then it seems like this means the tree-walker has to start knowing about the grammar, which sort of defeats the beauty of using SableCC.

Admittedly, I am new to this stuff, so maybe I don't fully understand how to write a good grammar or build the appropriate tree walker to post process it.  If you have can point me to some other examples of how this might be done, I would be happy to look at them and try to figure it out.



----- Original Message -----
From: Patrick LAM <plam@sable.mcgill.ca>
Date: Tue, 6 Jan 2004 20:04:05 -0500 (EST)
To: Roger Pomeroy <rogerandsue@mail.com>
Subject: Re: Lookahead implementation

> On Tue, 6 Jan 2004, Roger Pomeroy wrote:
> 
> > DIR = 2*3 + 5   !an arithmetic type expression using symbol DIR
> >
> > DIR 1 type=3+5 list=abc    !a command directive with some arguments
> 
> This seems to be the same problem that Pohl was asking about a few days
> back.  Why don't you parse DIR as simply an identifier in your abstract
> syntax tree, then once you have the whole expression, decide if it was
> actually a symbol or a command directive, using a type-inferring walker?
> 
> pat
> 
> 
> 

-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm