Subversion Repositories wimsdev

Rev

Rev 8206 | Rev 13121 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8206 Rev 12963
Line 9... Line 9...
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
  int yylex();
13
  int yylex();
14
  int yyerror(const char * msg);
14
  int yyerror(char * msg);
15
 
15
 
16
typedef struct{
16
typedef struct{
17
  int i, d; /* integer numerator, denominator */
17
  int i, d; /* integer numerator, denominator */
18
  double r;
18
  double r;
19
  AtomeListe * al;
19
  AtomeListe * al;
Line 23... Line 23...
23
  char symb[4];
23
  char symb[4];
24
  moltype t;
24
  moltype t;
25
  std::string s;
25
  std::string s;
26
} yystype;
26
} yystype;
27
 
27
 
28
#define YYSTYPE yystype
28
#define YYSTYPE yystype 
29
 
29
 
30
/* variables globales */
30
/* variables globales */
31
 
31
 
32
 yystype result;
32
 yystype result;
33
 extern char * yytext;
33
 extern char * yytext;
Line 52... Line 52...
52
%token Lsq
52
%token Lsq
53
%token Rsq
53
%token Rsq
54
%token Haut
54
%token Haut
55
%token Spc
55
%token Spc
56
%token Sol
56
%token Sol
-
 
57
%token Liq
57
%token Gas
58
%token Gas
58
%token Aqueous
59
%token Aqueous
59
%token Egal
60
%token Egal
60
%token Compose
61
%token Compose
61
%token AntiCompose
62
%token AntiCompose
62
 
63
 
63
%%
64
%%
64
 
65
 
65
/* les règles */
66
/* les règles */
66
but : chcompose {
67
but : chcompose { 
67
  result=$1;
68
  result=$1;
68
  isequation=1;
69
  isequation=1;
69
}
70
}
70
| molec {
71
| molec {
71
  result=$1;
72
  result=$1;
Line 76... Line 77...
76
chcompose : chc {$$=$1;}
77
chcompose : chc {$$=$1;}
77
| chcompose spc01 Compose spc01 chc {
78
| chcompose spc01 Compose spc01 chc {
78
  $1.cq->addChemeq($5.cq);
79
  $1.cq->addChemeq($5.cq);
79
  $$=$1;
80
  $$=$1;
80
}
81
}
81
| chcompose spc01 AntiCompose spc01 chc {
82
| chcompose spc01 AntiCompose spc01 chc { 
82
  $1.cq->subChemeq($5.cq);
83
  $1.cq->subChemeq($5.cq);
83
  $$=$1;
84
  $$=$1;
84
}
85
}
85
;
86
;
86
 
87
 
Line 141... Line 142...
141
| Frac spc01 molec {
142
| Frac spc01 molec {
142
  $$ = $3;
143
  $$ = $3;
143
  $$.m->nombre($1.i,$1.d);
144
  $$.m->nombre($1.i,$1.d);
144
}
145
}
145
| molec{
146
| molec{
146
  $$ = $1;
147
  $$ = $1; 
147
}
148
}
148
;
149
;
149
 
150
 
150
spc01 : /*rien*/
151
spc01 : /*rien*/
151
| Spc
152
| Spc
Line 163... Line 164...
163
composition0 : composition {$$.al=$1.al;}
164
composition0 : composition {$$.al=$1.al;}
164
| Lsq spc01 composition spc01 Rsq {$$.al=$3.al; $$.al->sq(1);}
165
| Lsq spc01 composition spc01 Rsq {$$.al=$3.al; $$.al->sq(1);}
165
;
166
;
166
 
167
 
167
typage : /* rien */ {$$.t = aqueous;}
168
typage : /* rien */ {$$.t = aqueous;}
168
| Aqueous {$$.t = aqueous;}
169
| Aqueous {$$.t = aqueous_explicit;}
169
| Sol {$$.t = sol;}
170
| Sol {$$.t = sol;}
-
 
171
| Liq {$$.t = liquid;}
170
| Gas {$$.t = gas;}
172
| Gas {$$.t = gas;}
171
;
173
;
172
 
174
 
173
charge : Plus {$$.i=1;}
175
charge : Plus {$$.i=1;}
174
| Haut Plus {$$.i=1;}
176
| Haut Plus {$$.i=1;}
Line 176... Line 178...
176
| Moins{$$.i=-1;}
178
| Moins{$$.i=-1;}
177
| Haut  Moins{$$.i=-1;}
179
| Haut  Moins{$$.i=-1;}
178
;
180
;
179
 
181
 
180
groupe : Lpar composition Rpar {
182
groupe : Lpar composition Rpar {
181
  $$=$2;
183
  $$=$2; 
182
}
184
}
183
;
185
;
184
 
186
 
185
atome_general : groupe {
187
atome_general : groupe {
186
  $$.al = new AtomeListe("",0,0,$1.al);
188
  $$.al = new AtomeListe("",0,0,$1.al);
187
}
189
}
Line 208... Line 210...
208
 
210
 
209
molecularite : /*rien*/{
211
molecularite : /*rien*/{
210
  $$.i=1;
212
  $$.i=1;
211
}
213
}
212
| Int {
214
| Int {
213
  $$=$1;
215
  $$=$1; 
214
}
216
}
215
;
217
;
216
 
218
 
217
%%
219
%%
218
#include "chemlex.cc"
220
#include "chemlex.cc"
Line 224... Line 226...
224
  return thelexer->yylex();
226
  return thelexer->yylex();
225
}
227
}
226
 
228
 
227
/* le programme lui-même */
229
/* le programme lui-même */
228
 
230
 
229
inline int yyerror(const char * msg){
231
inline int yyerror(char * msg){
230
  fprintf(stderr, "ERROR %s at %d\n ", msg, position);
232
  fprintf(stderr, "ERROR %s at %d\n ", msg, position);
231
  exit(1);
233
  exit(1);
232
}
234
}
233
 
235
 
234
void printVersion(){
236
void printVersion(){
Line 281... Line 283...
281
    printVersion(); return 0;
283
    printVersion(); return 0;
282
  }
284
  }
283
  if (envinput !=NULL){
285
  if (envinput !=NULL){
284
    std::istringstream iss(envinput);
286
    std::istringstream iss(envinput);
285
    thelexer= new yyFlexLexer (&iss);
287
    thelexer= new yyFlexLexer (&iss);
286
  }
288
  } 
287
  yyparse();
289
  yyparse();
288
 
290
 
289
  bool wantedlatex=(strchr(asked,'l')!=NULL);
291
  bool wantedlatex=(strchr(asked,'l')!=NULL);
290
  if (isequation) {
292
  if (isequation) {
291
    for(i=0; i<strlen(asked); i++){
293
    for(i=0; i<strlen(asked); i++){