-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlexerdefinition.l
72 lines (58 loc) · 1.8 KB
/
lexerdefinition.l
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
70
%option noyywrap
%{
/* ------------------------------------------------------------------
Initial code (copied verbatim to the output file)
------------------------------------------------------------------ */
// Includes
#include <stdio.h>
#include <string.h> // strcpy, strncpy
#include "lexersymbols.h"
#include "shared.h"
void disregard_comment();
%}
/* ------------------------------------------------------------------
Some macros (standard regular expressions)
------------------------------------------------------------------ */
LETTER [a-zA-Z_]
DIGIT [0-9]
INTEGER {DIGIT}*
IDENT {LETTER}({LETTER}|{DIGIT})*
STR \"[^\"]*\"
WSPACE [ \t]+
%%
"archetype" {return ARCHETYPE_KEYWORD;}
"object" {return OBJECT_KEYWORD;}
"is" {return INHERITANCE_OP;}
"native" {return NATIVE_KEYWORD;}
"state" {return STATE_KEYWORD;}
"stateset" {return STATESET_KEYWORD;}
"integer" {return TYPE_INTEGER;}
"string" {return TYPE_STRING;}
"." {return MEMBER_OP;}
"," {return ARG_SEPARATOR;}
"#" {disregard_comment();}
"{" {return OPEN_BRACKET;}
"}" {return CLOSE_BRACKET;}
"(" {return OPEN_PAREN;}
")" {return CLOSE_PAREN;}
"if" {return IF;}
"else" {return ELSE;}
"==" {return EQUAL_OP;}
"=" {return ASSIGN_OP;}
\n {}
{INTEGER} {printf("integer %s\n\n", yytext); yylval.integer = atoi(yytext); return INTEGER;}
{IDENT} {return ID;}
{STR} {printf("string"); yylval.str = yytext; return STRING;}
{WSPACE} {}
. {return ERROR_TOKEN;}
%%
void disregard_comment()
{
char current_char;
current_char = input();
/* Read through characters until we hit either no more characters or a new line */
while(current_char != '\0' && current_char != '\n')
{
current_char = input();
}
}