4
#include "Expressions.h"
5
using namespace PetriEngine::PQL;
9
void pqlqerror(const char *s) {printf("ERROR: %s\n", s);}
15
/* Possible data representation */
17
PetriEngine::PQL::Expr* expr;
18
PetriEngine::PQL::Condition* cond;
23
/* Terminal type definition */
24
%token <string> ID INT
25
%token <token> LPAREN RPAREN
26
%token <token> AND OR NOT
27
%token <token> EQUAL NEQUAL LESS LESSEQUAL GREATER GREATEREQUAL
28
%token <token> PLUS MINUS MULTIPLY
30
/* Terminal associativity */
34
/* Nonterminal type definition */
35
%type <expr> expr term factor
36
%type <cond> logic compare
38
/* Operator precedence, more possibly coming */
44
query : logic { query = $1; }
48
logic : logic AND logic { $$ = new AndCondition($1, $3); }
49
| logic OR logic { $$ = new OrCondition($1, $3); }
50
| NOT logic { $$ = new NotCondition($2); }
51
| LPAREN logic RPAREN { $$ = $2; }
52
| compare { $$ = $1; }
55
compare : expr EQUAL expr { $$ = new EqualCondition($1, $3); }
56
| expr NEQUAL expr { $$ = new NotEqualCondition($1, $3); }
57
| expr LESS expr { $$ = new LessThanCondition($1, $3); }
58
| expr LESSEQUAL expr { $$ = new LessThanOrEqualCondition($1, $3); }
59
| expr GREATER expr { $$ = new GreaterThanCondition($1, $3); }
60
| expr GREATEREQUAL expr { $$ = new GreaterThanOrEqualCondition($1, $3); }
63
expr : expr PLUS term { $$ = new PlusExpr($1, $3); }
64
| expr MINUS term { $$ = new SubtractExpr($1, $3); }
65
| MINUS expr { $$ = new MinusExpr($2); }
69
term : term MULTIPLY factor { $$ = new MultiplyExpr($1, $3); }
73
factor : LPAREN expr RPAREN { $$ = $2; }
74
| INT { $$ = new LiteralExpr(atol($1->c_str())); delete $1; }
75
| ID { $$ = new IdentifierExpr(*$1, @1.first_column); delete $1; }