summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/automate/grammar.yy
blob: a7807779050c1cc029c84fcc2b018ad42b85883a (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
%{
#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;
    Expression *expression;
}

%token <num> NUM
%token <fl> FLOAT
%token <boolean> BOOL
%token <s> STRING
%token ERR GOTO
%token EQ NEQ LEQ GEQ

/*TOKEN des actions
%token INITIALISATION
%token RECHERCHER
%token ROTATION
%token AVANCER_PALET
%token NB_PALET_PILE
%token NB_PALET_STOCKE
%token MISE_EN_PLACE
%token REPERER_COULEUR
%token RETOURNER
%token AVANCER
%token RECULER
%token PLACER_PINCE
%token PRINT

/*TOKEN des conditions
%token INIT
%token PALETS_TROUVES
%token PALETS
%token STOCKE
%token COULEUR_ADVERSE
%token PINCE_ANGLE
%token PINCE_POS
%token ROBOT_RECULE
%token ROBOT_AVANCE

%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. */
%left '|'
%left '&'
%left '!'
%left EQ NEQ LEQ GEQ '<' '>'

%left '+' '-'
%left '*' '/'
%left NEG

%%

input:	  grafcet	{ input_grafcet = $1; }
;

grafcet:
          /* Rien */		{ $$ = new Grafcet (); }
	| 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)); }
;

/* # represente un label ex : # 25
etape:	  '#' NUM		{ $$ = new Etape ($2); }
;

/*met les actions ici puis defini une classe pour l'action (avec parametres)
action:	  PRINT STRING		{ $$ = new ActionPrint (*$2); delete $2; }
	| INITIALISATION	{ $$ = new ActionInit ();}
	| RECHERCHER		{ $$ = new ActionRechercher ();}
	| ROTATION		{ $$ = new ActionRotation ();}
	| AVANCER_PALET		{ $$ = new ActionAvancerPalet ();}
	| NB_PALET_PILE		{ $$ = new ActionNbPaletPile ();}
	| NB_PALET_STOCKE	{ $$ = new ActionNbPaletStocke ();}
	| MISE_EN_PLACE		{ $$ = new ActionMiseEnPlace ();}
	| REPERER_COULEUR NUM	{ $$ = new ActionRepererCouleur ($2);}
	| RETOURNER		{ $$ = new ActionRetourner ();}
	| AVANCER NUM		{ $$ = new ActionAvancer ($2);}
	| RECULER NUM		{ $$ = new ActionReculer ($2);}
	| PLACER_PINCE NUM	{ $$ = new ActionPlacerPince ($2);}
;

receptivite:
	  BOOL			{ $$ = new ReceptiviteBool ($1); }
	| INIT 			{ $$ = new ReceptInit (false); }
	| PALETS_TROUVES	{ $$ = new ReceptPaletsTrouves (false); }
	| PALETS NUM		{ $$ = new ReceptPalets (false,$2); }
	| STOCKE NUM		{ $$ = new ReceptStocke (false,$2); }
	| COULEUR_ADVERSE NUM	{ $$ = new ReceptCouleurAdverse (false,$2); }
	| PINCE_ANGLE NUM	{ $$ = new ReceptPinceAngle (false,$2); }
	| PINCE_POS NUM		{ $$ = new ReceptPincePos (false,$2); }
	| ROBOT_RECULE		{ $$ = new ReceptRobotRecule (false); }
	| ROBOT_AVANCE 		{ $$ = new ReceptRobotAvance (false); }
	| 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:
	  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