-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlex.txt
40 lines (40 loc) · 1012 Bytes
/
lex.txt
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
%{
#include<stdlib.h>
void yyerror(char*);
extern void addVar(char*);
Map sym[100];
%}
%%
[0-9]+ {yylval.iValue=atof(yytext);return NUMBER;}
[0-9]*\.[0-9]+ {yylval.iValue = atof(yytext); return NUMBER;}
[-()<>=+*/;{}] {return *yytext;}
">=" return GE;
"<=" return LE;
"==" return EQ;
"!=" return NE;
"++" return SELFADD;
"--" return SELFMINUS;
"&&" return AND;
"||" return OR;
"begin" return _BEGIN;
"end" return END;
"while" return WHILE;
"if" return IF;
"else" return ELSE;
"print" return PRINT;
"repeat" return REPEAT;
"until" return UNTIL;
"for" return FOR;
("{body}"|"{head}")"+"?"-"? {strcpy(yylval.com,yytext);return COMMAND;}
("{lua}"|"{rua}"|"{lla}"|"{rla}"|"{lul}"|"{rul}"|"{lll}"|"{rll}")x?z?"+"?"-"? {strcpy(yylval.com,yytext);return COMMAND;}
"robot" return ROBOT;
"delay" return DELAY;
"reset" {strcpy(yylval.com,yytext);return RESET;}
[a-zA-Z][a-zA-Z0-9]* {addVar(yytext);yylval.sIndex=currentVar;return VARIABLE;}
[\t\n]+ ;
.yyerror("Unknow");
%%
int yywrap(void)
{
return 1;
}