3 /* In order to compile this file with visual c++ 6, you have to create a unistd.h
\r
4 file in on of your include directories with this inside:
\r
9 #include "script_compiler.h"
\r
11 #define YY_NEVER_INTERACTIVE 1
\r
12 #define PR_PRINTF(a) printf a
\r
14 #include "script_parser_yacc.h"
\r
15 #include "script_vm.h"
\r
17 using namespace std;
\r
18 using namespace NLMISC;
\r
19 using namespace AICOMP;
\r
20 using namespace AIVM;
\r
22 extern void aiClean ();
\r
26 char aiFile[512] = {0};
\r
27 const char *aiInputScript;
\r
28 uint aiInputScriptLength;
\r
30 #define YY_INPUT(buf,result,max_size) \
\r
31 result = (uint)std::min ((uint)max_size, (uint)aiInputScriptLength); \
\r
32 memcpy (buf, aiInputScript, result); \
\r
33 aiInputScript += result; \
\r
34 aiInputScriptLength -= result;
\r
36 size_t makeStringId (const char *str)
\r
40 if ( strRef.at(0)=='"'
\r
41 && strRef.at(0)==strRef.at(strRef.size()-1))
\r
42 strId=CStringMapper::map(strRef.substr(1,strRef.size()-2));
\r
44 strId=CStringMapper::map(strRef);
\r
46 return (size_t)strId;
\r
49 void addSignature (char *dest, char s)
\r
51 uint size = (uint)strlen (dest);
\r
52 if (size+1 < (uint)(AICOMP_MAX_SIGNATURE))
\r
59 void addSignature (char *dest, char *src)
\r
61 uint size0 = (uint)strlen (dest);
\r
62 uint size1 = (uint)strlen (src);
\r
63 if (size0+size1+1 < (uint)(AICOMP_MAX_SIGNATURE))
\r
67 #define INIT(a) ailval.Opcode.Opcode = a; ailval.Opcode.Line = aiLine; ailval.Opcode.Signature[0] = 0;
\r
68 #define INIT_OP(a,b) ailval.Operator.Opcode = a; ailval.Opcode.Line = aiLine; ailval.Operator.Operator= b; ailval.Opcode.Signature[0] = 0;
\r
72 %option nounput prefix="ai"
\r
78 ctxname @({alpha}|[_])({alpha}|{digit}|[_])*
\r
79 strname $({alpha}|[_])({alpha}|{digit}|[_])*
\r
80 name ({alpha}|[_])({alpha}|{digit}|[_])*
\r
81 double1 [-+]?{digit}+\.([eE][-+]?{digit}+)?
\r
82 double2 [-+]?{digit}+[eE][-+]?{digit}+
\r
83 double3 [-+]?{digit}*\.{digit}+([eE][-+]?{digit}+)?
\r
85 double {double1}|{double2}|{double3}|{int}
\r
87 comment2 \/\/[^\n]*\n
\r
88 string \"([^\n"]|(\\\"))*\"
\r
94 {comment1} { aiLine++; }
\r
96 {comment2} { aiLine++; }
\r
100 if { return TOKEN_IF; }
\r
101 else { return TOKEN_ELSE; }
\r
102 while { return TOKEN_WHILE; }
\r
103 print { return TOKEN_PRINT; }
\r
104 log { return TOKEN_LOG; }
\r
105 switch { return TOKEN_SWITCH; }
\r
106 case { return TOKEN_CASE; }
\r
107 rand { return TOKEN_RAND; }
\r
108 onchildren { return TOKEN_ONCHILDREN; }
\r
109 "." { return TOKEN_POINT; }
\r
110 "," { return TOKEN_SEPARATOR; }
\r
111 "=" { return TOKEN_ASSIGNATOR; }
\r
112 ";" { return TOKEN_PV; }
\r
113 ":" { return TOKEN_PP; }
\r
114 "(" { return TOKEN_LP; }
\r
115 ")" { return TOKEN_RP; }
\r
116 "{" { return TOKEN_LA; }
\r
117 "}" { return TOKEN_RA; }
\r
122 NLMISC::fromString(yytext, f);
\r
123 INIT(*((size_t*)&f));
\r
124 return TOKEN_NUMBER;
\r
126 {string} { INIT(makeStringId (yytext)); return TOKEN_CHAIN; }
\r
127 {name} { INIT(makeStringId (yytext)); return TOKEN_NAME; }
\r
128 {ctxname} { INIT(makeStringId (yytext)); return TOKEN_CTXNAME; }
\r
129 {strname} { INIT(makeStringId (yytext)); return TOKEN_STRNAME; }
\r
131 "&&" { INIT(CScriptVM::AND); return TOKEN_LOGIC; }
\r
132 "||" { INIT(CScriptVM::OR); return TOKEN_LOGIC; }
\r
134 "==" { INIT_OP(CScriptVM::EQ, "=="); return TOKEN_COMP; }
\r
135 ">=" { INIT_OP(CScriptVM::SUPEQ, ">="); return TOKEN_COMP; }
\r
136 "=>" { INIT_OP(CScriptVM::SUPEQ, "=>"); return TOKEN_COMP; }
\r
137 "<=" { INIT_OP(CScriptVM::INFEQ, "<="); return TOKEN_COMP; }
\r
138 "=<" { INIT_OP(CScriptVM::INFEQ, "=<"); return TOKEN_COMP; }
\r
139 "!=" { INIT_OP(CScriptVM::NEQ, "!="); return TOKEN_COMP; }
\r
140 "<>" { INIT_OP(CScriptVM::NEQ, "<>"); return TOKEN_COMP; }
\r
141 "><" { INIT_OP(CScriptVM::NEQ, "><"); return TOKEN_COMP; }
\r
142 ">" { INIT_OP(CScriptVM::SUP, ">" ); return TOKEN_COMP; }
\r
143 "<" { INIT_OP(CScriptVM::INF, "<" ); return TOKEN_COMP; }
\r
145 "+=" { INIT_OP(CScriptVM::ADD, "+="); return TOKEN_ASSIGN; }
\r
146 "-=" { INIT_OP(CScriptVM::SUB, "-="); return TOKEN_ASSIGN; }
\r
147 "*=" { INIT_OP(CScriptVM::MUL, "*="); return TOKEN_ASSIGN; }
\r
148 "/=" { INIT_OP(CScriptVM::DIV, "/="); return TOKEN_ASSIGN; }
\r
150 "++" { INIT(CScriptVM::INCR); return TOKEN_INCRDECR; }
\r
151 "--" { INIT(CScriptVM::DECR); return TOKEN_INCRDECR; }
\r
153 "+" { INIT(CScriptVM::ADD); return TOKEN_ADD; }
\r
154 "-" { INIT(CScriptVM::SUB); return TOKEN_SUB; }
\r
155 "*" { INIT_OP(CScriptVM::MUL, "*"); return TOKEN_FACTOR; }
\r
156 "/" { INIT_OP(CScriptVM::DIV, "/"); return TOKEN_FACTOR; }
\r
162 // ai_delete_buffer (yy_current_buffer);
\r