forked from meakitfed/ProjetMort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tp.l
89 lines (71 loc) · 2.04 KB
/
tp.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
Chiffre [0-9]
Entier {Chiffre}+
Lower [a-z]
Upper [A-Z]
Lettre [a-zA-Z]
LC ({Lettre}|{Chiffre})
Delim [ \b\t\n\r]
Symbole [\():;,.{}]
BS \\.
PasBSG [^\\"]
Guill "\""
Star "*"
NotStar [^*]
NotStarPar [^*/]
%{
#include <string.h>
#include <strings.h>
#include "tp.h"
#include "tp_y.h"
extern char *strdup(const char *);
extern YYSTYPE yylval;
extern int yylineno;
extern int yylex();
int keywordOrId() {
if (! strcmp(yytext, "is")) return IS;
if (! strcmp(yytext, "class")) return CLASS;
if (! strcmp(yytext, "var")) return VAR;
if (! strcmp(yytext, "extends")) return EXTENDS;
if (! strcmp(yytext, "def")) return DEF;
if (! strcmp(yytext, "override")) return OVERRIDE;
if (! strcmp(yytext, "if")) return IF;
if (! strcmp(yytext, "then")) return THEN;
if (! strcmp(yytext, "else")) return ELSE;
if (! strcmp(yytext, "new")) return NEWC;
if (! strcmp(yytext, "return")) return RETURN;
if (! strcmp(yytext, "object")) return OBJECT;
yylval.S = strdup(yytext);
return(Id);
}
int IdClasse() {
yylval.S = strdup(yytext);
return(Classname);
}
void lexError(char c) {
fprintf(stderr, "Error: Skipping invalid character '%c' on line %d\n",
c, yylineno);
setError(LEXICAL_ERROR);
}
%}
%%
{Entier} { yylval.I = atoi(yytext); return(Cste); }
{Delim} { }
{Symbole} { return(yytext[0]); }
":=" { return(AFF); }
"=" { yylval.C = EQ; return(RelOp); }
"<>" { yylval.C = NE; return(RelOp); }
"<=" { yylval.C = INFE; return(RelOp); }
">=" { yylval.C = SUPE; return(RelOp); }
">" { yylval.C = SUP; return(RelOp); }
"<" { yylval.C = INF; return(RelOp); }
"+" { return(ADD); }
"-" { return(SUB); }
"*" { return(MUL); }
"/" { return(DIV); }
"&" { return(CONCAT); }
"/*"({NotStar}|({Star}+{NotStarPar}))*{Star}*"*/" { }
{Lower}{LC}* { return keywordOrId(); }
{Upper}{LC}* { return IdClasse(); }
{Guill}({BS}|{PasBSG})*{Guill} {yylval.S = strdup(yytext); return Chaine;}
. { lexError(yytext[0]); }
%%