1

Can you see any error with the following regular expression? I am defining it in Antlr 3.4, but it accepts arguments like $one, £one although it shouldn't. However, it doesn't accept o£ne, or o$ne.

ID : ('a'..'z'|'A'..'Z'|' _ ') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;

Thanks in advance.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
John David
  • 111
  • 1
  • 6

1 Answers1

3

No, ID does not match "$one" or "£one" as you can see:

T.g

grammar T;

parse : ID EOF;
ID    : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;

Main.java

import org.antlr.runtime.*;

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

Run the test

java -cp antlr-3.4-complete.jar org.antlr.Tool T.g
javac -cp antlr-3.4-complete.jar *.java
java -cp .;antlr-3.4-complete.jar Main

will produce the following error:

line 1:0 mismatched character '$' expecting set null

Note that both antlr-3.4-complete.jar and antlr-3.4-complete-no-antlrv2.jar produce the same error (or any other 3.x version, for that matter).

My guess is that you're using ANTLRWorks and you didn't notice the error messages on the console tab (they're there!).

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288