summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/automate/grammar.yy
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buzz/src/automate/grammar.yy')
-rw-r--r--2003/i/buzz/src/automate/grammar.yy55
1 files changed, 44 insertions, 11 deletions
diff --git a/2003/i/buzz/src/automate/grammar.yy b/2003/i/buzz/src/automate/grammar.yy
index 709c8e3..04a001e 100644
--- a/2003/i/buzz/src/automate/grammar.yy
+++ b/2003/i/buzz/src/automate/grammar.yy
@@ -27,6 +27,7 @@ Grafcet *input_grafcet;
Action *action;
Receptivite *receptivite;
Transition *transition;
+ Expression *expression;
}
%token <num> NUM
@@ -34,18 +35,25 @@ Grafcet *input_grafcet;
%token <boolean> BOOL
%token <s> STRING
%token ERR GOTO
+%token EQ NEQ LEQ GEQ
%token PRINT
%type <grafcet> grafcet
%type <etape> etape
%type <action> action
%type <receptivite> receptivite
%type <transition> transition
+%type <expression> expression
%type <fl> flnum
/* Priorité des opérateurs. */
-%right '+'
-%right '.'
-%right '!'
+%left '|'
+%left '&'
+%left '!'
+%left EQ NEQ LEQ GEQ '<' '>'
+
+%left '+' '-'
+%left '*' '/'
+%left NEG
%%
@@ -54,10 +62,10 @@ input: grafcet { input_grafcet = $1; }
grafcet:
/* Rien */ { $$ = new Grafcet (); }
- | grafcet etape { $$ = $1; $$->m_grafcet.push_back (Grafcet::GrafcetElem ($2)); }
- | grafcet action { $$ = $1; $$->m_grafcet.push_back (Grafcet::GrafcetElem ($2)); }
- | grafcet receptivite { $$ = $1; $$->m_grafcet.push_back (Grafcet::GrafcetElem ($2)); }
- | grafcet transition { $$ = $1; $$->m_grafcet.push_back (Grafcet::GrafcetElem ($2)); }
+ | grafcet etape { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($2)); }
+ | grafcet action { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($2)); }
+ | grafcet receptivite { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($2)); }
+ | grafcet transition { $$ = $1; $$->m_grafcet.push_back (Grafcet::Elem ($2)); }
;
etape: '#' NUM { $$ = new Etape ($2); }
@@ -68,11 +76,36 @@ action: PRINT STRING { $$ = new ActionPrint (*$2); delete $2; }
receptivite:
BOOL { $$ = new ReceptiviteBool ($1); }
- | receptivite '.' receptivite
- { $$ = new ReceptiviteBoolOp ($1, '.', $3); }
- | receptivite '+' receptivite
- { $$ = new ReceptiviteBoolOp ($1, '+', $3); }
+ | receptivite '&' receptivite
+ { $$ = new ReceptiviteBoolOp ($1, '&', $3); }
+ | receptivite '|' receptivite
+ { $$ = new ReceptiviteBoolOp ($1, '|', $3); }
| '!' receptivite { $$ = new ReceptiviteBoolOp ('!', $2); }
+ | '(' receptivite ')' { $$ = $2; }
+ | expression EQ expression
+ { $$ = new ReceptiviteCmpOp ($1, '=', $3); }
+ | expression NEQ expression
+ { $$ = new ReceptiviteCmpOp ($1, 'n', $3); }
+ | expression LEQ expression
+ { $$ = new ReceptiviteCmpOp ($1, 'l', $3); }
+ | expression GEQ expression
+ { $$ = new ReceptiviteCmpOp ($1, 'g', $3); }
+ | expression '<' expression
+ { $$ = new ReceptiviteCmpOp ($1, '<', $3); }
+ | expression '>' expression
+ { $$ = new ReceptiviteCmpOp ($1, '>', $3); }
+;
+
+expression:
+ NUM { $$ = new ExpressionNum ($1); }
+ | expression '+' expression
+ { $$ = new ExpressionNumOp ($1, '+', $3); }
+ | expression '-' expression
+ { $$ = new ExpressionNumOp ($1, '-', $3); }
+ | expression '*' expression
+ { $$ = new ExpressionNumOp ($1, '*', $3); }
+ | '-' expression %prec NEG
+ { $$ = new ExpressionNumOp ('n', $2); }
;
transition: