-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntaxe.lex
48 lines (42 loc) · 883 Bytes
/
syntaxe.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
%{
#include "y.tab.h"
int fail=0;
int line= 0;
extern YYSTYPE yylval;
%}
VARNAME ([a-zA-Z]+[0-9_]*)*
INTEGER [0-9]*
SPACE [ \t]*
%x COMMENT
%%
"/*" {BEGIN COMMENT;}
<COMMENT>"*/" {BEGIN INITIAL;}
<COMMENT>"\n" { line++;}
<COMMENT>. {}
int { return tINTDECL;}
const {return tCONST;}
"{" {return tACCO;}
"}" {return tACCC;}
"<" {return tINF;}
">" {return tSUP;}
"+" {return tADD;}
"-" {return tSUB;}
"*" {return tSTAR;}
"/" {return tDIV;}
"%" {return tPERC;}
"(" {return tPARO;}
")" {return tPARC;}
"," {return tVIRG;}
"==" {return tEQEQ;}
"=" {return tEQ;}
"printf" {return tPRINTF;}
";" {return tINSTREND;}
"\n" {printf("\n");line++;}
"//" {printf("tCOMM");}
"if" {return tIF;}
"else" {return tELSE;}
"while" {return tWHILE;}
{SPACE} {}
{INTEGER} { yylval.nombre = atoi(yytext); return tInt;}
{VARNAME} {yylval.string = strdup(yytext); return tName;}
. { fail++;}