-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.lex
54 lines (36 loc) · 828 Bytes
/
calc.lex
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
%{
#include "global.h"
#include "calc.h"
#include <stdlib.h>
%}
blancs [ \t]+
chiffre [0-9]
entier {chiffre}+
exposant [eE][+-]?{entier}
reel {entier}("."{entier})?{exposant}?
%%
{blancs} { /* On ignore */ }
{reel} {
yylval.dval=atof(yytext);
return(NOMBRE);
}
"+" return(PLUS);
"-" return(MOINS);
"*" return(FOIS);
"/" return(DIVISE);
"^" return(PUISSANCE);
"(" return(PARENTHESE_GAUCHE);
")" return(PARENTHESE_DROITE);
"\n" return(FIN);
[_a-zA-Z][_a-zA-Z0-9]* {
yylval.cval = strdup(yytext);
// printf("found symbole: '%s'\n", yytext);
return(SYMBOLE);
}
%%
void parseExpr(char* my_string) {
YY_BUFFER_STATE my_string_buffer = yy_scan_string (my_string);
/* my_parse_result = */
yyparse ();
yy_delete_buffer (my_string_buffer);
}