summaryrefslogtreecommitdiff
path: root/src/map/magic-interpreter-lexer.lpp
blob: 2b68acfa5355d837f3bc79e5544c3bb660f3c630 (plain) (blame)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
%{
#include "magic-interpreter-lexer.hpp"
#
#include "magic-interpreter-parser.hpp"

#include "../io/cxxstdio.hpp"

#ifdef HEADING
# error "what platform is this? please tell me who #defined HEADING"
#endif

#define FIXLOC magic_frontend_lloc.first_line = magic_frontend_lineno

#define HEADING(dir) { magic_frontend_lval.i = dir; FIXLOC; return DIR; }

// silence compiler warnings
#define YY_USER_INIT (void)yylval, (void)yylloc
%}

%option yylineno
%option noyywrap
%option prefix="magic_frontend_"
%option nounput
%option noinput
%option bison-bridge bison-locations

%%

"S"                     HEADING(0);
"SW"                    HEADING(1);
"W"                     HEADING(2);
"NW"                    HEADING(3);
"N"                     HEADING(4);
"NE"                    HEADING(5);
"E"                     HEADING(6);
"SE"                    HEADING(7);
"="                     {FIXLOC; return '=';}
"=="                    {FIXLOC; return EQ;}
"<>"                    {FIXLOC; return NEQ;}
"!="                    {FIXLOC; return NEQ;}
">"                     {FIXLOC; return '>';}
"<"                     {FIXLOC; return '<';}
">="                    {FIXLOC; return GTE;}
"<="                    {FIXLOC; return LTE;}
"("                     {FIXLOC; return '(';}
")"                     {FIXLOC; return ')';}
"+"                     {FIXLOC; return '+';}
"-"                     {FIXLOC; return '-';}
"*"                     {FIXLOC; return '*';}
"/"                     {FIXLOC; return '/';}
"%"                     {FIXLOC; return '%';}
"&&"                    {FIXLOC; return ANDAND;}
"||"                    {FIXLOC; return OROR;}
";"                     {FIXLOC; return ';';}
":"                     {FIXLOC; return ':';}
","                     {FIXLOC; return ',';}
"@"                     {FIXLOC; return '@';}
"|"                     {FIXLOC; return '|';}
"["                     {FIXLOC; return '[';}
"]"                     {FIXLOC; return ']';}
"&"                     {FIXLOC; return '&';}
"^"                     {FIXLOC; return '^';}
"."                     {FIXLOC; return '.';}
"<<"                    {FIXLOC; return SHL;}
">>"                    {FIXLOC; return SHR;}
"PROCEDURE"             {FIXLOC; return PROCEDURE;}
"CALL"                  {FIXLOC; return CALL;}
"OR"                    {FIXLOC; return OR;}
"TO"                    {FIXLOC; return TO;}
"TOWARDS"               {FIXLOC; return TOWARDS;}
"TELEPORT-ANCHOR"       {FIXLOC; return TELEPORT_ANCHOR;}
"SILENT"                {FIXLOC; return SILENT;}
"LOCAL"                 {FIXLOC; return LOCAL;}
"NONMAGIC"              {FIXLOC; return NONMAGIC;}
"SPELL"                 {FIXLOC; return SPELL;}
"LET"                   {FIXLOC; return LET;}
"IN"                    {FIXLOC; return IN;}
"END"                   {FIXLOC; return END;}
"=>"                    {FIXLOC; return DARROW;}
"STRING"                {FIXLOC; return STRING_TY;}
"REQUIRE"               {FIXLOC; return REQUIRE;}
"CATALYSTS"             {FIXLOC; return CATALYSTS;}
"COMPONENTS"            {FIXLOC; return COMPONENTS;}
"MANA"                  {FIXLOC; return MANA;}
"CASTTIME"              {FIXLOC; return CASTTIME;}
"SKIP"                  {FIXLOC; return SKIP;}
"ABORT"                 {FIXLOC; return ABORT;}
"BREAK"                 {FIXLOC; return BREAK;}
"EFFECT"                {FIXLOC; return EFFECT_;}
"ATEND"                 {FIXLOC; return ATEND;}
"ATTRIGGER"             {FIXLOC; return ATTRIGGER;}
"CONST"                 {FIXLOC; return CONST;}
"PC"                    {FIXLOC; return PC_F;}
"NPC"                   {FIXLOC; return NPC_F;}
"MOB"                   {FIXLOC; return MOB_F;}
"ENTITY"                {FIXLOC; return ENTITY_F;}
"TARGET"                {FIXLOC; return TARGET_F;}
"IF"                    {FIXLOC; return IF;}
"THEN"                  {FIXLOC; return THEN;}
"ELSE"                  {FIXLOC; return ELSE;}
"FOREACH"               {FIXLOC; return FOREACH;}
"FOR"                   {FIXLOC; return FOR;}
"DO"                    {FIXLOC; return DO;}
"WAIT"                  {FIXLOC; return SLEEP;}

\{([^\}]|\\.)*\}        {
    magic_frontend_lval.s = dumb_string::copy(yytext);
    FIXLOC;
    return SCRIPT_DATA;
}

\"([^\"]|\\.)*\"        {
    dumb_string string = dumb_string::copy(yytext + 1);
    const char *src = string.c_str();
    char *dst = &string[0];
    while (*src && *src != '"')
    {
        if (*src == '\\')
        {
            *dst++ = src[1];
            src += 2;
        }
        else
            *dst++ = *src++;
    }
    *dst = '\0'; /* terminate */
    magic_frontend_lval.s = string;
    FIXLOC;
    return STRING;
}

"-"?[0-9]+              {
    magic_frontend_lval.i = atoi(yytext);
    FIXLOC;
    return INT;
 }

"0x"[0-9a-fA-F]+        {
    magic_frontend_lval.i = strtol(yytext + 2, NULL, 16);
    FIXLOC;
    return INT;
 }

[a-zA-Z][-_a-zA-Z0-9]*  {
    magic_frontend_lval.s = dumb_string::copy(yytext);
    FIXLOC;
    return ID;
}

"#".*$                  /* Ignore comments */
"//".*$                 /* Ignore comments */
[ \n\t\r]               /* ignore whitespace */
.                       FPRINTF(stderr, "%s: Unexpected character in line %d\n", MAGIC_CONFIG_FILE, magic_frontend_lineno);

%%