Hi all,

As I understand it, ANTLR's lexer matches rules from top to bottom in the .g
grammar file and when two rules match the same number of characters, the one
that is defined first has precedence over the later one(s).

However, take the following grammar:

grammar T;

@lexer::members {
  private boolean test() {
    return true;
  }
}

parse
  :  (t=. {System.out.println(tokenNames[$t.type] + " :: " +  $t.text);})*
EOF
  ;

KEY
  :  'key'
  ;

ANY
  :  ({test()}?=> . )+
  ;


And the test class:"

import org.antlr.runtime.*;


public class Main {
  public static void main(String[] args) throws Exception {
    TLexer lexer = new TLexer(new ANTLRStringStream("key"));
    TParser parser = new TParser(new CommonTokenStream(lexer));
    parser.parse();
  }
}


I'd expected "KEY :: key" to be printed to the console, however, "ANY :: key"
is printed instead. So the last rule is matched, while the KEY rule also
matches the same input and is defined before ANY. Why?

Kind regards,

Bart.

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

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

Reply via email to