I want to parse recipes. How can I distinguish (for instance) between a
measuring unit such as "cups" and other general words?

 

If I do 

 

WORD:

                LETTER+;

UNIT:

                "cups";

 

the lexer will emit WORD for "cups" as well at least that's what I see
happening. I tried

 

WORD:

        u=UNIT { 
          $u.setType(UNIT);

          emit($u);

                } | LETTER+;

 

but that causes an error saying that UNIT can never be matched.

 

If I place the burden on the parser say as

 

unit:

                w=WORD 

{

                if ($w == "cups") return $w; 

}

;

 

and the WORD token is actually not a unit I have lost the token to the
parser. Should I / How can I place that nonmatch token back into the token
stream? Or what's the solution to that??

 

Thanks a lot - Sven


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to