[antlr-interest] simple grammar question

Michael Roberts mike at 7f.com
Fri Mar 2 18:37:05 PST 2012


Hi folks.

I'm in the process of learning antlr (I just ordered Terrance's books), but
there something I am missing here.  The below compiles fine using
AntlrWorks, but when I feed it:

foo/aa/bb

I get a a MissingTokenException (see attached bitmap), after it's matched
an identifier and a /.

grammar JLG2;

options {
   backtrack=true;
   memoize=true;
}

@header {
package org.veve.reflect.interpreter.output;
}

@lexer::header {
package org.veve.reflect.interpreter.output;
}

compilationUnit : relativePath;

identifier : IdentifierStart IdentifierPart* ;
relativePath : identifier (SLASH identifier)* ;

SLASH : '/';

fragment IdentifierPart
    :
    'a'..'z' | 'A'..'Z' | '_' | '0'..'9'
    ;

fragment IdentifierStart
    :
    'a'..'z' | 'A'..'Z' | '_'
    ;

My expectation there was that identifier would match an alphanumeric
string, and that the rule for relativePath would let me string such
identifiers together with / in between.  However, I'm clearly missing
something obvious.  Thanks in advance.

MR
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glg2.jpg
Type: image/jpeg
Size: 8172 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20120302/44d8a1cc/attachment.jpg 


More information about the antlr-interest mailing list