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

Re: Questions about blank tokens, and reduce/reduce errors



Hi Roger,

You guessed right; the cleanest approach would be to use "states", but
there's a problem: how do you trigger state transition at the right
time? This is a very difficult thing to do as the lexer is always one
token ahead of the LALR(1) parser.

One of the fundamental features of SableCC4 is to automate "context
transitions". (SableCC 4 uses the word "context" instead of rather
ambiguous word "state"). This would allow you to specify, in the parser
section (e.g. called production section in SableCC3) the lexical context
in which each production should be parsed. As a side effect, SableCC 4
will detect "context transition" conflicts (which usually result
difficult to identify bugs in compilers).

I know, this does not help you on the very short time, as SableCC 4 is
not yet available. Yet, it is progressing steadily, as I am currently
working full time on it. I should be releasing an alpha containing the
new and powerful lexer generator in a few days.

Etienne

Roger Pomeroy wrote:
> First the general question ... the language that I am trying to get 
> the grammar for has both "typical" programming like constructs 
> (assignments, loops,etc) but also has lines that are of a form 
> COMMANDNAME  ARG1 ARG2 ...  where arg1,arg2 might be either a 
> keyword pair, or just a value (without the keyword).  For these 
> lines, there are cases where I might want (need?) blanks to be 
> significant, but everywhere else I view blanks as ignored tokens.  
> I am thinking that if I need to keep the blanks, I should simply 
> 'grab' the  entire line after the COMMANDNAME and parse it 
> separately, not trying to include the parsing of all the keys in my 
> SableCC grammar.  I am just wondering if anyone else has any 
> thoughts on whether that is the best way to approach this, or if 
> there is some other way I should do it (like using states, etc)?  
> It seems like if I have to make blanks not an ignored token the 
> grammar will get really messy?
>   

-- 
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org


Attachment: signature.asc
Description: OpenPGP digital signature