-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.l
73 lines (60 loc) · 1.88 KB
/
tokens.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
%option yylineno
%option nounput
%{
#include <string>
#include <iostream>
#include <vector>
#include "Structs.hpp"
#include "parser.hpp"
using namespace std;
#define TOKEN(t) yylval.str = new string(yytext, yyleng) ; return t
extern "C" int yywrap() { return(1) ; }
%}
%option nounput
digito [0-9]
letra [a-zA-Z]
%%
(\[\*)([^*]|\*+[^*\]])*(\*+\]) ;
#[^#\n]*\n ;
[ \t\n] ;
program TOKEN(RPROGRAM);
int TOKEN(RINTEGER);
float TOKEN(RFLOAT);
and TOKEN(RAND);
or TOKEN(ROR);
not TOKEN(RNOT);
for TOKEN(RFOR);
while TOKEN(RWHILE);
until TOKEN(RUNTIL);
exit TOKEN(REXIT);
proc TOKEN(RPROCEDURE);
if TOKEN(RIF);
else TOKEN(RELSE);
forever TOKEN(RFOREVER);
do TOKEN(RDO);
skip TOKEN(RSKIP);
read TOKEN(RREAD);
println TOKEN(RPRINTLN);
"{" TOKEN(TLBRACE);
"}" TOKEN(TRBRACE);
"(" TOKEN(TLPAREN);
")" TOKEN(TRPAREN);
"," TOKEN(TCOMMA);
"=" TOKEN(TASSIG);
";" TOKEN(TSEMIC);
"<=>" TOKEN(TCGLE);
"<" TOKEN(TCLT);
"<=" TOKEN(TCLE);
">" TOKEN(TCGT);
">=" TOKEN(TCGE);
"==" TOKEN(TEQUAL);
"/=" TOKEN(TNEQUAL);
"/" TOKEN(TDIV);
"+" TOKEN(TPLUS);
"-" TOKEN(TMINUS);
"*" TOKEN(TMUL);
{letra}+(_?{letra}|{digito})* TOKEN(TIDENTIFIER) ;
{digito}+\.{digito}+([eE][\+\-]?{digito}+)? TOKEN(TDOUBLE);
{digito}+ TOKEN(TINTEGER);
. { cout << "Token desconocido: " << yytext << endl; yyterminate();}
%%