Note that there are some explanatory texts on larger screens.

plurals
  1. POAntlr Left-Factoring Grammar
    primarykey
    data
    text
    <p>I am new to Antlr. I am defining a grammar for my company using Antlr 3.</p> <p>Below is my grammar:</p> <pre><code>grammar Grammar; @header { package com.grammar; } true : 'true'; false : 'false'; null : 'null'; value : true | false | null | STRING | NUMBER; query : (STATEMENT+) | STATEMENT?; INSERT : 'INSERT INTO' TABLE 'VALUES' '('ELEMENTS')'';'; STATEMENT : INSERT; STRING : ('a'..'z'|'A'..'Z')+; INTEGER : '0'..'9'+; ELEMENTS : value | value ',' ELEMENTS; </code></pre> <p>When I try to generate the code using ANTLRWorks, I get the following Exception:</p> <pre><code>error (211): Grammar.g.1:8: [fatal] rule Tokens has non-LL(*) decision due to recursive rule invocations reacable from alts 18,24. Resolve by left-factoring or using syntactic predicates or using backtrack=true option </code></pre> <p>I had a look at the following website:</p> <p><a href="http://www.antlr.org/wiki/display/ANTLR3/How+to+remove+global+backtracking+from+your+grammar" rel="nofollow">http://www.antlr.org/wiki/display/ANTLR3/How+to+remove+global+backtracking+from+your+grammar</a></p> <p>Any suggestions what can be done? I couldn't find much online.</p> <p>When I add the following:</p> <pre><code> grammar Grammar; @options { backtrack=true; } </code></pre> <p>I get only one Exception:</p> <pre><code> error(100): Grammar.g:3:2: syntax error: antlr: NoViableAltException(55@[]) [12:03:20] error(100): Grammar.g:3:2: syntax error: antlr: MissingTokenException (inserted [@-1,0:0='&lt;missing ACTION&gt;',&lt;50&gt;,3:1] at options {) [12:03:20] error(100): Grammar.g:3:2: syntax error: antlr: org.antlr.runtime.EarlyExitException [12:03:20] error(150): grammar file Grammar.g has no rules [12:03:20] error(100): Grammar.g:0:1: syntax error: assign.types: MismatchedTreeNodeException(0!=3) </code></pre> <p>EDIT:</p> <p>I have added value and ELEMENTS. When using ELEMENTS inside the graph in ANTLRWorks, the value cannot be seen. I can only see:</p> <pre><code>',' ELEMENTS </code></pre> <p>instead of:</p> <pre><code>value | value ',' ELEMENTS </code></pre> <p>Could this be the cause of the problem for the Tokens Exception? Is this actually allowed? What is the solution?</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.
    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