-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspell.l
More file actions
91 lines (72 loc) · 2.77 KB
/
spell.l
File metadata and controls
91 lines (72 loc) · 2.77 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
%{
#include "spell.tab.h"
#include <string>
#include <iostream>
using namespace std;
extern int yylineno;
%}
%option noyywrap
letter [a-zA-Z]
digit [0-9]
id {letter}({letter}|{digit}|_)*
integer {digit}+
float ({digit}+\.{digit}+)|(\.{digit}+)
string \"[^\"]*\"
whitespace [ \t\r]+
comment \/\/.*
%%
{whitespace} {/*ignore*/}
"\n" { yylineno++;}
{comment} {/*ignore*/}
"DUEL" { yylval.str_val = new string(yytext); return DUEL_KW;}
"HOUSE" { yylval.str_val = new string(yytext); return HOUSE_KW; }
"FIELD" { yylval.str_val = new string(yytext); return FIELD_KW; }
"CHARM" { yylval.str_val = new string(yytext); return CHARM_KW; }
"SPELL" { yylval.str_val = new string(yytext); return SPELL_KW; }
"PARCHMENT" { yylval.str_val = new string(yytext); return PARCHMENT_KW; }
"SUMMON" { yylval.str_val = new string(yytext); return SUMMON_KW; }
"PROPHECY" { yylval.str_val = new string(yytext); return IF_KW; }
"CHANT" { yylval.str_val = new string(yytext); return WHILE_KW; }
"ACCIO" { yylval.str_val = new string(yytext); return RETURN_KW; }
"Print" { yylval.str_val = new string(yytext); return PRINT_KW; }
"else" { yylval.str_val = new string(yytext); return ELSE_KW; }
"int" { yylval.str_val = new string(yytext); return TYPE_INT; }
"float" { yylval.str_val = new string(yytext); return TYPE_FLOAT; }
"string" { yylval.str_val = new string(yytext); return TYPE_STRING; }
"bool" { yylval.str_val = new string(yytext); return TYPE_BOOL; }
"true" { yylval.bool_val = true; return TRUE_LITERAL; }
"false" { yylval.bool_val = false; return FALSE_LITERAL;}
{integer} { yylval.int_val = stoi(yytext); return INT_LITERAL;}
{float} { yylval.float_val = stod(yytext); return FLOAT_LITERAL;}
{string} {
string tmp(yytext);
if(tmp.size() >= 2) tmp= tmp.substr(1, tmp.size()-2);
yylval.str_val = new string(tmp);
return STRING_LITERAL;
}
"<~" { return ASSIGN_OP;}
"**" { return ACCESS_OP;}
"&&" {return AND;}
"||" {return OR;}
"==" {return EQUAL;}
"!=" {return NOT_EQUAL;}
"!" {return NOT;}
"+" { return '+'; }
"-" { return '-'; }
"*" { return '*'; }
"/" { return '/'; }
"%" { return '%'; }
"<" { return '<'; }
">" { return '>'; }
"<=" {return LESS_EQUAL;}
">=" {return GREATER_EQUAL;}
"(" { return '('; }
")" { return ')'; }
"{" { return '{'; }
"}" { return '}'; }
"," { return ','; }
";" { return ';'; }
":" { return ':'; }
{id} { yylval.str_val = new string(yytext); return ID; }
. { cerr <<"lexical error on line "<< yylineno; }
%%