[antlr-interest] Simple lexical predicate question

Ryan Hollom ryan.hollom at us.lawson.com
Tue Sep 12 07:27:22 PDT 2006


Greetings-

I am writing a parser/lexer for a language with the following constructs, 
and am having difficulty getting the lexer to work properly.

identifier is a Field
        identifier is a LocalField
        identifier is Numeric
        identifier is an AddressField

So, I have the keywords 'is a Field', 'is a', 'is', and 'is an' 
('LocalField' and 'AddressField' can be any name, and 'Numeric' can be one 
of about 30 different things).

I've had a difficult time defining the rules for these, as I get a lexer 
no viable alt error.  Here is an example of my rule:
fieldDefinition :
        identifier 'is a Field'
                (identifier 
                        (('is a' | 'is an') identifier) | 'is' 
primitiveType)
                );

primitiveType : 'Alpha' | 'Numeric';

The lexer then chokes on input like:
MyField is a Field
        MyNumericField is Numeric

with a no viable alt line 2:20; char='N'

I assume that I need to define lexer rules for the 'is ...' keywords with 
some type of predicate, but haven't been able to figure it out yet.  Could 
someone point me in the right direction?

Thanks in advance,
Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060912/a9bfb939/attachment.html 


More information about the antlr-interest mailing list