[antlr-interest] Concept Problem with recognizing Tokens
Terence Parr
parrt at cs.usfca.edu
Mon Apr 30 13:06:55 PDT 2007
Seems you are doing everything in the lexer. Send identifiers or
keywords to the parser and then have the parser apply the appropriate
grammatical structure. Then, you will automatically get your
messages you seek. :)
Ter
On Apr 30, 2007, at 9:54 AM, Jeff Skaanland wrote:
> Hopefully this isn't just something I've been overlooking in my
> searches
> but....
>
> I'm processing a type of assembly language and am running into a
> problem.
> Outside of Labels, there is a set amount of vocabulary for the
> language
> which I defined as tokens (MAC = "mac"; ALU = "alu"; ...).
>
> Problem I face:
> When I intentionally put an error into the input stream, for
> example use 'Mcdonalds' as command, instead of saying "found
> MCDONALDS,
> expected MAC" it reports "found 'c', expected 'a'. To fix this, I
> wished to
> process every word into a token, but then I can't figure out how to
> take a
> token, INSTRUCTION, and then check to see if it's actually a MAC
> token or
> ALU token and, if not, spit out "Found MCDONALDS, expected
> RUTHS_CHRIS" (Or
> expected MAC again...)
>
> Thanks for setting me straight,
>
> JT
>
>
More information about the antlr-interest
mailing list