-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.l
85 lines (66 loc) · 1.83 KB
/
lexer.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
%{
#include <stdio.h>
#include <string>
#include "../memory.h"
#include "../code_generator.h"
#include "../code_writer.h"
#include "../instruction_generators.h"
#include "../tokens.h"
#include "parser.tab.hpp"
using namespace std;
int yylex();
%}
%x COMMENT
number [0-9]+
pid [_a-z]+
blank [\t \r]*
punctuation [\(\)\:\;\,]
%%
"DECLARE" {return DECLARE;}
"BEGIN" {return MY_BEGIN;}
"END" {return END;}
"IF" {return IF;}
"THEN" {return THEN;}
"ELSE" {return ELSE;}
"ENDIF" {return ENDIF;}
"WHILE" {return WHILE;}
"DO" {return DO;}
"ENDWHILE" {return ENDWHILE;}
"REPEAT" {return REPEAT;}
"UNTIL" {return UNTIL;}
"FOR" {return FOR;}
"FROM" {return FROM;}
"TO" {return TO;}
"DOWNTO" {return DOWNTO;}
"ENDFOR" {return ENDFOR;}
"WRITE" {return WRITE;}
"READ" {return READ;}
":=" {return IS;}
"=" {return EQ;}
"!=" {return DIF;}
"<" {return LT;}
">" {return GT;}
"<=" {return EQLT;}
">=" {return EQGT;}
"+" {return ADD;}
"-" {return SUB;}
"*" {return MUL;}
"/" {return DIV;}
"%" {return MOD;}
{pid} {yylval.pid = new string(yytext); return pidentifier;}
{number} {yylval.num = std::stoll(yytext); return num;}
{punctuation} {return yytext[0];}
"\n" {yylineno++;}
"[" {BEGIN(COMMENT);}
<COMMENT>{
"[" ;
"]" BEGIN(INITIAL);
. ;
"\n"
}
{blank} {}
. ;
%%
int yywrap(){
return 1;
}