-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.l
More file actions
56 lines (47 loc) · 1.52 KB
/
test.l
File metadata and controls
56 lines (47 loc) · 1.52 KB
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
%{
#include <stdio.h>
#include <string.h>
#include "AST.h"
#include "test.tab.h"
extern union _NODE_ yylval;
void showError();
%}
numbers ([0-9])+
alpha ([a-zA-Z])+
%%
"$" {return (STOP);}
"?" {return (QMARK);}
":" {return (COLON);}
"," {return (COMMA);}
"(" {return (BOPEN);}
")" {return (BCLOSE);}
"[" {return (SBOPEN);}
"]" {return (SBCLOSE);}
"{" {return (CBOPEN);}
"}" {return (CBCLOSE);}
"<"|">"|">="|"<="|"==" {sscanf(yytext, "%s", yylval.roperator);return (ROP);}
"=" {return (EQUAL);}
"+"|"-" {sscanf(yytext, "%s", yylval.aoperator); return (AOP);}
"*"|"/" {sscanf(yytext, "%s", yylval.aboperator); return (ABOP);}
"&&"|"||" {sscanf(yytext, "%s", yylval.boperator); return (BOP);}
"!" {sscanf(yytext, "%s", yylval.uoperator);return (UOP);}
int|bool|void {sscanf(yytext, "%s", yylval.dtype); return (DTYPE);}
while {return (WHILE);}
for {return (FOR);}
if {return (IF);}
else {return (ELSE);}
input {return (INPUT);}
output {return (OUTPUT);}
return {return (RETURN);}
break {return (BREAK);}
continue {return (CONTINUE);}
true|false { yylval.bvalue=0; if(yytext=="true") yylval.bvalue = 1; return (BOOL);}
{alpha} {sscanf(yytext, "%s", yylval.name); return (STRING);}
{numbers} {yylval.number = atoi(yytext); return (INT);}
";" {return (SEMICOLON);}
[ \t\n]+ /* eat up whitespace */
. {printf("unrecognized: %s\n",yytext);showError(); return(OTHER);}
%%
void showError(){
printf("\nerror\n");
}