Subversion Repositories wimsdev

Rev

Rev 13121 | 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
 
17747 georgesk 11
   #ifndef size_t
12
   #define size_t int
13
   #endif     
10 reyssat 14
 
15
/* les nombres */
16
digits         [0-9]
17
spc            [ \t]+
18
int            {digits}+
19
frac           {int}{spc}?[/]{spc}?{int}
20
mantisse       {digits}+
104 bpr 21
real           -?{int}([.]{mantisse})?([Ee][+-]?{int})?
10 reyssat 22
eol            \n.*
23
 
104 bpr 24
/* la flèche */
10 reyssat 25
fleche         [-]+>
26
 
13121 georgesk 27
/* la double flèche */
28
dfleche        <[-]+>
29
 
17747 georgesk 30
/* fonction spéciale : toute chaîne préfixée par "func:" */
31
func          func:.*
32
 
10 reyssat 33
%%
104 bpr 34
 /* les règles */
10 reyssat 35
 
36
 /* pour les atomes */
12963 georgesk 37
Uu[a-z]|[A-Z][a-z]? { /* éléments Uux : transuraniens après le N° 109
104 bpr 38
                           les autres sont les éléments ordinaires */
10 reyssat 39
    int i = 0;
40
    position += strlen(yytext);
41
    while (lesatomes[i].Zed != 0 && strcmp(yytext, lesatomes[i].symb)) i++;
42
    if (lesatomes[i].Zed == 0){
104 bpr 43
      yylval.i=-2;      /* -2 est le n° pour les éléments non définis */
10 reyssat 44
      strncpy(yylval.symb, yytext,3);
45
    }
46
    else {
47
      yylval.i=i;
48
      strcpy(yylval.symb, lesatomes[i].symb);
49
    }
50
    yylval.s = yytext;
51
    return Atome;
52
  }
53
 
54
e      {position++; yylval.i=-1; strcpy(yylval.symb, "e");return Atome;}
55
 
56
 
57
\(     { position++; return Lpar;}
58
\)     { position++; return Rpar;}
59
 
60
{spc}+\( { position += strlen(yytext); return SpcLpar;}
61
\[       { position ++; return Lsq;}
62
\]       { position ++; return Rsq;}
63
{int}  { position += strlen(yytext); yylval.i = atoi(yytext); return Int; }
64
{real} { position += strlen(yytext); yylval.r = atof(yytext); return Real;}
65
{frac} { position += strlen(yytext); ind = index(yytext,'/'); *ind=0; 
66
         yylval.i = atoi(yytext); yylval.d = atoi(ind+1); 
67
         return Frac;
68
       }
69
\+{int}  { position += strlen(yytext); yylval.i = atoi(yytext+1); 
70
           return Charge;
71
         }
72
\+[\+]+  { position += strlen(yytext); 
73
           yylval.i = strlen(yytext); return Charge;
74
         }
75
\-[\-]+  { position += strlen(yytext); yylval.i = -strlen(yytext); 
76
           return Charge;
77
         }
78
{int}\+  { position += strlen(yytext); yytext[strlen(yytext)]=0; 
79
           yylval.i = atoi(yytext); return Charge;
80
         }
81
{int}\-  { position += strlen(yytext); yytext[strlen(yytext)]=0; 
82
           yylval.i = -atoi(yytext); return Charge;
83
         }
84
{spc}+\+ {position += strlen(yytext); return SpcPlus;}
104 bpr 85
\-       {position += strlen(yytext); return Moins;}
86
\+       {position ++; return Plus;} 
87
\*       {position ++; return Mul;}
13121 georgesk 88
{dfleche} {position += strlen(yytext); return Dfleche;}
10 reyssat 89
{fleche} {position += strlen(yytext); return Fleche;}
104 bpr 90
{spc}    {position += strlen(yytext); return Spc;}
91
\^       {position ++; return Haut;}
12963 georgesk 92
_\(s\)|_s|s     {position += strlen(yytext); return Sol;}
93
_\(l\)|_l|l     {position += strlen(yytext); return Liq;}
94
_\(g\)|_g|g     {position += strlen(yytext); return Gas;}
95
_\(aq\)|_ag|aq   {position += strlen(yytext); return Aqueous;}
104 bpr 96
=        {position ++; return Egal;}
97
#        {position ++; return Compose;}
98
~        {position+=2; return AntiCompose;}
17747 georgesk 99
{func}   {position += strlen(yytext); yytext[strlen(yytext)]=0; 
100
  yylval.s = yytext+strlen("func:"); return Func;}
104 bpr 101
{eol}    {/* rien c'est la fin des entrées */}
102
.|\n     {position += strlen(yytext); /* rien */}
17747 georgesk 103