-
Notifications
You must be signed in to change notification settings - Fork 0
/
roseta.l
64 lines (60 loc) · 1.61 KB
/
roseta.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
%{
#include "y.tab.h"
%}
%option nounput yylineno
%%
"for" {return FOR_TOKEN;}
"while" {return WHILE_TOKEN;}
"if" {return IF_TOKEN;}
"do" {return DO_TOKEN;}
"else" {return ELSE_TOKEN;}
"object" {return OBJECT_TOKEN;}
"true" {return TRUE_TOKEN;}
"null" {return NULL_TOKEN;}
"false" {return FALSE_TOKEN;}
"print" {return PRINT;}
"void" {return VOID;}
"case" {return CASE;}
"default" {return DEFAULT;}
"int" {return TYPE;}
"char" {return TYPE;}
"char *" {return TYPE;}
"int *" {return TYPE;}
"main" {return MAIN;}
"switch" {return SWITCH_TOKEN;}
"-" {return OP_MINUS;}
"+" {return OP_PLUS;}
"*" {return OP_MULT;}
"/" {return OP_DIV;}
"%" {return OP_MOD;}
"<=" {return OP_LE;}
">=" {return OP_GE;}
"==" {return OP_EQ;}
">" {return OP_GT;}
"<" {return OP_LT;}
"=" {return OP_ASSIGN;}
":" {return COLON;}
"!=" {return OP_NE;}
"||" {return OP_OR;}
"&&" {return OP_AND;}
"!" {return NOT;}
int|Integer|String {return TYPE;}
[a-zA-Z][_a-zA-Z0-9]* {return NAME;}
[\+-]?[1-9][0-9]* {return NUMBER;}
[\"].*[\"] {return STRING;}
"{" {return OPEN_C_BRACKET;}
"}" {return CLOSE_C_BRACKET;}
"[" {return OPEN_S_BRACKET;}
"]" {return CLOSE_S_BRACKET;}
"(" {return OPEN_PARENTHESIS;}
")" {return CLOSE_PARENTHESIS;}
";" {return SEMICOLON;}
"." {return DOT;}
"," {return COMMA;}
[ \t\n] ;
. {printf("unexpected character\n");}
%%
int yywrap(void)
{
return 1;
}