Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, thank you for that detailed explanation. That really helps :-) ... All of the "$a.term" and similar stuff is sorted out now and code is generated that actually compiles (I simply hacked in that code wanting to fix the issues with that as soon as something is generated at all). I simply commented out a lot of options and keept on generating until I came to the one fragment that seems to break the build. I turned on that backtrack feature, because some errors I got, suggested that I turn it on.</p> <p>EDIT: Well I actually refactored the grammar to get rid of the errors without activating backtrack and now my parser is generated really fast and it seems to do it's job nicely. Here comes the current version:</p> <pre><code>grammar SecurityRulesNew; options { language = Java; output=AST; ASTLabelType=CommonTree; /* backtrack = true;*/ } tokens { POS; NEG; CALL; } @header {package de.cware.cweb.services.evaluator.parser; import de.cware.cweb.services.evaluator.terms.*;} @lexer::header{package de.cware.cweb.services.evaluator.parser;} formula returns [Term term] : a=expression EOF { $term = $a.term; } ; expression returns [Term term] : a=boolExpr { $term = $a.term; } ; boolExpr returns [Term term] : a=sumExpr (AND! b=boolExpr | OR! c=boolExpr | LT! d=boolExpr | LTEQ! e=boolExpr | GT! f=boolExpr | GTEQ! g=boolExpr | EQ! h=boolExpr | NOTEQ! i=boolExpr)? { if(b != null) { $term = new AndTerm($a.term, $b.term); } else if(c != null) { $term = new OrTerm($a.term, $c.term); } else if(d != null) { $term = new LessThanTerm($a.term, $d.term); } else if(e != null) { $term = new LessThanOrEqualTerm($a.term, $e.term); } else if(f != null) { $term = new GreaterThanTerm($a.term, $f.term); } else if(g != null) { $term = new GreaterThanOrEqualTerm($a.term, $g.term); } else if(h != null) { $term = new EqualsTerm($a.term, $h.term); } else if(i != null) { $term = new NotEqualsTerm($a.term, $i.term); } else { $term = $a.term; } } ; sumExpr returns [Term term] : a=productExpr (SUB! b=sumExpr | ADD! c=sumExpr)? { if(b != null) { $term = new SubTerm($a.term, $b.term); } else if(c != null) { $term = new AddTerm($a.term, $c.term); } else { $term = $a.term; } } ; productExpr returns [Term term] : a=expExpr (DIV! b=productExpr | MULT! c=productExpr)? { if(b != null) { $term = new DivTerm($a.term, $b.term); } else if(c != null) { $term = new MultTerm($a.term, $c.term); } else { $term = $a.term; } } ; expExpr returns [Term term] : a=unaryOperation (EXP! b=expExpr)? { if(b != null) { $term = new ExpTerm($a.term, $b.term); } else { $term = $a.term; } } ; unaryOperation returns [Term term] : a=operand { $term = $a.term; } | NOT! a=operand { $term = new NotTerm($a.term); } | SUB! a=operand { $term = new NegateTerm($a.term); } | LPAREN! e=expression RPAREN! { $term = $e.term; } ; operand returns [Term term] : l=literal { $term = $l.term; } | v=VARIABLE { $term = new VariableTerm($v.text); } | f=functionExpr { $term = $f.term; } ; functionExpr returns [Term term] : f=FUNCNAME LPAREN! (a=arguments)? RPAREN! { $term = new CallFunctionTerm($f.text, $a.terms); } ; arguments returns [List&lt;Term&gt; terms] : a=expression (COMMA b=arguments)? { $terms = new ArrayList&lt;Term&gt;(); $terms.add($a.term); if(b != null) { $terms.addAll($b.terms); } } ; literal returns [Term term] : n=NUMBER { $term = new NumberLiteral(Double.valueOf($n.text)); } | s=STRING { $term = new StringLiteral($s.text.substring(1, s.getText().length() - 1)); } | TRUE! { $term = new TrueLiteral(); } | FALSE! { $term = new FalseLiteral(); } ; STRING : '\"' ( options {greedy=false;} : ESCAPE_SEQUENCE | ~'\\' )* '\"' | '\'' ( options {greedy=false;} : ESCAPE_SEQUENCE | ~'\\' )* '\'' ; WHITESPACE : (' ' | '\n' | '\t' | '\r')+ {skip();}; TRUE : ('t'|'T')('r'|'R')('u'|'U')('e'|'E') ; FALSE : ('f'|'F')('a'|'A')('l'|'L')('s'|'S')('e'|'E') ; NOTEQ : '!='; LTEQ : '&lt;='; GTEQ : '&gt;='; AND : '&amp;&amp;'; OR : '||'; NOT : '!'; EQ : '='; LT : '&lt;'; GT : '&gt;'; EXP : '^'; MULT : '*'; DIV : '/'; ADD : '+'; SUB : '-'; LPAREN : '('; RPAREN : ')'; COMMA : ','; PERCENT : '%'; VARIABLE : '[' ~('[' | ']')+ ']' ; FUNCNAME : (LETTER)+ ; NUMBER : (DIGIT)+ ('.' (DIGIT)+)? ; fragment LETTER : ('a'..'z') | ('A'..'Z') ; fragment DIGIT : ('0'..'9') ; fragment ESCAPE_SEQUENCE : '\\' 't' | '\\' 'n' | '\\' '\"' | '\\' '\'' | '\\' '\\' ; </code></pre> <p>Thanks again for your explanation ... it got me on the right track :-)</p> <p>Chris</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.
    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