Rev 13327 | Rev 17770 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 13327 | Rev 17747 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | #include <math.h> |
8 | #include <math.h> |
9 | #include "chemeq.h" |
9 | #include "chemeq.h" |
10 | //#include <FlexLexer.h> |
10 | //#include <FlexLexer.h> |
11 | #include <sstream> |
11 | #include <sstream> |
12 | 12 | ||
- | 13 | #include "html_table.cc" |
|
- | 14 | ||
13 | int yylex(); |
15 | int yylex(); |
14 | int chemerror(char * msg); |
16 | int chemerror(char * msg); |
15 | int yyerror(const char * msg); |
17 | int yyerror(const char * msg); |
16 | 18 | ||
17 | typedef struct{ |
19 | typedef struct{ |
Line 60... | Line 62... | ||
60 | %token Gas |
62 | %token Gas |
61 | %token Aqueous |
63 | %token Aqueous |
62 | %token Egal |
64 | %token Egal |
63 | %token Compose |
65 | %token Compose |
64 | %token AntiCompose |
66 | %token AntiCompose |
65 | 67 | %token Func |
|
66 | %% |
68 | %% |
67 | 69 | ||
68 | /* les règles */ |
70 | /* les règles */ |
69 | but : chcompose { |
71 | but : chcompose { |
70 | result=$1; |
72 | result=$1; |
71 | isequation=1; |
73 | isequation=1; |
72 | } |
74 | } |
73 | | molec { |
75 | | molec { |
74 | result=$1; |
76 | result=$1; |
75 | isequation=0; |
77 | isequation=0; |
76 | } |
78 | } |
- | 79 | | special_func { |
|
- | 80 | result=$1; |
|
- | 81 | isequation=-1; |
|
- | 82 | } |
|
77 | ; |
83 | ; |
78 | 84 | ||
79 | chcompose : chc {$$=$1;} |
85 | chcompose : chc {$$=$1;} |
80 | | chcompose spc01 Compose spc01 chc { |
86 | | chcompose spc01 Compose spc01 chc { |
81 | $1.cq->addChemeq($5.cq); |
87 | $1.cq->addChemeq($5.cq); |
82 | $$=$1; |
88 | $$=$1; |
83 | } |
89 | } |
84 | | chcompose spc01 AntiCompose spc01 chc { |
90 | | chcompose spc01 AntiCompose spc01 chc { |
85 | $1.cq->subChemeq($5.cq); |
91 | $1.cq->subChemeq($5.cq); |
86 | $$=$1; |
92 | $$=$1; |
87 | } |
93 | } |
88 | ; |
94 | ; |
89 | 95 | ||
90 | chc : chemeq cste{ |
96 | chc : chemeq cste{ |
91 | $$=$1; |
97 | $$=$1; |
Line 95... | Line 101... | ||
95 | | Frac spc01 Mul spc01 chc { |
101 | | Frac spc01 Mul spc01 chc { |
96 | $$.cq = $5.cq; $$.cq->multiply($1.i,$1.d); |
102 | $$.cq = $5.cq; $$.cq->multiply($1.i,$1.d); |
97 | } |
103 | } |
98 | | Int spc01 Mul spc01 chc { |
104 | | Int spc01 Mul spc01 chc { |
99 | $$.cq = $5.cq; $$.cq->multiply($1.i,1); |
105 | $$.cq = $5.cq; $$.cq->multiply($1.i,1); |
100 | } |
106 | } |
101 | ; |
107 | ; |
102 | 108 | ||
103 | cste : /* rien */ {$$.s = ""; $$.r = MINVAL; /* valeur négative : non défini */} |
109 | cste : /* rien */ {$$.s = ""; $$.r = MINVAL; /* valeur négative : non défini */} |
104 | | SpcLpar cste1 Rpar {$$ = $2;} |
110 | | SpcLpar cste1 Rpar {$$ = $2;} |
105 | ; |
111 | ; |
Line 112... | Line 118... | ||
112 | | Int {$$.r=1.0*$1.i;} |
118 | | Int {$$.r=1.0*$1.i;} |
113 | | Plus spc01 Real{$$.r=$3.r;} |
119 | | Plus spc01 Real{$$.r=$3.r;} |
114 | | Moins spc01 Real{$$.r=-$3.r;} |
120 | | Moins spc01 Real{$$.r=-$3.r;} |
115 | | Plus spc01 Int{$$.r=1.0*$3.i;} |
121 | | Plus spc01 Int{$$.r=1.0*$3.i;} |
116 | | Moins spc01 Int{$$.r=-1.0*$3.i;} |
122 | | Moins spc01 Int{$$.r=-1.0*$3.i;} |
117 | ; |
123 | ; |
118 | 124 | ||
119 | volt : /* rien */ |
125 | volt : /* rien */ |
120 | | spc01 Atome {if ($2.s.compare("V")!=0) chemerror (strdup("only 'V' allowed as unit")); } |
126 | | spc01 Atome {if ($2.s.compare("V")!=0) chemerror (strdup("only 'V' allowed as unit")); } |
121 | ; |
127 | ; |
122 | 128 | ||
123 | id : Atome {/* $$.s contient le nom */} |
129 | id : Atome {/* $$.s contient le nom */} |
124 | ; |
130 | ; |
125 | 131 | ||
126 | chemeq : membre Spc Fleche spc01 membre{ |
132 | chemeq : membre Spc Fleche spc01 membre{ |
127 | $$.cq = new Chemeq($1.mb,$5.mb); |
133 | $$.cq = new Chemeq($1.mb,$5.mb); |
128 | } |
134 | } |
129 | | membre Spc Dfleche spc01 membre{ |
135 | | membre Spc Dfleche spc01 membre{ |
130 | $$.cq = new Chemeq($1.mb,$5.mb,true); |
136 | $$.cq = new Chemeq($1.mb,$5.mb,true); |
131 | } |
137 | } |
132 | ; |
138 | ; |
133 | 139 | ||
134 | membre : membre SpcPlus spc01 molecs { |
140 | membre : membre SpcPlus spc01 molecs { |
135 | $$.mb->addMol($4.m); |
141 | $$.mb->addMol($4.m); |
136 | } |
142 | } |
137 | | molecs { |
143 | | molecs { |
138 | $$.mb = new Membre; |
144 | $$.mb = new Membre; |
139 | $$.mb->push_back($1.m); |
145 | $$.mb->push_back($1.m); |
140 | } |
146 | } |
141 | ; |
147 | ; |
142 | 148 | ||
143 | molecs : Int spc01 molec { |
149 | molecs : Int spc01 molec { |
144 | $$ = $3; |
150 | $$ = $3; |
145 | $$.m->nombre($1.i); |
151 | $$.m->nombre($1.i); |
146 | } |
152 | } |
147 | | Frac spc01 molec { |
153 | | Frac spc01 molec { |
148 | $$ = $3; |
154 | $$ = $3; |
149 | $$.m->nombre($1.i,$1.d); |
155 | $$.m->nombre($1.i,$1.d); |
150 | } |
156 | } |
151 | | molec{ |
157 | | molec{ |
152 | $$ = $1; |
158 | $$ = $1; |
153 | } |
159 | } |
154 | ; |
160 | ; |
155 | 161 | ||
156 | spc01 : /*rien*/ |
162 | spc01 : /*rien*/ |
157 | | Spc |
163 | | Spc |
158 | ; |
164 | ; |
159 | 165 | ||
160 | molec : composition0 typage{ |
166 | molec : composition0 typage{ |
161 | $$.m = new Molec($1.al,0); $$.m->typage($2.t); |
167 | $$.m = new Molec($1.al,0); $$.m->typage($2.t); |
162 | } |
168 | } |
163 | | composition0 charge typage{ |
169 | | composition0 charge typage{ |
164 | $$.m = new Molec($1.al,$2.i);$$.m->typage($3.t); |
170 | $$.m = new Molec($1.al,$2.i);$$.m->typage($3.t); |
165 | } |
171 | } |
166 | ; |
172 | ; |
167 | 173 | ||
168 | 174 | ||
169 | composition0 : composition {$$.al=$1.al;} |
175 | composition0 : composition {$$.al=$1.al;} |
170 | | Lsq spc01 composition spc01 Rsq {$$.al=$3.al; $$.al->sq(1);} |
176 | | Lsq spc01 composition spc01 Rsq {$$.al=$3.al; $$.al->sq(1);} |
171 | ; |
177 | ; |
172 | 178 | ||
173 | typage : /* rien */ {$$.t = aqueous;} |
179 | typage : /* rien */ {$$.t = aqueous;} |
174 | | Aqueous {$$.t = aqueous_explicit;} |
180 | | Aqueous {$$.t = aqueous_explicit;} |
175 | | Sol {$$.t = sol;} |
181 | | Sol {$$.t = sol;} |
176 | | Liq {$$.t = liquid;} |
182 | | Liq {$$.t = liquid;} |
177 | | Gas {$$.t = gas;} |
183 | | Gas {$$.t = gas;} |
Line 217... | Line 223... | ||
217 | $$.i=1; |
223 | $$.i=1; |
218 | } |
224 | } |
219 | | Int { |
225 | | Int { |
220 | $$=$1; |
226 | $$=$1; |
221 | } |
227 | } |
- | 228 | ; |
|
- | 229 | ||
- | 230 | special_func : Func { |
|
- | 231 | $$.s=$1.s; |
|
- | 232 | } |
|
222 | ; |
233 | ; |
223 | 234 | ||
224 | %% |
235 | %% |
225 | #include "chemlex.cc" |
236 | #include "chemlex.cc" |
226 | 237 | ||
Line 298... | Line 309... | ||
298 | thelexer= new yyFlexLexer (&iss); |
309 | thelexer= new yyFlexLexer (&iss); |
299 | } |
310 | } |
300 | yyparse(); |
311 | yyparse(); |
301 | 312 | ||
302 | bool wantedlatex=(strchr(asked,'l')!=NULL); |
313 | bool wantedlatex=(strchr(asked,'l')!=NULL); |
303 | if (isequation) { |
314 | if (isequation == 1) { |
304 | for(i=0; i<strlen(asked); i++){ |
315 | for(i=0; i<strlen(asked); i++){ |
305 | switch(asked[i]){ |
316 | switch(asked[i]){ |
306 | case 'm': nooption=0; |
317 | case 'm': nooption=0; |
307 | result.cq->printnorm(std::cout); std::cout << std::endl; |
318 | result.cq->printnorm(std::cout); std::cout << std::endl; |
308 | break; |
319 | break; |
Line 344... | Line 355... | ||
344 | result.cq->normalise(); |
355 | result.cq->normalise(); |
345 | result.cq->printnorm(std::cout); std::cout << std::endl; |
356 | result.cq->printnorm(std::cout); std::cout << std::endl; |
346 | } |
357 | } |
347 | } |
358 | } |
348 | else { /* ce n'est pas une équation */ |
359 | else { /* ce n'est pas une équation */ |
- | 360 | if (isequation == 0) { |
|
- | 361 | /* c'est une molécule */ |
|
349 | for(i=0; i<strlen(asked); i++){ |
362 | for(i=0; i<strlen(asked); i++){ |
350 |
|
363 | switch(asked[i]){ |
351 |
|
364 | case 'M': nooption=0; |
352 | std::cout << result.m->weight(); |
365 | std::cout << result.m->weight(); |
353 | std::cout << std::endl; |
366 | std::cout << std::endl; |
354 | break; |
367 | break; |
- | 368 | } |
|
- | 369 | } |
|
- | 370 | if (nooption){ |
|
- | 371 | std::cout << *result.m; |
|
355 | } |
372 | } |
356 | } |
373 | } |
357 |
|
374 | else { |
- | 375 | /* c'est une fonction spéciale */ |
|
358 |
|
376 | if (result.s == "html_table"){ |
- | 377 | std::cout << html_table << std::endl; |
|
- | 378 | } else { |
|
- | 379 | std::cout << "ERROR: no feature named “" << result.s << "”" << std::endl; |
|
- | 380 | } |
|
359 | } |
381 | } |
360 | } |
382 | } |
361 | return 0; |
383 | return 0; |
362 | } |
384 | } |