11 #define YYLTYPE Location
12 #define YY_NEVER_INTERACTIVE 1 // Avoid calling isatty on eC File object
17 public void SetEchoOn(bool b) { echoOn = b; }
19 extern YYLTYPE type_yylloc;
20 extern YYLTYPE expression_yylloc;
22 extern File fileInput;
28 yylloc.end.charPos += yyleng;
29 yylloc.end.pos += yyleng;
30 type_yylloc.end.charPos += yyleng;
31 type_yylloc.end.pos += yyleng;
32 expression_yylloc.end.charPos += yyleng;
33 expression_yylloc.end.pos += yyleng;
36 #define YY_USER_ACTION \
40 yylloc.end.charPos += yyleng;
41 yylloc.end.pos += yyleng;
44 #define YY_INPUT(buf,result,max_size) \
45 result = fileInput.Read(buf, 1, max_size) \
47 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
48 File fileStack[MAX_INCLUDE_DEPTH];
49 char sourceFileStack[MAX_INCLUDE_DEPTH][MAX_LOCATION];
50 public void SetSomeSourceFileStack(char * fileName, int index) { strcpy(sourceFileStack[index], fileName); }
51 YYLTYPE locStack[MAX_INCLUDE_DEPTH];
52 AccessMode declModeStack[MAX_INCLUDE_DEPTH];
53 int include_stack_ptr = 0;
63 yylloc.start = yylloc.end;
64 type_yylloc.start = type_yylloc.end;
65 expression_yylloc.start = expression_yylloc.end;
68 "#" { preprocessor(); }
70 "//" { commentCPP(); }
72 "auto" { return(AUTO); }
73 "break" { return(BREAK); }
74 "case" { return(CASE); }
75 "char" { return(CHAR); }
76 "const" { return(CONST); }
77 "continue" { return(CONTINUE); }
78 "default" { return(DEFAULT); }
80 "double" { return(DOUBLE); }
81 "else" { return(ELSE); }
82 "enum" { return(ENUM); }
83 "extern" { return(EXTERN); }
84 "float" { return(FLOAT); }
85 "for" { return(FOR); }
86 "goto" { return(GOTO); }
88 "int" { return(INT); }
89 "uint" { return(UINT); }
90 /* "uint16" { return(UINT16); } */
91 /* "uint32" { return(UINT32); } */
92 /* "bool" { return(BOOL_TOKEN); } */
93 "long" { return(LONG); }
94 "register" { return(REGISTER); }
95 "return" { return(RETURN); }
96 "short" { return(SHORT); }
97 "signed" { return(SIGNED); }
98 "__signed" { return(SIGNED); }
99 "__signed__" { return(SIGNED); }
100 "sizeof" { return(SIZEOF); }
101 "__alignof__" { return(ALIGNOF); }
102 "static" { return(STATIC); }
103 "struct" { return(STRUCT); }
104 "switch" { return(SWITCH); }
105 "typedef" { return(TYPEDEF); }
106 "union" { return(UNION); }
107 "unsigned" { return(UNSIGNED); }
108 "void" { return(VOID); }
109 "volatile" { return(VOLATILE); }
110 "__volatile__" { return(VOLATILE); }
111 "__volatile" { return(VOLATILE); }
112 "while" { return(WHILE); }
114 "property" { return(PROPERTY); }
115 "set" { return(SETPROP); } // TODO: Don't make this a keyword...
116 "get" { return(GETPROP); } // TODO: Don't make this a keyword...
117 "isset" { return(ISPROPSET); } // TODO: Don't make this a keyword...
118 "class" { return(CLASS); }
119 "thisclass" { return(THISCLASS); }
120 "virtual" { return(VIRTUAL); }
121 "delete" { return(DELETE); }
122 "new" { return(NEWOP); }
123 "new0" { return(NEW0OP); }
124 "renew" { return(RENEW); }
125 "renew0" { return(RENEW0); }
126 "import" { return(IMPORT); }
127 "define" { return(DEFINE); }
128 "__int64" { return(INT64); }
129 "int64" { return(INT64); }
130 "__builtin_va_list" { return(VALIST); }
131 "__builtin_va_arg" { return(VAARG); }
133 /* "__attribute__".?"(("({D}|{L})*"))" { return(EXT_ATTRIB); } */
135 /* DID I MEAN? "__attribute__"" "*"(("" "*({D}|{L})*" "*("("({D}|{L})*(" "*","" "*({D}|{L})*)*" "*")")?" "*"))" { return(EXT_ATTRIB); } */
138 "__attribute_deprecated__"(" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
139 "__attribute__" (" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
140 "__attribute" (" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
143 [__attribute__] [spaces]
145 [digits | letters] [spaces]
146 ( [(] [digits or letters or "] ( [spaces] [,] [spaces] [digits or letters or "] )* [spaces] [)] )?
148 ( [,] [spaces] [digits or letters] [spaces]
149 ( [(] [digits or letters or "]
150 ( [spaces] [,] [spaces] [digits or letters or "] )* [spaces] [)]
155 /* "__attribute__".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); } */
156 /* "__attribute".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); }*/
158 "__attribute_deprecated__" { return ATTRIB_DEP; }
159 "__attribute__" { return ATTRIB; }
160 "__attribute" { return __ATTRIB; }
162 "__inline__" { return(EXT_STORAGE); }
163 "_inline" { return(EXT_STORAGE); }
164 "__inline" { return(EXT_STORAGE); }
165 "inline" { return(EXT_STORAGE); }
166 "__declspec("({D}|{L})*")" { return(EXT_STORAGE); }
167 "dllexport" { return(EXT_STORAGE); }
168 "dllimport" { return(EXT_STORAGE); }
169 "__cdecl" { return(EXT_DECL); }
170 "__stdcall" { return(EXT_DECL); }
171 "__stdcall__" { return(EXT_DECL); }
172 "_stdcall" { return(EXT_DECL); }
173 "stdcall" { return(EXT_DECL); }
174 "__restrict" { return(EXT_DECL); }
175 "__const" { return(EXT_DECL); }
176 "__restrict__" { return(EXT_DECL); }
177 "public" { return(PUBLIC); }
178 "private" { return(PRIVATE); }
179 "typed_object" { return(TYPED_OBJECT); }
180 "any_object" { return(ANY_OBJECT); }
181 "incref" { return(_INCREF); }
182 "__extension__" { return(EXTENSION); }
183 "_extension_" { return(EXTENSION); }
184 "__asm__" { return(ASM); }
185 "asm" { return(ASM); }
186 "__asm" { return(ASM); }
187 "__typeof" { return(TYPEOF); }
188 "watch" { return(WATCH); }
189 "stopwatching" { return(STOPWATCHING); }
190 "firewatchers" { return(FIREWATCHERS); }
191 "watchable" { return(WATCHABLE); }
192 "class_designer" { return(CLASS_DESIGNER); }
193 "class_no_expansion" { return(CLASS_NO_EXPANSION); }
194 "class_fixed" { return(CLASS_FIXED); }
195 "class_default_property" { return(CLASS_DEFAULT_PROPERTY); }
196 "property_category" { return(PROPERTY_CATEGORY); }
197 "class_data" { return(CLASS_DATA); }
198 "class_property" { return(CLASS_PROPERTY); }
199 "subclass" { return(SUBCLASS); }
200 "namespace" { return(NAMESPACE); }
201 "dbtable" { return(DBTABLE); }
202 "dbfield" { return(DBFIELD); }
203 "dbindex" { return(DBINDEX); }
204 "database_open" { return(DATABASE_OPEN); }
206 ("::"|(({IDENT}"&"?"::")*)){IDENT}? { return(check_type()); } // {L}({L}|{D})* { return(check_type()); } // ("::"|(({IDENT}"::")*)){IDENT} { return(check_type()); } // {L}({L}|{D})* { return(check_type()); }
208 0[xX]{H}+{IS}? { return(CONSTANT); }
209 0{D}+{IS}? { return(CONSTANT); }
210 {D}+{IS}? { return(CONSTANT); }
211 L?'(\\.|[^\\'])+' { return(CONSTANT); }
213 {D}+{E}{FS}? { return(CONSTANT); }
214 {D}*"."{D}+({E})?{FS}? { return(CONSTANT); }
215 {D}+"."{D}*({E})?{FS}? { return(CONSTANT); }
217 L?\"(\\.|[^\\"])*\" { return(STRING_LITERAL); }
219 "..." { return(ELLIPSIS); }
220 ">>=" { return(RIGHT_ASSIGN); }
221 "<<=" { return(LEFT_ASSIGN); }
222 "+=" { return(ADD_ASSIGN); }
223 "-=" { return(SUB_ASSIGN); }
224 "*=" { return(MUL_ASSIGN); }
225 "/=" { return(DIV_ASSIGN); }
226 "%=" { return(MOD_ASSIGN); }
227 "&=" { return(AND_ASSIGN); }
228 "^=" { return(XOR_ASSIGN); }
229 "|=" { return(OR_ASSIGN); }
230 ">>" { return(RIGHT_OP); }
231 "<<" { return(LEFT_OP); }
232 "++" { return(INC_OP); }
233 "--" { return(DEC_OP); }
234 "->" { return(PTR_OP); }
235 "&&" { return(AND_OP); }
236 "||" { return(OR_OP); }
237 "<=" { return(LE_OP); }
238 ">=" { return(GE_OP); }
239 "==" { return(EQ_OP); }
240 "!=" { return(NE_OP); }
241 /* "::" { return(CLASS_OP); } */
243 ("{"|"<%") { return('{'); }
244 ("}"|"%>") { return('}'); }
250 ("["|"<:") { return('['); }
251 ("]"|":>") { return(']'); }
269 while(include_stack_ptr && !fileStack[include_stack_ptr-1])
272 defaultDeclMode = declMode = declModeStack[include_stack_ptr];
275 if ( --include_stack_ptr < 0 )
277 include_stack_ptr = 0;
283 yy_delete_buffer( YY_CURRENT_BUFFER );
284 fileInput = fileStack[include_stack_ptr];
285 yylloc = locStack[include_stack_ptr];
286 type_yylloc = locStack[include_stack_ptr];
287 expression_yylloc = locStack[include_stack_ptr];
288 yy_switch_to_buffer(include_stack[include_stack_ptr] );
289 defaultDeclMode = declMode = declModeStack[include_stack_ptr];
294 [ \v\f] { yylloc.start = yylloc.end; type_yylloc.start = type_yylloc.end; expression_yylloc.start = expression_yylloc.end;}
296 yylloc.end.charPos = 1; yylloc.end.line += yyleng; yylloc.start = yylloc.end;
297 type_yylloc.end.charPos = 1; type_yylloc.end.line += yyleng; type_yylloc.start = type_yylloc.end;
298 expression_yylloc.end.charPos = 1; expression_yylloc.end.line += yyleng; expression_yylloc.start = expression_yylloc.end;
301 yylloc.start.charPos++ /*= 3 - (yylloc.start.col % 3)*/; yylloc.end.charPos = yylloc.start.charPos; yylloc.start.pos = yylloc.end.pos;
302 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;
303 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;
306 . { yylloc.start = yylloc.end; expression_yylloc.start = expression_yylloc.end; type_yylloc.start = type_yylloc.end; }
329 yylloc.end.charPos = 1;
335 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
340 yylloc.end.charPos++;
343 if(c == '/' && last == '*')
347 yylloc.start = yylloc.end;
363 yylloc.end.charPos = 1;
370 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
375 yylloc.end.charPos++;
380 yylloc.start = yylloc.end;
399 yylloc.end.charPos = 1;
404 char * pointer = line + 1;
407 lineNumber = GetValue(&pointer);
410 char fileName[MAX_LOCATION];
415 GetString(&pointer, fileName, MAX_LOCATION);
416 inOut = GetValue(&pointer);
420 char extension[MAX_EXTENSION];
422 defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
424 GetExtension(fileName, extension);
425 if(!strcmp(extension, "c") || !strcmp(extension, "h"))
426 declMode = defaultDeclMode = defaultAccess;
428 fileStack[include_stack_ptr] = null;
434 defaultDeclMode = declMode = declModeStack[include_stack_ptr];
437 yylloc.end.charPos = 1;
438 yylloc.end.line = lineNumber;
439 //yylloc.end.pos -= count;
441 if(include_stack_ptr > 0 || (lineNumber && fileName[0]))
442 yylloc.end.included = GetIncludeFileID(fileName);
444 yylloc.end.included = 0;
447 int lineNumber = strtol(line+1, &endPtr, 0);
453 yylloc.end.charPos = 1;
454 yylloc.end.line = lineNumber;
455 yylloc.end.pos -= count;
464 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
473 yylloc.end.charPos++;
479 yylloc.start = yylloc.end;
482 TrimLSpaces(line, line);
483 for(c = 0; line[c] && line[c] != ' '; c++);
484 if(!strncmp(line, "include", c))
486 char includeFile[MAX_LOCATION] = "";
488 memmove(line, line+c, strlen(line+c)+1);
489 TrimLSpaces(line, line);
492 for(c = 1; line[c]; c++)
496 strncpy(includeFile, line+1, c-1);
497 includeFile[c-1] = '\0';
502 else if(line[0] == '<')
504 for(c = 1; line[c]; c++)
507 strncpy(includeFile, line+1, c-1);
508 includeFile[c-1] = '\0';
513 if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
515 fprintf( stderr, $"Includes nested too deeply" );
519 if(inCompiler || !FindIncludeFileID(includeFile))
521 File file = OpenIncludeFile(includeFile);
524 char extension[MAX_EXTENSION];
526 fileStack[include_stack_ptr] = fileInput;
527 locStack[include_stack_ptr] = yylloc;
528 defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
529 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
531 yylloc.start.charPos = yylloc.end.charPos = 1;
532 yylloc.start.line = yylloc.end.line = 1;
533 yylloc.start.pos = yylloc.end.pos = 0;
534 yylloc.start.included = yylloc.end.included = GetIncludeFileID(includeFile);
536 GetExtension(includeFile, extension);
537 if(!strcmp(extension, "c") || !strcmp(extension, "h"))
538 declMode = defaultDeclMode = defaultAccess;
541 yy_switch_to_buffer( yy_create_buffer( fileInput, YY_BUF_SIZE ) );
551 public void resetScanner()
554 yylloc.start.charPos = yylloc.end.charPos = 1;
555 yylloc.start.line = yylloc.end.line = 1;
556 yylloc.start.pos = yylloc.end.pos = 0;
557 yylloc.start.included = yylloc.end.included = 0;
559 expression_yylloc.start.charPos = expression_yylloc.end.charPos = 1;
560 expression_yylloc.start.line = expression_yylloc.end.line = 1;
561 expression_yylloc.start.pos = expression_yylloc.end.pos = 0;
562 expression_yylloc.start.included = expression_yylloc.end.included = 0;
564 type_yylloc.start.charPos = type_yylloc.end.charPos = 1;
565 type_yylloc.start.line = type_yylloc.end.line = 1;
566 type_yylloc.start.pos = type_yylloc.end.pos = 0;
567 type_yylloc.start.included = type_yylloc.end.included = 0;
569 include_stack_ptr = 0;
572 void resetScannerPos(CodePosition pos)
575 yylloc.start = yylloc.end = pos;
576 type_yylloc.start = type_yylloc.end = pos;
577 expression_yylloc.start = expression_yylloc.end = pos;
584 YYLTYPE expression_yylloc;
587 AccessMode defaultDeclMode;
590 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
591 File fileStack[MAX_INCLUDE_DEPTH];
592 char sourceFileStack[MAX_INCLUDE_DEPTH][MAX_LOCATION];
593 YYLTYPE locStack[MAX_INCLUDE_DEPTH];
594 AccessMode declModeStack[MAX_INCLUDE_DEPTH];
595 int include_stack_ptr;
596 YY_BUFFER_STATE buffer;
609 LexerBackup pushLexer()
611 LexerBackup backup { };
613 backup.yylloc = yylloc;
614 backup.type_yylloc = type_yylloc;
615 backup.expression_yylloc = expression_yylloc;
616 backup.fileInput = fileInput;
617 memcpy(backup.include_stack, include_stack, sizeof(include_stack));
618 memcpy(backup.fileStack, fileStack, sizeof(fileStack));
619 memcpy(backup.sourceFileStack, sourceFileStack, sizeof(sourceFileStack));
620 memcpy(backup.locStack, locStack, sizeof(locStack));
621 memcpy(backup.declModeStack, declModeStack, sizeof(declModeStack));
622 backup.include_stack_ptr = include_stack_ptr;
623 backup.defaultDeclMode = defaultDeclMode;
624 backup.declMode = declMode;
625 backup.buffer = yy_current_buffer;
627 backup.yy_n_chars = yy_n_chars;
628 backup.yytext_ptr = yytext_ptr;
629 backup.yy_c_buf_p = yy_c_buf_p;
631 backup.yy_hold_char = yy_hold_char;
632 backup.yychar = yychar;
633 backup.yy_init = yy_init;
634 backup.yy_start = yy_start;
638 yy_current_buffer = 0;
640 yylloc.start.charPos = yylloc.end.charPos = 1;
641 yylloc.start.line = yylloc.end.line = 1;
642 yylloc.start.pos = yylloc.end.pos = 0;
643 yylloc.start.included = yylloc.end.included = 0;
645 expression_yylloc.start.charPos = expression_yylloc.end.charPos = 1;
646 expression_yylloc.start.line = expression_yylloc.end.line = 1;
647 expression_yylloc.start.pos = expression_yylloc.end.pos = 0;
648 expression_yylloc.start.included = expression_yylloc.end.included = 0;
650 type_yylloc.start.charPos = type_yylloc.end.charPos = 1;
651 type_yylloc.start.line = type_yylloc.end.line = 1;
652 type_yylloc.start.pos = type_yylloc.end.pos = 0;
653 type_yylloc.start.included = type_yylloc.end.included = 0;
655 include_stack_ptr = 0;
660 void popLexer(LexerBackup backup)
662 yylloc = backup.yylloc;
663 type_yylloc = backup.type_yylloc;
664 expression_yylloc = backup.expression_yylloc;
665 fileInput = backup.fileInput;
666 memcpy(include_stack, backup.include_stack, sizeof(include_stack));
667 memcpy(fileStack, backup.fileStack, sizeof(fileStack));
668 memcpy(sourceFileStack, backup.sourceFileStack, sizeof(sourceFileStack));
669 memcpy(locStack, backup.locStack, sizeof(locStack));
670 memcpy(declModeStack, backup.declModeStack, sizeof(declModeStack));
671 include_stack_ptr = backup.include_stack_ptr;
672 defaultDeclMode = backup.defaultDeclMode;
673 declMode = backup.declMode;
675 // yy_switch_to_buffer(backup.buffer);
676 yy_current_buffer = backup.buffer;
677 yy_n_chars = backup.yy_n_chars;
678 yytext_ptr = backup.yytext_ptr;
679 yy_c_buf_p = backup.yy_c_buf_p;
681 yy_hold_char = backup.yy_hold_char;
682 yychar = backup.yychar;
683 yy_init = backup.yy_init;
684 yy_start = backup.yy_start;