14 #define YYLTYPE Location
15 #define YY_NEVER_INTERACTIVE 1 // Avoid calling isatty on eC File object
20 public void SetEchoOn(bool b) { echoOn = b; }
22 extern YYLTYPE type_yylloc;
23 extern YYLTYPE expression_yylloc;
25 extern File fileInput;
31 yylloc.end.charPos += yyleng;
32 yylloc.end.pos += yyleng;
33 type_yylloc.end.charPos += yyleng;
34 type_yylloc.end.pos += yyleng;
35 expression_yylloc.end.charPos += yyleng;
36 expression_yylloc.end.pos += yyleng;
39 #define YY_USER_ACTION \
43 yylloc.end.charPos += yyleng;
44 yylloc.end.pos += yyleng;
47 #define YY_INPUT(buf,result,max_size) \
48 result = fileInput.Read(buf, 1, max_size) \
50 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
51 File fileStack[MAX_INCLUDE_DEPTH];
52 char sourceFileStack[MAX_INCLUDE_DEPTH][MAX_LOCATION];
53 public void SetSomeSourceFileStack(const char * fileName, int index) { strcpy(sourceFileStack[index], fileName); }
54 YYLTYPE locStack[MAX_INCLUDE_DEPTH];
55 AccessMode declModeStack[MAX_INCLUDE_DEPTH];
56 int include_stack_ptr = 0;
66 yylloc.start = yylloc.end;
67 type_yylloc.start = type_yylloc.end;
68 expression_yylloc.start = expression_yylloc.end;
71 "#" { preprocessor(); }
73 "//" { commentCPP(); }
75 "auto" { return(AUTO); }
76 "break" { return(BREAK); }
77 "case" { return(CASE); }
78 "char" { return(CHAR); }
79 "const" { return(CONST); }
80 "continue" { return(CONTINUE); }
81 "default" { return(DEFAULT); }
83 "double" { return(DOUBLE); }
84 "else" { return(ELSE); }
85 "enum" { return(ENUM); }
86 "extern" { return(EXTERN); }
87 "float" { return(FLOAT); }
88 "for" { return(FOR); }
89 "goto" { return(GOTO); }
91 "int" { return(INT); }
92 "uint" { return(UINT); }
93 /* "uint16" { return(UINT16); } */
94 /* "uint32" { return(UINT32); } */
95 /* "bool" { return(BOOL_TOKEN); } */
96 "long" { return(LONG); }
97 "register" { return(REGISTER); }
98 "return" { return(RETURN); }
99 "short" { return(SHORT); }
100 "signed" { return(SIGNED); }
101 "__signed" { return(SIGNED); }
102 "__signed__" { return(SIGNED); }
103 "sizeof" { return(SIZEOF); }
104 "__alignof__" { return(ALIGNOF); }
105 "static" { return(STATIC); }
106 "__thread" { return(THREAD); }
107 "struct" { return(STRUCT); }
108 "switch" { return(SWITCH); }
109 "typedef" { return(TYPEDEF); }
110 "union" { return(UNION); }
111 "unsigned" { return(UNSIGNED); }
112 "void" { return(VOID); }
113 "volatile" { return(VOLATILE); }
114 "__volatile__" { return(VOLATILE); }
115 "__volatile" { return(VOLATILE); }
116 "while" { return(WHILE); }
118 "property" { return(PROPERTY); }
119 "set" { return(SETPROP); } // TODO: Don't make this a keyword...
120 "get" { return(GETPROP); } // TODO: Don't make this a keyword...
121 "isset" { return(ISPROPSET); } // TODO: Don't make this a keyword...
122 "class" { return(CLASS); }
123 "thisclass" { return(THISCLASS); }
124 "virtual" { return(VIRTUAL); }
125 "delete" { return(DELETE); }
126 "new" { return(NEWOP); }
127 "new0" { return(NEW0OP); }
128 "renew" { return(RENEW); }
129 "renew0" { return(RENEW0); }
130 "import" { return(IMPORT); }
131 "define" { return(DEFINE); }
132 "__int64" { return(INT64); }
133 "int64" { return(INT64); }
134 "__builtin_va_list" { return(VALIST); }
135 "__builtin_va_arg" { return(VAARG); }
136 "Bool" { return(BOOL); }
137 "_Bool" { return(_BOOL); }
138 "_Complex" { return(_COMPLEX); }
139 "_Imaginary" { return(_IMAGINARY); }
140 "restrict" { return(EXT_DECL); }
142 /* "__attribute__".?"(("({D}|{L})*"))" { return(EXT_ATTRIB); } */
144 /* DID I MEAN? "__attribute__"" "*"(("" "*({D}|{L})*" "*("("({D}|{L})*(" "*","" "*({D}|{L})*)*" "*")")?" "*"))" { return(EXT_ATTRIB); } */
147 "__attribute_deprecated__"(" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
148 "__attribute__" (" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
149 "__attribute" (" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
152 [__attribute__] [spaces]
154 [digits | letters] [spaces]
155 ( [(] [digits or letters or "] ( [spaces] [,] [spaces] [digits or letters or "] )* [spaces] [)] )?
157 ( [,] [spaces] [digits or letters] [spaces]
158 ( [(] [digits or letters or "]
159 ( [spaces] [,] [spaces] [digits or letters or "] )* [spaces] [)]
164 /* "__attribute__".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); } */
165 /* "__attribute".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); }*/
167 "__attribute_deprecated__" { return ATTRIB_DEP; }
168 "__attribute__" { return ATTRIB; }
169 "__attribute" { return __ATTRIB; }
171 "__inline__" { return(EXT_STORAGE); }
172 "_inline" { return(EXT_STORAGE); }
173 "__inline" { return(EXT_STORAGE); }
174 "inline" { return(EXT_STORAGE); }
175 "__declspec("({D}|{L})*")" { return(EXT_STORAGE); }
176 "dllexport" { return(EXT_STORAGE); }
177 "dllimport" { return(EXT_STORAGE); }
178 "__cdecl" { return(EXT_DECL); }
179 "__stdcall" { return(EXT_DECL); }
180 "__stdcall__" { return(EXT_DECL); }
181 "_stdcall" { return(EXT_DECL); }
182 "stdcall" { return(EXT_DECL); }
183 "__restrict" { return(EXT_DECL); }
184 "__const" { return(EXT_DECL); }
185 "__restrict__" { return(EXT_DECL); }
186 "public" { return(PUBLIC); }
187 "private" { return(PRIVATE); }
188 "typed_object" { return(TYPED_OBJECT); }
189 "any_object" { return(ANY_OBJECT); }
190 "incref" { return(_INCREF); }
191 "__extension__" { return(EXTENSION); }
192 "_extension_" { return(EXTENSION); }
193 "__asm__" { return(ASM); }
194 "asm" { return(ASM); }
195 "__asm" { return(ASM); }
196 "__typeof" { return(TYPEOF); }
197 "watch" { return(WATCH); }
198 "stopwatching" { return(STOPWATCHING); }
199 "firewatchers" { return(FIREWATCHERS); }
200 "watchable" { return(WATCHABLE); }
201 "class_designer" { return(CLASS_DESIGNER); }
202 "class_no_expansion" { return(CLASS_NO_EXPANSION); }
203 "class_fixed" { return(CLASS_FIXED); }
204 "class_default_property" { return(CLASS_DEFAULT_PROPERTY); }
205 "property_category" { return(PROPERTY_CATEGORY); }
206 "class_data" { return(CLASS_DATA); }
207 "class_property" { return(CLASS_PROPERTY); }
208 "subclass" { return(SUBCLASS); }
209 "namespace" { return(NAMESPACE); }
210 "dbtable" { return(DBTABLE); }
211 "dbfield" { return(DBFIELD); }
212 "dbindex" { return(DBINDEX); }
213 "database_open" { return(DATABASE_OPEN); }
215 ("::"|(({IDENT}"&"?"::")*)){IDENT}? { return(check_type()); } // {L}({L}|{D})* { return(check_type()); } // ("::"|(({IDENT}"::")*)){IDENT} { return(check_type()); } // {L}({L}|{D})* { return(check_type()); }
217 0[xX]{H}+{IS}? { return(CONSTANT); }
219 0[xX]{H}+{P}{FS}? { return(CONSTANT); }
220 0[xX]{H}*"."{H}+({P})?{FS}? { return(CONSTANT); }
221 0[xX]{H}+"."{H}*({P})?{FS}? { return(CONSTANT); }
223 0{D}+{IS}? { return(CONSTANT); }
224 {D}+{IS}? { return(CONSTANT); }
225 L?'(\\.|[^\\'])+' { return(CONSTANT); }
227 {D}+{E}{FS}? { return(CONSTANT); }
228 {D}*"."{D}+({E})?{FS}? { return(CONSTANT); }
229 {D}+"."{D}*({E})?{FS}? { return(CONSTANT); }
231 L?\"(\\.|[^\\"])*\" { return(STRING_LITERAL); }
233 "..." { return(ELLIPSIS); }
234 ">>=" { return(RIGHT_ASSIGN); }
235 "<<=" { return(LEFT_ASSIGN); }
236 "+=" { return(ADD_ASSIGN); }
237 "-=" { return(SUB_ASSIGN); }
238 "*=" { return(MUL_ASSIGN); }
239 "/=" { return(DIV_ASSIGN); }
240 "%=" { return(MOD_ASSIGN); }
241 "&=" { return(AND_ASSIGN); }
242 "^=" { return(XOR_ASSIGN); }
243 "|=" { return(OR_ASSIGN); }
244 ">>" { return(RIGHT_OP); }
245 "<<" { return(LEFT_OP); }
246 "++" { return(INC_OP); }
247 "--" { return(DEC_OP); }
248 "->" { return(PTR_OP); }
249 "&&" { return(AND_OP); }
250 "||" { return(OR_OP); }
251 "<=" { return(LE_OP); }
252 ">=" { return(GE_OP); }
253 "==" { return(EQ_OP); }
254 "!=" { return(NE_OP); }
255 /* "::" { return(CLASS_OP); } */
257 ("{"|"<%") { return('{'); }
258 ("}"|"%>") { return('}'); }
264 ("["|"<:") { return('['); }
265 ("]"|":>") { return(']'); }
283 while(include_stack_ptr && !fileStack[include_stack_ptr-1])
286 defaultDeclMode = declMode = structDeclMode = declModeStack[include_stack_ptr];
289 if ( --include_stack_ptr < 0 )
291 include_stack_ptr = 0;
297 yy_delete_buffer( YY_CURRENT_BUFFER );
298 fileInput = fileStack[include_stack_ptr];
299 yylloc = locStack[include_stack_ptr];
300 type_yylloc = locStack[include_stack_ptr];
301 expression_yylloc = locStack[include_stack_ptr];
302 yy_switch_to_buffer(include_stack[include_stack_ptr] );
303 defaultDeclMode = declMode = structDeclMode = declModeStack[include_stack_ptr];
308 [ \v\f] { yylloc.start = yylloc.end; type_yylloc.start = type_yylloc.end; expression_yylloc.start = expression_yylloc.end;}
310 yylloc.end.charPos = 1; yylloc.end.line += yyleng; yylloc.start = yylloc.end;
311 type_yylloc.end.charPos = 1; type_yylloc.end.line += yyleng; type_yylloc.start = type_yylloc.end;
312 expression_yylloc.end.charPos = 1; expression_yylloc.end.line += yyleng; expression_yylloc.start = expression_yylloc.end;
315 yylloc.start.charPos++ /*= 3 - (yylloc.start.col % 3)*/; yylloc.end.charPos = yylloc.start.charPos; yylloc.start.pos = yylloc.end.pos;
316 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;
317 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;
319 [\r] { yylloc.start = yylloc.end; expression_yylloc.start = expression_yylloc.end; type_yylloc.start = type_yylloc.end; }
321 yylloc.start = yylloc.end; expression_yylloc.start = expression_yylloc.end; type_yylloc.start = type_yylloc.end;
323 printf("lexer error: invalid char 0x%X at line %d, col %d\n", (unsigned char)yytext[0], yylloc.start.line, yylloc.start.charPos);
348 yylloc.end.charPos = 1;
354 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
359 yylloc.end.charPos++;
362 if(c == '/' && last == '*')
366 yylloc.start = yylloc.end;
382 yylloc.end.charPos = 1;
389 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
394 yylloc.end.charPos++;
399 yylloc.start = yylloc.end;
418 yylloc.end.charPos = 1;
423 char * pointer = line + 1;
426 lineNumber = GetValue(&pointer);
429 char fileName[MAX_LOCATION];
434 GetString(&pointer, fileName, MAX_LOCATION);
435 inOut = GetValue(&pointer);
439 char extension[MAX_EXTENSION];
441 defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
443 GetExtension(fileName, extension);
444 if(!strcmp(extension, "c") || !strcmp(extension, "h"))
445 declMode = defaultDeclMode = structDeclMode = defaultAccess;
447 fileStack[include_stack_ptr] = null;
453 defaultDeclMode = declMode = structDeclMode = declModeStack[include_stack_ptr];
456 yylloc.end.charPos = 1;
457 yylloc.end.line = lineNumber;
458 //yylloc.end.pos -= count;
460 if(include_stack_ptr > 0 || (lineNumber && fileName[0]))
461 yylloc.end.included = GetIncludeFileID(fileName);
463 yylloc.end.included = 0;
466 int lineNumber = strtol(line+1, &endPtr, 0);
472 yylloc.end.charPos = 1;
473 yylloc.end.line = lineNumber;
474 yylloc.end.pos -= count;
483 yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
492 yylloc.end.charPos++;
498 yylloc.start = yylloc.end;
501 TrimLSpaces(line, line);
502 for(c = 0; line[c] && line[c] != ' '; c++);
503 if(!strncmp(line, "include", c))
505 char includeFile[MAX_LOCATION] = "";
507 memmove(line, line+c, strlen(line+c)+1);
508 TrimLSpaces(line, line);
511 for(c = 1; line[c]; c++)
515 strncpy(includeFile, line+1, c-1);
516 includeFile[c-1] = '\0';
521 else if(line[0] == '<')
523 for(c = 1; line[c]; c++)
526 strncpy(includeFile, line+1, c-1);
527 includeFile[c-1] = '\0';
532 if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
534 fprintf( stderr, "%s", $"Includes nested too deeply" );
538 if(inCompiler || !FindIncludeFileID(includeFile))
540 File file = OpenIncludeFile(includeFile);
543 char extension[MAX_EXTENSION];
545 fileStack[include_stack_ptr] = fileInput;
546 locStack[include_stack_ptr] = yylloc;
547 defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
548 include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
550 yylloc.start.charPos = yylloc.end.charPos = 1;
551 yylloc.start.line = yylloc.end.line = 1;
552 yylloc.start.pos = yylloc.end.pos = 0;
553 yylloc.start.included = yylloc.end.included = GetIncludeFileID(includeFile);
555 GetExtension(includeFile, extension);
556 if(!strcmp(extension, "c") || !strcmp(extension, "h"))
557 declMode = defaultDeclMode = structDeclMode = defaultAccess;
560 yy_switch_to_buffer( yy_create_buffer( fileInput, YY_BUF_SIZE ) );
568 public void resetScanner()
571 yylloc.start.charPos = yylloc.end.charPos = 1;
572 yylloc.start.line = yylloc.end.line = 1;
573 yylloc.start.pos = yylloc.end.pos = 0;
574 yylloc.start.included = yylloc.end.included = 0;
576 expression_yylloc.start.charPos = expression_yylloc.end.charPos = 1;
577 expression_yylloc.start.line = expression_yylloc.end.line = 1;
578 expression_yylloc.start.pos = expression_yylloc.end.pos = 0;
579 expression_yylloc.start.included = expression_yylloc.end.included = 0;
581 type_yylloc.start.charPos = type_yylloc.end.charPos = 1;
582 type_yylloc.start.line = type_yylloc.end.line = 1;
583 type_yylloc.start.pos = type_yylloc.end.pos = 0;
584 type_yylloc.start.included = type_yylloc.end.included = 0;
586 include_stack_ptr = 0;
589 void resetScannerPos(CodePosition pos)
592 yylloc.start = yylloc.end = pos;
593 type_yylloc.start = type_yylloc.end = pos;
594 expression_yylloc.start = expression_yylloc.end = pos;
601 YYLTYPE expression_yylloc;
604 AccessMode defaultDeclMode;
607 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
608 File fileStack[MAX_INCLUDE_DEPTH];
609 char sourceFileStack[MAX_INCLUDE_DEPTH][MAX_LOCATION];
610 YYLTYPE locStack[MAX_INCLUDE_DEPTH];
611 AccessMode declModeStack[MAX_INCLUDE_DEPTH];
612 int include_stack_ptr;
613 YY_BUFFER_STATE buffer;
626 LexerBackup pushLexer()
628 LexerBackup backup { };
630 backup.yylloc = yylloc;
631 backup.type_yylloc = type_yylloc;
632 backup.expression_yylloc = expression_yylloc;
633 backup.fileInput = fileInput;
634 memcpy(backup.include_stack, include_stack, sizeof(include_stack));
635 memcpy(backup.fileStack, fileStack, sizeof(fileStack));
636 memcpy(backup.sourceFileStack, sourceFileStack, sizeof(sourceFileStack));
637 memcpy(backup.locStack, locStack, sizeof(locStack));
638 memcpy(backup.declModeStack, declModeStack, sizeof(declModeStack));
639 backup.include_stack_ptr = include_stack_ptr;
640 backup.defaultDeclMode = defaultDeclMode;
641 backup.declMode = declMode;
642 backup.buffer = yy_current_buffer;
644 backup.yy_n_chars = yy_n_chars;
645 backup.yytext_ptr = yytext_ptr;
646 backup.yy_c_buf_p = yy_c_buf_p;
648 backup.yy_hold_char = yy_hold_char;
649 backup.yychar = yychar;
650 backup.yy_init = yy_init;
651 backup.yy_start = yy_start;
655 yy_current_buffer = 0;
657 yylloc.start.charPos = yylloc.end.charPos = 1;
658 yylloc.start.line = yylloc.end.line = 1;
659 yylloc.start.pos = yylloc.end.pos = 0;
660 yylloc.start.included = yylloc.end.included = 0;
662 expression_yylloc.start.charPos = expression_yylloc.end.charPos = 1;
663 expression_yylloc.start.line = expression_yylloc.end.line = 1;
664 expression_yylloc.start.pos = expression_yylloc.end.pos = 0;
665 expression_yylloc.start.included = expression_yylloc.end.included = 0;
667 type_yylloc.start.charPos = type_yylloc.end.charPos = 1;
668 type_yylloc.start.line = type_yylloc.end.line = 1;
669 type_yylloc.start.pos = type_yylloc.end.pos = 0;
670 type_yylloc.start.included = type_yylloc.end.included = 0;
672 include_stack_ptr = 0;
677 void popLexer(LexerBackup backup)
679 yylloc = backup.yylloc;
680 type_yylloc = backup.type_yylloc;
681 expression_yylloc = backup.expression_yylloc;
682 fileInput = backup.fileInput;
683 memcpy(include_stack, backup.include_stack, sizeof(include_stack));
684 memcpy(fileStack, backup.fileStack, sizeof(fileStack));
685 memcpy(sourceFileStack, backup.sourceFileStack, sizeof(sourceFileStack));
686 memcpy(locStack, backup.locStack, sizeof(locStack));
687 memcpy(declModeStack, backup.declModeStack, sizeof(declModeStack));
688 include_stack_ptr = backup.include_stack_ptr;
689 defaultDeclMode = backup.defaultDeclMode;
690 declMode = structDeclMode = backup.declMode;
692 // yy_switch_to_buffer(backup.buffer);
693 yy_current_buffer = backup.buffer;
694 yy_n_chars = backup.yy_n_chars;
695 yytext_ptr = backup.yytext_ptr;
696 yy_c_buf_p = backup.yy_c_buf_p;
698 yy_hold_char = backup.yy_hold_char;
699 yychar = backup.yychar;
700 yy_init = backup.yy_init;
701 yy_start = backup.yy_start;