~verifypn-cpn/verifypn/colored

« back to all changes in this revision

Viewing changes to PetriEngine/PQL/PQLAssignmentParser.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 "PQL.h"
 
4
#include "Expressions.h"
 
5
using namespace PetriEngine::PQL;
 
6
 
 
7
AssignmentExpression* assignment;
 
8
extern int pqlalex();
 
9
void pqlaerror(const char *s) {printf("ERROR: %s\n", s);}
 
10
%}
 
11
 
 
12
%name-prefix "pqla"
 
13
%expect 2
 
14
 
 
15
/* Possible data representation */
 
16
%union {
 
17
        PetriEngine::PQL::Expr* expr;
 
18
        PetriEngine::PQL::AssignmentExpression* assExpr;
 
19
        std::string *string;
 
20
        int token;
 
21
}
 
22
 
 
23
/* Terminal type definition */
 
24
%token <string> ID INT
 
25
%token <token> LPAREN RPAREN ASSIGN SEMI
 
26
%token <token> AND OR NOT
 
27
%token <token> EQUAL NEQUAL LESS LESSEQUAL GREATER GREATEREQUAL
 
28
%token <token> PLUS MINUS MULTIPLY
 
29
 
 
30
/* Nonterminal type definition */
 
31
%type <expr> expr term factor
 
32
%type <assExpr> assignment
 
33
 
 
34
/* Operator precedence, more possibly coming */
 
35
 
 
36
%start root
 
37
 
 
38
%%
 
39
 
 
40
root    : assignment                    { assignment = (AssignmentExpression*)$1; }
 
41
                | error                                 { assignment = NULL; yyerrok; }
 
42
                ;
 
43
 
 
44
assignment      : ID ASSIGN expr SEMI assignment        { ((AssignmentExpression*)$5)->prepend(*$1, $3); delete $1;
 
45
                                                                                                  $$ = ((AssignmentExpression*)$5)}
 
46
                        | ID ASSIGN expr SEMI                           { AssignmentExpression* a = new AssignmentExpression();
 
47
                                                                                                  a->prepend(*$1, $3); delete $1;
 
48
                                                                                                  $$ = a;}
 
49
                        | ID ASSIGN expr                                        { AssignmentExpression* a = new AssignmentExpression();
 
50
                                                                                                  a->prepend(*$1, $3); delete $1;
 
51
                                                                                                  $$ = a;}
 
52
                        ;
 
53
 
 
54
expr    : expr PLUS term        { $$ = new PlusExpr($1, $3); }
 
55
                | expr MINUS term       { $$ = new SubtractExpr($1, $3); }
 
56
                | MINUS expr            { $$ = new MinusExpr($2); }
 
57
                | term                          { $$ = $1; }
 
58
                ;
 
59
 
 
60
term    : term MULTIPLY factor  { $$ = new MultiplyExpr($1, $3); }
 
61
                | factor                                { $$ = $1; }
 
62
                ;
 
63
 
 
64
factor  : LPAREN expr RPAREN    { $$ = $2; }
 
65
                | INT                   { $$ = new LiteralExpr(atol($1->c_str())); delete $1; }
 
66
                | ID                    { $$ = new IdentifierExpr(*$1, @1.first_column); delete $1; }
 
67
                ;