~verifypn-cpn/verifypn/colored

« back to all changes in this revision

Viewing changes to PetriEngine/PQL/SUMoQueryParser.y

  • Committer: Jonas Finnemann Jensen
  • Date: 2011-09-15 13:30:00 UTC
  • Revision ID: jopsen@gmail.com-20110915133000-wnywm1odf82emiuw
Import of sources from github

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
#include <stdio.h>
 
3
#include <string>
 
4
#include "PQL.h"
 
5
#include "Expressions.h"
 
6
using namespace PetriEngine::PQL;
 
7
 
 
8
Condition* sumoQuery;
 
9
std::string sumoName;
 
10
bool isInvariant;
 
11
extern int sumolex();
 
12
extern char* sumotext;
 
13
void sumoerror(const char *s) {printf("ERROR: %s: %s\n", s, sumotext);}
 
14
%}
 
15
 
 
16
%name-prefix "sumo"
 
17
 
 
18
/* Data representation */
 
19
%union {
 
20
        PetriEngine::PQL::Expr* expr;
 
21
        PetriEngine::PQL::Condition* cond;
 
22
        std::string* string;
 
23
        int token;
 
24
}
 
25
 
 
26
/* Terminal type definition */
 
27
%token <string> ID INT
 
28
%token <token> LPAREN RPAREN LBRACKET RBRACKET
 
29
%token <token> AND OR NOT REACHABLE INVARIANT
 
30
%token <token> CONTAINS EQUALS STAR VALUE EQUAL
 
31
 
 
32
/* Terminal associativity */
 
33
%left AND OR
 
34
%right NOT
 
35
 
 
36
/* Nonterminal type definition */
 
37
%type <cond> subformula atomic
 
38
%type <expr> idexpr expr
 
39
 
 
40
 
 
41
/* Lets begin */
 
42
 
 
43
%start root
 
44
 
 
45
%%
 
46
 
 
47
root    : ID EQUAL REACHABLE subformula         { sumoQuery = $4; isInvariant = false; sumoName = *$1; delete $1;}
 
48
                | ID EQUAL INVARIANT subformula         { sumoQuery = new NotCondition($4); isInvariant = true; sumoName = *$1; delete $1; }
 
49
                ;
 
50
 
 
51
subformula : subformula AND subformula          { $$ = new AndCondition($1, $3); }
 
52
                   | subformula OR subformula           { $$ = new OrCondition($1, $3); }
 
53
                   | NOT subformula                                     { $$ = new NotCondition($2); }
 
54
                   | LPAREN subformula RPAREN           { $$ = $2; }
 
55
                   | atomic                                                     { $$ = $1; }
 
56
                   ;
 
57
 
 
58
atomic : idexpr CONTAINS LBRACKET expr RBRACKET { $$ = new GreaterThanOrEqualCondition($1, $4); }
 
59
           | idexpr EQUALS LBRACKET expr RBRACKET { $$ = new EqualCondition($1, $4); }
 
60
           | idexpr EQUALS LBRACKET RBRACKET { $$ = new EqualCondition($1, new LiteralExpr(0)); }
 
61
           ;
 
62
 
 
63
idexpr : ID             { $$ = new IdentifierExpr(*$1, @1.first_column); delete $1; }
 
64
           ;
 
65
 
 
66
expr : INT STAR VALUE   { $$ = new LiteralExpr(atol($1->c_str())); delete $1; }
 
67
         ;