Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I find it hard to believe a <code>p</code> token is created based on the grammar you posted. Lexer rules that have <code>fragment</code> in front of them will not produce tokens: these rules are only used by other lexer rules.</p> <p>A simple demo shows this:</p> <pre><code>lexer grammar ExpressionLexer; @lexer::members { public static void main(String[] args) throws Exception { ExpressionLexer lexer = new ExpressionLexer(new ANTLRStringStream(args[0])); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.fill(); // remove this line when using ANTLR 3.2 or an older version System.out.println(tokens); } } COMMA : ','; LPAREN : '('; RPAREN : ')'; LBRACK : '['; RBRACK : ']'; PLUS : '+'; MINUS : '-'; MULT : '*'; DIV : '/'; PREV_VALUE : 'PreviousValue'; fragment DIGIT : ('0'..'9'); fragment LETTER : ('a'..'z'|'A'..'Z'|'_'); fragment TAB : ('\t') ; fragment NEWLINE : ('\r'|'\n') ; fragment SPACE : (' ') ; </code></pre> <p>Now generate the lexer and compile the <code>.java</code> source file:</p> <pre>java -cp antlr-3.3.jar org.antlr.Tool ExpressionLexer.g javac -cp antlr-3.3.jar *.java</pre> <p>and run a few tests:</p> <pre>java -cp .:antlr-3.3.jar ExpressionLexer p line 1:0 no viable alternative at character 'p'</pre> <p>which is correct since there is no (non-fragment) rule that starts with, or matches, a <code>"p"</code>.</p> <pre>java -cp .:antlr-3.3.jar ExpressionLexer P line 1:1 mismatched character '' expecting 'r'</pre> <p>which is correct since the only (non-fragment) rule that starts with a <code>"P"</code> expects an <code>"r"</code> to be the next character (which isn't there).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload