[antlr-interest] Allowing whitespace in symbols

soraz30 asger at udenbysvester.dk
Fri Oct 1 06:24:48 PDT 2004


I have a problem, and I'm not even sure I'm close to solving it.


I have a grammar, that defines two types of symbols, in seperate
symbol tables
AList
BList


A symbol in one of the lists, must be allowed to include spaces in
their names i.e.

in the DiagnoseList, I have "Foo Bar" as a valid entry.
in the InterventionList, I have "Poo Par" as a valid entry.

In my lexer, I have a rule that basically says (pseudo-code)
ID : [a-z0-9 ]+
   { if text in AList, _ttype=ASYMBOL; 
     if text in BList, _ttype=BSYMBOL;
   }


The parser then has
Line:- ASYMBOL BSYMBOL

On the input "Foo Bar Poo Par", this, ofcourse fails, because the rule
for ASYMBOL (that is: ID), has globbed the Poo Bar as part of the
reg-exp for ID.

Is there any way to achieve this? What I'm looking for, is a way for
the ID rule to say "Ok: That is enough. I now match an entry from one
of the lists.". 

I thought about an approach to match it manually against the lists,
and push the remainder back on the input-stream. Is this a viable
solution? Is it possible?

The symbol tables are loaded from an external source at run-time, so I
cant just insert them as literals (which, by the way, works nicely).

Thanks in advance
Asger



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list