-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlex.l
More file actions
34 lines (28 loc) · 935 Bytes
/
lex.l
File metadata and controls
34 lines (28 loc) · 935 Bytes
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
%{
#include <stdio.h>
#include "y.tab.h"
%}
%%
"//"[^\n]* { /* consume //-comment */ }
[ \t\n]+ { /* consume whitespace characters */ }
"return" { return TOK_RETURN; }
"int" { yylval.string=strdup(yytext); return TOK_TYPE; }
"main" { return TOK_IDENTIFIER; }
"{" { return TOK_LBRACE; }
"}" { return TOK_RBRACE; }
"(" { return TOK_LPAREN; }
")" { return TOK_RPAREN; }
"+" { return TOK_ADD; }
"-" { return TOK_SUBTRACT; }
"*" { return TOK_MULTIPLY; }
"/" { return TOK_DIVIDE; }
"!" { return TOK_NOT; }
";" { return TOK_SEMI; }
"cout" { return TOK_COUT; }
"<<" { return TOK_LSHIFT; }
[0-9]+ { yylval.number=atoi(yytext); return TOK_UINT; }
[a-zA-Z]+ { yylval.string=strdup(yytext); return TOK_IDENTIFIER; }
%%
int yywrap(){
return 1;
}