Rev 104 | Rev 13121 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
104 | bpr | 1 | /* -*- coding: utf-8 -*- */ |
10 | reyssat | 2 | %option noyywrap |
3 | %option c++ |
||
4 | |||
5 | #include <stdlib.h> |
||
6 | #include "chemeq.h" |
||
7 | |||
8 | char * ind; |
||
9 | int position = 0; |
||
10 | |||
11 | |||
12 | |||
13 | /* les nombres */ |
||
14 | digits [0-9] |
||
15 | spc [ \t]+ |
||
16 | int {digits}+ |
||
17 | frac {int}{spc}?[/]{spc}?{int} |
||
18 | mantisse {digits}+ |
||
104 | bpr | 19 | real -?{int}([.]{mantisse})?([Ee][+-]?{int})? |
10 | reyssat | 20 | eol \n.* |
21 | |||
104 | bpr | 22 | /* la flèche */ |
10 | reyssat | 23 | fleche [-]+> |
24 | |||
25 | %% |
||
104 | bpr | 26 | /* les règles */ |
10 | reyssat | 27 | |
28 | /* pour les atomes */ |
||
12963 | georgesk | 29 | Uu[a-z]|[A-Z][a-z]? { /* éléments Uux : transuraniens après le N° 109 |
104 | bpr | 30 | les autres sont les éléments ordinaires */ |
10 | reyssat | 31 | int i = 0; |
32 | position += strlen(yytext); |
||
33 | while (lesatomes[i].Zed != 0 && strcmp(yytext, lesatomes[i].symb)) i++; |
||
34 | if (lesatomes[i].Zed == 0){ |
||
104 | bpr | 35 | yylval.i=-2; /* -2 est le n° pour les éléments non définis */ |
10 | reyssat | 36 | strncpy(yylval.symb, yytext,3); |
37 | } |
||
38 | else { |
||
39 | yylval.i=i; |
||
40 | strcpy(yylval.symb, lesatomes[i].symb); |
||
41 | } |
||
42 | yylval.s = yytext; |
||
43 | return Atome; |
||
44 | } |
||
45 | |||
46 | e {position++; yylval.i=-1; strcpy(yylval.symb, "e");return Atome;} |
||
47 | |||
48 | |||
49 | \( { position++; return Lpar;} |
||
50 | \) { position++; return Rpar;} |
||
51 | |||
52 | {spc}+\( { position += strlen(yytext); return SpcLpar;} |
||
53 | \[ { position ++; return Lsq;} |
||
54 | \] { position ++; return Rsq;} |
||
55 | {int} { position += strlen(yytext); yylval.i = atoi(yytext); return Int; } |
||
56 | {real} { position += strlen(yytext); yylval.r = atof(yytext); return Real;} |
||
57 | {frac} { position += strlen(yytext); ind = index(yytext,'/'); *ind=0; |
||
58 | yylval.i = atoi(yytext); yylval.d = atoi(ind+1); |
||
59 | return Frac; |
||
60 | } |
||
61 | \+{int} { position += strlen(yytext); yylval.i = atoi(yytext+1); |
||
62 | return Charge; |
||
63 | } |
||
64 | \+[\+]+ { position += strlen(yytext); |
||
65 | yylval.i = strlen(yytext); return Charge; |
||
66 | } |
||
67 | \-[\-]+ { position += strlen(yytext); yylval.i = -strlen(yytext); |
||
68 | return Charge; |
||
69 | } |
||
70 | {int}\+ { position += strlen(yytext); yytext[strlen(yytext)]=0; |
||
71 | yylval.i = atoi(yytext); return Charge; |
||
72 | } |
||
73 | {int}\- { position += strlen(yytext); yytext[strlen(yytext)]=0; |
||
74 | yylval.i = -atoi(yytext); return Charge; |
||
75 | } |
||
76 | {spc}+\+ {position += strlen(yytext); return SpcPlus;} |
||
104 | bpr | 77 | \- {position += strlen(yytext); return Moins;} |
78 | \+ {position ++; return Plus;} |
||
79 | \* {position ++; return Mul;} |
||
10 | reyssat | 80 | {fleche} {position += strlen(yytext); return Fleche;} |
104 | bpr | 81 | {spc} {position += strlen(yytext); return Spc;} |
82 | \^ {position ++; return Haut;} |
||
12963 | georgesk | 83 | _\(s\)|_s|s {position += strlen(yytext); return Sol;} |
84 | _\(l\)|_l|l {position += strlen(yytext); return Liq;} |
||
85 | _\(g\)|_g|g {position += strlen(yytext); return Gas;} |
||
86 | _\(aq\)|_ag|aq {position += strlen(yytext); return Aqueous;} |
||
104 | bpr | 87 | = {position ++; return Egal;} |
88 | # {position ++; return Compose;} |
||
89 | ~ {position+=2; return AntiCompose;} |
||
90 | {eol} {/* rien c'est la fin des entrées */} |
||
91 | .|\n {position += strlen(yytext); /* rien */} |