-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLexico.l
49 lines (38 loc) · 1.09 KB
/
Lexico.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
%{
#include <stdio.h>
#include <stdlib.h>
#include "y.tab.h"
FILE *yyin;
int yylval;
char *yyltext;
int yyerror(void);
%}
%option noyywrap
%option yylineno
DIGITO [0-9]
LETRA [a-zA-Z]
CTE {DIGITO}+
ID {LETRA}({LETRA}|{DIGITO})*
OP_AS ":""="
OP_SUM "+"
OP_MUL "*"
OP_RES "-"
OP_DIV "/"
PA "("
PC ")"
%%
{CTE} {printf("\nConstante: %s\n", yytext);return CTE;}
{ID} {printf("\nIdentificador: %s\n", yytext);return ID;}
{OP_SUM} {printf("\nSuma: %s\n", yytext);return OP_SUM;}
{OP_AS} {printf("\nAsignacion: %s\n", yytext);return OP_AS;}
{OP_MUL} {printf("\nMultiplicacion: %s\n", yytext);return OP_MUL;}
{OP_RES} {printf("\nResta: %s\n", yytext);return OP_RES;}
{OP_DIV} {printf("\nDivision: %s\n", yytext);return OP_DIV;}
{PA} {printf("\nParAbre: %s\n", yytext);return PA;}
{PC} {printf("\nParCierra: %s\n", yytext);return PC;}
"\n"
"\t"
"\n\t"
" "
"\r\n"
. { printf( "ERROR LEXICO : Caracter no reconocido: %s\n", yytext ); exit (0);}