11 #define YYLTYPE Location
16 public void SetEchoOn(bool b) { echoOn = b; }
18 extern YYLTYPE type_yylloc;
19 extern YYLTYPE expression_yylloc;
21 extern File fileInput;
27 yylloc.end.charPos += yyleng;
28 yylloc.end.pos += yyleng;
29 type_yylloc.end.charPos += yyleng;
30 type_yylloc.end.pos += yyleng;
31 expression_yylloc.end.charPos += yyleng;
32 expression_yylloc.end.pos += yyleng;
35 #define YY_USER_ACTION \
39 yylloc.end.charPos += yyleng;
40 yylloc.end.pos += yyleng;
43 #define YY_INPUT(buf,result,max_size) \
44 result = fileInput.Read(buf, 1, max_size) \
46 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
47 File fileStack[MAX_INCLUDE_DEPTH];
48 char sourceFileStack[MAX_INCLUDE_DEPTH][MAX_LOCATION];
49 public void SetSomeSourceFileStack(char * fileName, int index) { strcpy(sourceFileStack[index], fileName); }
50 YYLTYPE locStack[MAX_INCLUDE_DEPTH];
51 AccessMode declModeStack[MAX_INCLUDE_DEPTH];
52 int include_stack_ptr = 0;
62 yylloc.start = yylloc.end;
63 type_yylloc.start = type_yylloc.end;
64 expression_yylloc.start = expression_yylloc.end;
67 "#" { preprocessor(); }
69 "//" { commentCPP(); }
71 "auto" { return(AUTO); }
72 "break" { return(BREAK); }
73 "case" { return(CASE); }
74 "char" { return(CHAR); }
75 "const" { return(CONST); }
76 "continue" { return(CONTINUE); }
77 "default" { return(DEFAULT); }
79 "double" { return(DOUBLE); }
80 "else" { return(ELSE); }
81 "enum" { return(ENUM); }
82 "extern" { return(EXTERN); }
83 "float" { return(FLOAT); }
84 "for" { return(FOR); }
85 "goto" { return(GOTO); }
87 "int" { return(INT); }
88 "uint" { return(UINT); }
89 /* "uint16" { return(UINT16); } */
90 /* "uint32" { return(UINT32); } */
91 /* "bool" { return(BOOL_TOKEN); } */
92 "long" { return(LONG); }
93 "register" { return(REGISTER); }
94 "return" { return(RETURN); }
95 "short" { return(SHORT); }
96 "signed" { return(SIGNED); }
97 "__signed__" { return(SIGNED); }
98 "sizeof" { return(SIZEOF); }
99 "static" { return(STATIC); }
100 "struct" { return(STRUCT); }
101 "switch" { return(SWITCH); }
102 "typedef" { return(TYPEDEF); }
103 "union" { return(UNION); }
104 "unsigned" { return(UNSIGNED); }
105 "void" { return(VOID); }
106 "volatile" { return(VOLATILE); }
107 "__volatile__" { return(VOLATILE); }
108 "__volatile" { return(VOLATILE); }
109 "while" { return(WHILE); }
111 "property" { return(PROPERTY); }
112 "set" { return(SETPROP); } // TODO: Don't make this a keyword...
113 "get" { return(GETPROP); } // TODO: Don't make this a keyword...
114 "isset" { return(ISPROPSET); } // TODO: Don't make this a keyword...
115 "class" { return(CLASS); }
116 "thisclass" { return(THISCLASS); }
117 "virtual" { return(VIRTUAL); }
118 "delete" { return(DELETE); }
119 "new" { return(NEWOP); }
120 "new0" { return(NEW0OP); }
121 "renew" { return(RENEW); }
122 "renew0" { return(RENEW0); }
123 "import" { return(IMPORT); }
124 "define" { return(DEFINE); }
125 "__int64" { return(INT64); }
126 "int64" { return(INT64); }
127 "__builtin_va_list" { return(VALIST); }
128 "__builtin_va_arg" { return(VAARG); }
130 /* "__attribute__".?"(("({D}|{L})*"))" { return(EXT_ATTRIB); } */
132 /* DID I MEAN? "__attribute__"" "*"(("" "*({D}|{L})*" "*("("({D}|{L})*(" "*","" "*({D}|{L})*)*" "*")")?" "*"))" { return(EXT_ATTRIB); } */
134 "__attribute_deprecated__"(" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
135 "__attribute__"(" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
136 "__attribute"(" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
138 /* "__attribute__".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); } */
139 /* "__attribute".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); }*/
141 "__inline__" { return(EXT_STORAGE); }
142 "_inline" { return(EXT_STORAGE); }
143 "__inline" { return(EXT_STORAGE); }
144 "inline" { return(EXT_STORAGE); }
145 "__declspec("({D}|{L})*")" { return(EXT_STORAGE); }
146 "dllexport" { return(EXT_STORAGE); }
147 "dllimport" { return(EXT_STORAGE); }
148 "__cdecl" { return(EXT_DECL); }
149 "__stdcall" { return(EXT_DECL); }
150 "__stdcall__" { return(EXT_DECL); }
151 "_stdcall" { return(EXT_DECL); }
152 "stdcall" { return(EXT_DECL); }
153 "__restrict" { return(EXT_DECL); }
154 "__const" { return(EXT_DECL); }
155 "__restrict__" { return(EXT_DECL); }
156 "public" { return(PUBLIC); }
157 "private" { return(PRIVATE); }
158 "typed_object" { return(TYPED_OBJECT); }
159 "any_object" { return(ANY_OBJECT); }
160 "incref" { return(_INCREF); }
161 "__extension__" { return(EXTENSION); }
162 "_extension_" { return(EXTENSION); }
163 "__asm__" { return(ASM); }
164 "asm" { return(ASM); }
165 "__asm" { return(ASM); }
166 "__typeof" { return(TYPEOF); }
167 "watch" { return(WATCH); }
168 "stopwatching" { return(STOPWATCHING); }
169 "firewatchers" { return(FIREWATCHERS); }
170 "watchable" { return(WATCHABLE); }
171 "class_designer" { return(CLASS_DESIGNER); }
172 "class_no_expansion" { return(CLASS_NO_EXPANSION); }
173 "class_fixed" { return(CLASS_FIXED); }
174 "class_default_property" { return(CLASS_DEFAULT_PROPERTY); }
175 "property_category" { return(PROPERTY_CATEGORY); }
176 "class_data" { return(CLASS_DATA); }
177 "class_property" { return(CLASS_PROPERTY); }
178 "subclass" { return(SUBCLASS); }
179 "namespace" { return(NAMESPACE); }
180 "dbtable" { return(DBTABLE); }
181 "dbfield" { return(DBFIELD); }
182 "dbindex" { return(DBINDEX); }
183 "database_open" { return(DATABASE_OPEN); }
185 ("::"|(({IDENT}"&"?"::")*)){IDENT}? { return(check_type()); } // {L}({L}|{D})* { return(check_type()); } // ("::"|(({IDENT}"::")*)){IDENT} { return(check_type()); } // {L}({L}|{D})* { return(check_type()); }
187 0[xX]{H}+{IS}? { return(CONSTANT); }
188 0{D}+{IS}? { return(CONSTANT); }
189 {D}+{IS}? { return(CONSTANT); }
190 L?'(\\.|[^\\'])+' { return(CONSTANT); }
192 {D}+{E}{FS}? { return(CONSTANT); }
193 {D}*"."{D}+({E})?{FS}? { return(CONSTANT); }
194 {D}+"."{D}*({E})?{FS}? { return(CONSTANT); }
196 L?\"(\\.|[^\\"])*\" { return(STRING_LITERAL); }
198 "..." { return(ELLIPSIS); }
199 ">>=" { return(RIGHT_ASSIGN); }
200 "<<=" { return(LEFT_ASSIGN); }
201 "+=" { return(ADD_ASSIGN); }
202 "-=" { return(SUB_ASSIGN); }
203 "*=" { return(MUL_ASSIGN); }
204 "/=" { return(DIV_ASSIGN); }
205 "%=" { return(MOD_ASSIGN); }
206 "&=" { return(AND_ASSIGN); }
207 "^=" { return(XOR_ASSIGN); }
208 "|=" { return(OR_ASSIGN); }
209 ">>" { return(RIGHT_OP); }
210 "<<" { return(LEFT_OP); }
211 "++" { return(INC_OP); }
212 "--" { return(DEC_OP); }
213 "->" { return(PTR_OP); }
214 "&&" { return(AND_OP); }
215 "||" { return(OR_OP); }
216 "<=" { return(LE_OP); }
217 ">=" { return(GE_OP); }
218 "==" { return(EQ_OP); }
219 "!=" { return(NE_OP); }
220 /* "::" { return(CLASS_OP); } */
222 ("{"|"<%") { return('{'); }
223 ("}"|"%>") { return('}'); }
229 ("["|"<:") { return('['); }
230 ("]"|":>") { return(']'); }
248 if ( --include_stack_ptr < 0 )
255 yy_delete_buffer( YY_CURRENT_BUFFER );
256 fileInput = fileStack[include_stack_ptr];
257 yylloc = locStack[include_stack_ptr];
258 type_yylloc = locStack[include_stack_ptr];
259 expression_yylloc = locStack[include_stack_ptr];
260 yy_switch_to_buffer(include_stack[include_stack_ptr] );
261 defaultDeclMode = declMode = declModeStack[include_stack_ptr];
266 [ \v\f] { yylloc.start = yylloc.end; type_yylloc.start = type_yylloc.end; expression_yylloc.start = expression_yylloc.end;}
268 yylloc.end.charPos = 1; yylloc.end.line += yyleng; yylloc.start = yylloc.end;
269 type_yylloc.end.charPos = 1; type_yylloc.end.line += yyleng; type_yylloc.start = type_yylloc.end;
270 expression_yylloc.end.charPos = 1; expression_yylloc.end.line += yyleng; expression_yylloc.start = expression_yylloc.end;
273 yylloc.start.charPos++ /*= 3 - (yylloc.start.col % 3)*/; yylloc.end.charPos = yylloc.start.charPos; yylloc.start.pos = yylloc.end.pos;
274 expression_yylloc.start.charPos++ /*= 3 - (expression_yylloc.start.col % 3)*/; expression_yylloc.end.charPos = expression_yylloc.start.charPos; expression_yylloc.start.pos = expression_yylloc.end.pos;
275 type_yylloc.start.charPos++ /*= 3 - (type_yylloc.start.col % 3)*/; type_yylloc.end.charPos = type_yylloc.start.charPos; type_yylloc.start.pos = type_yylloc.end.pos;
278 . { yylloc.start = yylloc.end; expression_yylloc.start = expression_yylloc.end; type_yylloc.start = type_yylloc.end; }
299 yylloc.end.charPos = 1;
305 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
310 yylloc.end.charPos++;
313 if(c == '/' && last == '*')
317 yylloc.start = yylloc.end;
333 yylloc.end.charPos = 1;
340 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
345 yylloc.end.charPos++;
350 yylloc.start = yylloc.end;
369 yylloc.end.charPos = 1;
374 char * pointer = line + 1;
377 lineNumber = GetValue(&pointer);
380 char fileName[MAX_LOCATION];
383 GetString(&pointer, fileName, MAX_LOCATION);
384 inOut = GetValue(&pointer);
388 char extension[MAX_EXTENSION];
390 defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
392 GetExtension(fileName, extension);
393 if(!strcmp(extension, "c") || !strcmp(extension, "h"))
394 declMode = defaultDeclMode = defaultAccess;
401 defaultDeclMode = declMode = declModeStack[include_stack_ptr];
404 yylloc.end.charPos = 1;
405 yylloc.end.line = lineNumber;
406 //yylloc.end.pos -= count;
407 yylloc.end.included = (include_stack_ptr > 0) ? GetIncludeFileID(fileName) : 0;
410 int lineNumber = strtol(line+1, &endPtr, 0);
416 yylloc.end.charPos = 1;
417 yylloc.end.line = lineNumber;
418 yylloc.end.pos -= count;
427 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
436 yylloc.end.charPos++;
442 yylloc.start = yylloc.end;
445 TrimLSpaces(line, line);
446 for(c = 0; line[c] && line[c] != ' '; c++);
447 if(!strncmp(line, "include", c))
449 char includeFile[MAX_LOCATION] = "";
451 strcpy(line, line+c);
452 TrimLSpaces(line, line);
455 for(c = 1; line[c]; c++)
459 strncpy(includeFile, line+1, c-1);
460 includeFile[c-1] = '\0';
465 else if(line[0] == '<')
467 for(c = 1; line[c]; c++)
470 strncpy(includeFile, line+1, c-1);
471 includeFile[c-1] = '\0';
476 if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
478 fprintf( stderr, "Includes nested too deeply" );
482 if(inCompiler || !FindIncludeFileID(includeFile))
484 File file = OpenIncludeFile(includeFile);
487 char extension[MAX_EXTENSION];
489 fileStack[include_stack_ptr] = fileInput;
490 locStack[include_stack_ptr] = yylloc;
491 defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
492 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
494 yylloc.start.charPos = yylloc.end.charPos = 1;
495 yylloc.start.line = yylloc.end.line = 1;
496 yylloc.start.pos = yylloc.end.pos = 0;
497 yylloc.start.included = yylloc.end.included = GetIncludeFileID(includeFile);
499 GetExtension(includeFile, extension);
500 if(!strcmp(extension, "c") || !strcmp(extension, "h"))
501 declMode = defaultDeclMode = defaultAccess;
504 yy_switch_to_buffer( yy_create_buffer( fileInput, YY_BUF_SIZE ) );
514 public void resetScanner()
517 yylloc.start.charPos = yylloc.end.charPos = 1;
518 yylloc.start.line = yylloc.end.line = 1;
519 yylloc.start.pos = yylloc.end.pos = 0;
520 yylloc.start.included = yylloc.end.included = false;
522 expression_yylloc.start.charPos = expression_yylloc.end.charPos = 1;
523 expression_yylloc.start.line = expression_yylloc.end.line = 1;
524 expression_yylloc.start.pos = expression_yylloc.end.pos = 0;
525 expression_yylloc.start.included = expression_yylloc.end.included = false;
527 type_yylloc.start.charPos = type_yylloc.end.charPos = 1;
528 type_yylloc.start.line = type_yylloc.end.line = 1;
529 type_yylloc.start.pos = type_yylloc.end.pos = 0;
530 type_yylloc.start.included = type_yylloc.end.included = false;
532 include_stack_ptr = 0;
535 void resetScannerPos(CodePosition pos)
538 yylloc.start = yylloc.end = pos;
539 type_yylloc.start = type_yylloc.end = pos;
540 expression_yylloc.start = expression_yylloc.end = pos;