forked from ajhalthor/interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemantics.l
More file actions
executable file
·69 lines (52 loc) · 2.24 KB
/
Copy pathsemantics.l
File metadata and controls
executable file
·69 lines (52 loc) · 2.24 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
57
58
59
60
61
62
63
64
65
66
67
68
69
%{
#include <string.h>
#include <stdlib.h>
#include "y.tab.h"
void extern yyerror(char*);
void InvalidToken();
%}
whitespace [ \t\r\v\f]
linefeed \n
%%
"void" |
"int" |
"char" |
"float" |
"unsigned int" |
"unsigned char" |
"void*" |
"int*" |
"char*" |
"float*" {yylval.dataType = strdup(yytext);return DATA_TYPE;}
"struct" {yylval.dataType = strdup(yytext);return STRUCT;}
"'" {return SINGLE_QUOTES;}
"," {return COMMA;}
";" {return SEMI_COLON;}
"=" {return EQUALS;}
"(" {return BRACKET_OPEN;}
")" {return BRACKET_CLOSE;}
"{" {return CURLY_BRACE_OPEN;}
"}" {return CURLY_BRACE_CLOSE;}
"[" {return BIG_BRACKET_OPEN;}
"]" {return BIG_BRACKET_CLOSE;}
[\'][a-zA-Z][\'] {yylval.charVal = yytext[1]; return CHARACTER_VALUE;}
[-+]?[0-9]+ {yylval.intVal = atoi(yytext); return INTEGER_VALUE;}
[-+]?[0-9]*\.?[0-9]+ {yylval.floatVal = atof(yytext); return FLOAT_VALUE;}
[a-zA-Z][_a-zA-Z0-9]*(\[[0-9]+\])+ {yylval.strVal = strdup(yytext); return ARRAY_IDENTIFIER;}
[a-zA-Z][_a-zA-Z0-9]* {yylval.dataType = strdup(yytext); return IDENTIFIER;}
\"(\\.|[^"])*\" {yylval.strVal = strdup(yytext); return STRING_VALUE;}
{linefeed} {yylineno++;}
{whitespace} ;
. {InvalidToken();}
%%
int yywrap(void){
return 1;
}
void yyerror(char *s) {
fprintf(stderr, "\nERROR ON LINE %d : \n %s\n", yylineno, s);
exit(0);
}
void InvalidToken(){
printf("ERROR ON LINE %d : \n Invalid Token %s\n", yylineno,yytext);
exit(0);
}