-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.l
More file actions
32 lines (25 loc) · 745 Bytes
/
lexer.l
File metadata and controls
32 lines (25 loc) · 745 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
%{
#include "parser.tab.h"
void yyerror (char *s);
int yylex();
extern int lastValOfExpr;
%}
%%
"Print" {return PRINT;}
"Add" {return ADD;}
"with" {return WITH;}
"Substract" {return SUBSTRACT;}
"from" {return FROM;}
"Multiply" {return MULTIPLY;}
"Divide" {return DIVIDE;}
"by" {return BY;}
"Assign" {return ASSIGN;}
"to" {return TO;}
[a-zA-Z] {yylval.id = yytext[0]; return identifier;}
[0-9]+ {yylval.num = atoi(yytext); return number;}
[ \r\t] {;}
[-+\*/\n] {return yytext[0];}
<<EOF>> {printf("%d\n", lastValOfExpr); return 0;}
. {ECHO; yyerror ("Unexpected character encountered");}
%%
int yywrap (void) {return 1;}