summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/automate/grammar.yy
blob: 709c8e3966eb3a2ed1a9e1206cfa183402ea92d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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