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.yy95
1 files changed, 95 insertions, 0 deletions
diff --git a/2003/i/buzz/src/automate/grammar.yy b/2003/i/buzz/src/automate/grammar.yy
new file mode 100644
index 0000000..709c8e3
--- /dev/null
+++ b/2003/i/buzz/src/automate/grammar.yy
@@ -0,0 +1,95 @@
+%{
+#include <iostream>
+using namespace std;
+
+#include "grafcet.h"
+using namespace Automate;
+
+void
+yyerror (const char *s);
+
+int
+yylex (void);
+
+Grafcet *input_grafcet;
+
+%}
+
+%defines
+
+%union {
+ int num;
+ double fl;
+ bool boolean;
+ string *s;
+ Grafcet *grafcet;
+ Etape *etape;
+ Action *action;
+ Receptivite *receptivite;
+ Transition *transition;
+}
+
+%token <num> NUM
+%token <fl> FLOAT
+%token <boolean> BOOL
+%token <s> STRING
+%token ERR GOTO
+%token PRINT
+%type <grafcet> grafcet
+%type <etape> etape
+%type <action> action
+%type <receptivite> receptivite
+%type <transition> transition
+%type <fl> flnum
+
+/* Priorité des opérateurs. */
+%right '+'
+%right '.'
+%right '!'
+
+%%
+
+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)); }
+;
+
+etape: '#' NUM { $$ = new Etape ($2); }
+;
+
+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 { $$ = new ReceptiviteBoolOp ('!', $2); }
+;
+
+transition:
+ GOTO NUM { $$ = new Transition ($2); }
+;
+
+flnum: FLOAT { $$ = $1; }
+ | NUM { $$ = $1; }
+ | flnum '/' flnum { $$ = $1 / $3; }
+;
+
+%%
+
+void
+yyerror (const char *s)
+{
+ cerr << "Parse error: " << s << endl;
+}
+
+// vim: ft=yacc