-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.ypp
More file actions
181 lines (146 loc) · 4.7 KB
/
parser.ypp
File metadata and controls
181 lines (146 loc) · 4.7 KB
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
178
179
180
181
%{
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <map>
#include <QtGui>
#include <QApplication>
#include "monDessin.h"
#include "Figure.hpp"
#include "Option.hpp"
#include "Rectangle.hpp"
#include "Cercle.hpp"
#include "Ligne.hpp"
#include "global.h"
#define YYERROR_VERBOSE
#define USE(VALUE) /*empty*/
extern "C" int yyparse (void);
extern "C" int yylex(void);
extern "C" void yyerror(const std::string&);
extern FILE* yyin;
std::vector<Figure> liste_figures;
//0 pour un rectangle, 1 pour un cercle et 2 pour une ligne
std::vector<int> which_figure;
enum type_option { couleur, rotation, remplissage, epaisseur, opacite };
enum nom_forme { rectangle, cercle, ligne };
enum nom_couleur { rouge, vert, bleu, jaune, noir, blanc, gris };
std::map<type_option, typegeneral> options_separees;
QPointer<monDessin> D;
%}
%union{
double valeur_numerique;
char indice_table_symboles;
int entier;
Figure figure;
Option opt;
}
%token <valeur_numerique> NOMBRE
%token <entier> NOM_FORME
%token <entier> COULEUR
%token <entier> REMPLISSAGE
%token MOT_COULEUR MOT_EPAISSEUR MOT_OPACITE MOT_REMPLISSAGE MOT_ROTATION
%token PARENTHESE_OUVRANTE PARENTHESE_FERMANTE
%token ACCOLADE_OUVRANTE ACCOLADE_FERMANTE
%token EGAL
%token VIRGULE
%token POURCENT
%token DEGRE
%token FIN
%token END
%type<opt> liste_options
%type<figure> Expression_Complete
%type<figure> DeclarationForme
%left VARIABLE
%start Input
%%
Input:
/* Vide */
| Input Ligne
;
Ligne:
FIN { std::cout << "Fin de la Ligne - Ligne Vide" << std::endl; }
| Expression_Complete FIN { std::cout << "Fin de l'expression ONE-LINE" << std::endl; }
| Expression_longue FIN { std::cout << "Fin de l'expression MULTI-LINE" << std::endl; }
| END FIN {printf("fin du programme\n"); return 0;}
;
Expression_Complete:
NOM_FORME PARENTHESE_OUVRANTE NOMBRE VIRGULE NOMBRE VIRGULE NOMBRE VIRGULE NOMBRE PARENTHESE_FERMANTE ACCOLADE_OUVRANTE liste_options ACCOLADE_FERMANTE
{
which_figure.push_back($1);
Figure fig($3,$5,$7,$9);
fig.setOption($12);
liste_figures.push_back(fig);
$$= fig;
}
;
liste_options:
FIN { Option vide; $$= vide; }
| COULEUR VIRGULE NOMBRE VIRGULE REMPLISSAGE VIRGULE NOMBRE VIRGULE NOMBRE POURCENT
{ Option tmp($1, $3, $5, $7, $9); $$= tmp;}
;
Option:
MOT_COULEUR EGAL COULEUR FIN { std::cout << "couleur=COULEUR" << std::endl;
type_option id= couleur;
typegeneral col; col.entier= $3;
std::pair<type_option, typegeneral> current_opt= std::make_pair(id, col);
options_separees.insert(current_opt);
}
| MOT_ROTATION EGAL NOMBRE DEGRE FIN { std::cout << "rotation=ROTATION" << std::endl;
type_option id= rotation;
typegeneral rot; rot.entier= $3;
std::pair<type_option, typegeneral> current_opt= std::make_pair(id, rot);
options_separees.insert(current_opt);
}
| MOT_REMPLISSAGE EGAL REMPLISSAGE FIN { std::cout << "remplissage=REMPLISSAGE" << std::endl;
type_option id= remplissage;
typegeneral remp; remp.booleen= $3;
std::pair<type_option, typegeneral> current_opt= std::make_pair(id, remp);
options_separees.insert(current_opt);
}
| MOT_EPAISSEUR EGAL NOMBRE FIN { std::cout << "epaisseur=EPAISSEUR" << std::endl;
type_option id= epaisseur;
typegeneral ep; ep.entier= $3;
std::pair<type_option, typegeneral> current_opt= std::make_pair(id, ep);
options_separees.insert(current_opt);
}
| MOT_OPACITE EGAL NOMBRE POURCENT FIN { std::cout << "opacite=OPACITE" << std::endl;
type_option id= opacite;
typegeneral op; op.entier= $3;
std::pair<type_option, typegeneral> current_opt= std::make_pair(id, op);
options_separees.insert(current_opt);
}
;
Options:
{ std::cout << "fin des options separees" << std::endl; }
| Option Options { std::cout << "ajout d'une option" << std::endl; }
;
DeclarationForme:
NOM_FORME PARENTHESE_OUVRANTE NOMBRE VIRGULE NOMBRE VIRGULE NOMBRE VIRGULE NOMBRE PARENTHESE_FERMANTE ACCOLADE_OUVRANTE FIN
{ std::cout << "Declaration d'une Forme (Forme et Coordonnees)" << std::endl;
which_figure.push_back($1);
Figure fig($3,$5,$7,$9);
liste_figures.push_back(fig);
$$= fig;
}
;
Expression_longue:
DeclarationForme Options ACCOLADE_FERMANTE FIN
{ std::cout << "Fin de l'expression longue" << std::endl; }
;
%%
void trace(QMainWindow * w){
D = new monDessin;
w->setCentralWidget(D);
w->setMinimumSize(800, 600);
yyparse();
D->setFigures(liste_figures);
D->setWhichFigure(which_figure);
D->draw();
w->show();
return ;
}
void yyerror(const std::string& mess){
std::cout << mess << std::endl;
}