forked from newseduser/basic_oop_compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.l
More file actions
37 lines (33 loc) · 648 Bytes
/
lexer.l
File metadata and controls
37 lines (33 loc) · 648 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
35
36
37
%{
#include <stdlib.h>
#include <stdio.h>
#include "header.h"
#include "y.tab.h"
int number;
%}
%%
"begin" {return BEG;}
"end" {return END;}
"read" {return READ;}
"write" {return WRITE;}
[a-z] {yylval = makeVarNode(yytext); return ID;}
[0-9]+ {number = atoi(yytext); yylval = makeLeafNode(number); return NUM;}
"+" {return PLUS;}
"-" {return MINUS;}
"*" {return MUL;}
"/" {return DIV;}
"=" {return ASG;}
";" {return LINE_ENDER;}
[ \t] {}
[()] {return *yytext;}
[\n] {return NEWLINE;}
. {yyerror("unknown character\n");exit(1);}
%%
int yywrap(void) {
return 1;
}
void lex_input_file(FILE*src_file)
{
if(src_file!=NULL)
yyin=src_file;
}