-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.l
77 lines (70 loc) · 1.77 KB
/
scanner.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
%{
#include <cstdlib>
#include "parser.hpp"
%}
%option noyywrap
%option yylineno
DIGIT [0-9]*
id [a-zA-Z][a-zA-Z0-9_]*
%%
"+" {return ADD;}
"-" {return SUB;}
"*" {return MULT;}
"/" {return DIV;}
"&" {return AND;}
"|" {return OR;}
"~" {return TILDA;}
"=" {return EQ;}
":=" {return ASSIGN;}
"<>" {return ARROWS;}
"<" {return LT;}
">" {return GT;}
">=" {return GTE;}
"<=" {return LTE;}
"." {return DEC;}
"," {return COMMA;}
":" {return COL;}
";" {return SEMCOL;}
"(" {return POPEN;}
")" {return PCLOSE;}
"[" {return BOPEN;}
"]" {return BCLOSE;}
"%" {return PERC;}
"array"|"ARRAY" {return ARRAY;}
"begin"|"BEGIN" {return START;}
"chr"|"CHR" {return CHR;}
"const"|"CONST" {return CONST;}
"do"|"DO" {return DO;}
"downto"|"DOWNTO" {return DOWNTO;}
"else"|"ELSE" {return ELSE;}
"elseif"|"ELSEIF" {return ELSEIF;}
"end"|"END" {return END;}
"for"|"FOR" {return FOR;}
"forward"|"FORWARD" {return FORWARD;}
"function"|"FUNCTION" {return FUNCTION;}
"if"|"IF" {return IF;}
"of"|"OF" {return OF;}
"ord"|"ORD" {return ORD;}
"pred"|"PRED" {return PRED;}
"procedure"|"PROCEDURE" {return PROCEDURE;}
"read"|"READ" {return READ;}
"record"|"RECORD" {return RECORD;}
"ref"|"REF" {return REF;}
"repeat"|"REPEAT" {return REPEAT;}
"return"|"RETURN" {return RETURN;}
"stop"|"STOP" {return STOP;}
"succ"|"SUCC" {return SUCC;}
"then"|"THEN" {return THEN;}
"to"|"TO" {return TO;}
"type"|"TYPE" {return TYPE;}
"until"|"UNTIL" {return UNTIL;}
"var"|"VAR" {return VAR;}
"while"|"WHILE" {return WHILE;}
"write"|"WRITE" {return WRITE;}
{id} {yylval.id = strdup(yytext); return ID;}
{DIGIT}+ {yylval.val = atoi(yytext); return NUMBER;}
0x({DIGIT}+) {yylval.val = atoi(yytext); return NUMBER;}
\'\\t\'|\'.\'|\'\\n\' {yylval.id = strdup(yytext); return CHAR;}
\"[^\"]*\" {yylval.id = strdup(yytext); return STR;}
$(.*)\n {}
[ \t\n] {}