Note that there are some explanatory texts on larger screens.

plurals
  1. POANTLR3 common values in 2 different domain values
    text
    copied!<p>I need to define a language-parser for the following search criteria:</p> <pre><code>CRITERIA_1=&lt;values-set-#1&gt; AND/OR CRITERIA_2=&lt;values-set-#2&gt;; </code></pre> <p>Where <code>&lt;values-set-#1&gt;</code> can have values from 1-50 and <code>&lt;values-set-#2&gt;</code> can be from the following set (5, A, B, C) - case is not important here.</p> <p>I have decided to use ANTLR3 (v3.4) with output in C# (CSharp3) and it used to work pretty smooth until now. The problem is that it fails to parse the string when I provide values from both data-sets (I.e. in this case '5'). For example, if I provide the following string</p> <pre><code>CRITERIA_1=5; </code></pre> <p>It returns the following error where the value node was supposed to be:</p> <pre><code>&lt;unexpected: [@1,11:11='5',&lt;27&gt;,1:11], resync=5&gt; </code></pre> <p>The grammar definition file is the following:</p> <pre><code>grammar ZeGrammar; options { language=CSharp3; TokenLabelType=CommonToken; output=AST; ASTLabelType=CommonTree; k=3; } tokens { ROOT; CRITERIA_1; CRITERIA_2; OR = 'OR'; AND = 'AND'; EOF = ';'; LPAREN = '('; RPAREN = ')'; } public start : expr EOF -&gt; ^(ROOT expr) ; expr : subexpr ((AND|OR)^ subexpr)* ; subexpr : grouppedsubexpr | 'CRITERIA_1=' rangeval1_expr -&gt; ^(CRITERIA_1 rangeval1_expr) | 'CRITERIA_2=' rangeval2_expr -&gt; ^(CRITERIA_2 rangeval2_expr) ; grouppedsubexpr : LPAREN! expr RPAREN! ; rangeval1_expr : rangeval1_subexpr | RANGE1_VALUES ; rangeval1_subexpr : LPAREN! rangeval1_expr (OR^ rangeval1_expr)* RPAREN! ; RANGE1_VALUES : (('0'..'4')? ('0'..'9') | '5''0') ; rangeval2_expr : rangeval2_subexpr | RANGE2_VALUES ; rangeval2_subexpr : LPAREN! rangeval2_expr (OR^ rangeval2_expr)* RPAREN! ; RANGE2_VALUES : '5' | ('a'|'A') | ('b'|'B') | ('c'|'C') ; </code></pre> <p>And if I remove the value '5' from <code>RANGE2_VALUES</code> it works fine. Can anyone hint me on what I am doing wrong?</p>
 

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