-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.y
138 lines (133 loc) · 3.04 KB
/
parser.y
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
%{
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include "EspeceMoleculaire.h"
#include "Reaction.h"
int yyparse();
int yylex(char**);
int yyerror(std::string s);
extern int diametre;
extern std::vector<EspeceMoleculaire*> especes;
extern std::vector<Reaction*> reactions;
%}
%language "c++"
%define api.value.type {char*}
%require "3.2" /*To remove useless stack.hh*/
%token IDENT
%token NUMBER
%token SPECIES
%token LP
%token RP
%token LB
%token RB
%token COMMA
%token SEMI
%token EQUALS
%token SIZE
%token SPEED
%token POP
%token DIAM
%token PLUS
%token ARROW
%%
MODELE : SDECL SINST
;
DECL : SPECIES LISTID SEMI {}
;
LISTID : IDENT {especes.push_back(new EspeceMoleculaire($1));}
| LISTID COMMA IDENT {especes.push_back(new EspeceMoleculaire($3));}
;
SIZEM : SIZE LP IDENT RP EQUALS NUMBER SEMI {
for(EspeceMoleculaire* e : especes)
{
if(e->getNom() == $3)
{
e->setTaille(atoi($6));
break;
}
}
}
;
SPEEDM : SPEED LP IDENT RP EQUALS NUMBER SEMI {
for(EspeceMoleculaire* e : especes)
{
if(e->getNom() == $3)
{
e->setVitesse(atof($6));
break;
}
}
}
;
POPM : POP LP IDENT RP EQUALS NUMBER SEMI {
for(EspeceMoleculaire* e : especes)
{
if(e->getNom() == $3)
{
e->pop = atoi($6);
break;
}
}
}
;
DIA : DIAM EQUALS NUMBER SEMI {diametre = atoi($3);}
;
REACT : IDENT REACTID ARROW IDENT REACTID LB NUMBER RB SEMI {
EspeceMoleculaire *r1, *r2, *p1, *p2;
bool dr = false;
for(EspeceMoleculaire* e : especes)
{
if(e->getNom() == $1){
r1 = e;
dr = true;
}
}
dr = false;
for(EspeceMoleculaire* e : especes)
{
if(e->getNom() == $2){
r2 = e;
dr = true;
}
}
bool dp = false;
for(EspeceMoleculaire* e : especes)
{
if(e->getNom() == $4){
p1 = e;
dp = true;
}
}
dp = false;
for(EspeceMoleculaire* e : especes)
{
if(e->getNom() == $5){
p2 = e;
dp = true;
}
}
reactions.push_back(new Reaction(r1, r2, p1, p2, dr, dp, atof($7)));
}
;
REACTID : { char txt[1] = "";
$$ = txt;}
| PLUS IDENT {$$ = $2;}
;
SDECL : DECL
| SDECL DECL
;
SINST : INST
| SINST INST
;
INST : REACT
| DIA
| SIZEM
| SPEEDM
| POPM
;
%%
void yy::parser::error(const std::string& msg) {
std::cerr << "yyerror : " << msg << std::endl;
}