forked from rimazou/AnaSyntax2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.l
108 lines (73 loc) · 2.1 KB
/
parser.l
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
%{
#include "global.h"
bool erreurLexical = false;
unsigned int linenbr=1;
%}
letter [a-z]
capLetter [A-Z]
digit [0-9]
identifier ({letter}|{capLetter}|"_")({digit}|{letter}|{capLetter}|"_")*
everything .
%%
\*{3}({everything}|\n)*\*{3} {} /* can be used with files only */
\*{2}{everything}* {}
\'{everything}\' {yylval.text=strdup(yytext[1]); return TOKEN_CHAR;}
\"(\\.|[^"\\])*\" {yylval.text=strdup(yytext); return TOKEN_TEXT;} /*Text is a string*/
{digit}+ {yylval.num=atoi(yytext); return TOKEN_NUMBER;}
"false" { return TOKEN_FALSE;}
"true" { return TOKEN_TRUE;}
"DECLARE" {return TOKEN_DECLARE ;}
"CONST" {return TOKEN_CONST;}
"START" {return TOKEN_START ;}
"STOP" {return TOKEN_STOP ;}
"structure" {return TOKEN_STRUCT;}
"read" {return TOKEN_READ ;}
"write" {return TOKEN_WRITE ;}
"if" {return TOKEN_IF ;}
"else" {return TOKEN_ELSE ;}
"for" {return TOKEN_FOR;}
"in" {return TOKEN_IN ;}
"from" {return TOKEN_FROM ;}
"while" {return TOKEN_WHILE;}
"<-" {return TOKEN_ASSIGN;}
"num" { return NUM;}
"bool" {return BOOL;}
"char" {return CHAR;}
" "* {}/* ignore all space */
"." {return FININSTR;}
"{" {return ACCOLAD_G;}
"}" { return ACCOLAD_D;}
"begin" {return TOKEN_BEGIN;}
"end" {return END;}
"(" {return PARENTHESE_G;}
")" {return PARENTHESE_D;}
"[" {return CROCHET_G;}
"]" {return CROCHET_D;}
"<" {return TOKEN_INF;}
">" {return TOKEN_SUP;}
"<=" {return TOKEN_INFEGAL;}
">=" {return TOKEN_SUPEGAL;}
"=" {return TOKEN_EGAL;}
"!=" {return TOKEN_DIFF;}
"+" {return TOKEN_ADD;}
"-" {return TOKEN_SOUSTR;}
"*" {return TOKEN_MULT;}
"/" {return TOKEN_DIVIS;}
"mod" {return TOKEN_MOD;}
"not" {return TOKEN_NOT;}
"and" {return TOKEN_AND;}
"or" {return TOKEN_OR;}
"," {return TOKEN_COMMA;}
":" {return TOKEN_ACSTRUCT;}
{identifier} {
//AjouterTable(table->Entete_llc, "identifier",yytext);
yylval.text = strdup(yytext);
return TOKEN_ID;
}
# {return TOKEN_FININPUT;}
"\n" {linenbr++;}
. {fprintf(stderr,"\tERREUR : Lexeme inconnu a la ligne %d. Il s'agit de %s et comporte %d lettre(s)\n",linenbr,yytext,yyleng);
erreurLexical = true;
return yytext[0];}
%%
int yywrap() {};