| OLD | NEW |
| 1 #include <fcntl.h> | 1 #include <fcntl.h> |
| 2 #include <stdio.h> | 2 #include <stdio.h> |
| 3 #include <stddef.h> | 3 #include <stddef.h> |
| 4 #include <stdlib.h> | 4 #include <stdlib.h> |
| 5 #include <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 /*!types:re2c */ | 7 /*!types:re2c */ |
| 8 | 8 |
| 9 #if defined(WIN32) | 9 #if defined(WIN32) |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include <unistd.h> | 22 #include <unistd.h> |
| 23 | 23 |
| 24 #ifndef O_BINARY | 24 #ifndef O_BINARY |
| 25 #define O_BINARY 0 | 25 #define O_BINARY 0 |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 // ---------------------------------------------------------------------- | 30 // ---------------------------------------------------------------------- |
| 31 #define PUSH_EOS(T) { printf("got eos\n"); } | 31 #define PUSH_EOS(T) { printf("got eos\n"); } |
| 32 #define PUSH_T(T) { printf("got token %d\n", T); SKIP(); } | 32 #define PUSH_TOKEN(T) { \ |
| 33 #define PUSH_STRING() { printf("got string\n"); SKIP(); } | 33 printf("got token %s (%d)\n", tokenNames[T], T); \ |
| 34 #define PUSH_NUMBER() { printf("got number\n"); SKIP(); } | 34 SKIP(); } |
| 35 #define PUSH_STRING() { \ |
| 36 --cursor; \ |
| 37 printf("got string\n"); \ |
| 38 size_t tokenSize = cursor-start; \ |
| 39 fwrite(start, tokenSize, 1, stdout); \ |
| 40 printf("\n"); \ |
| 41 SKIP(); } |
| 42 #define PUSH_NUMBER() { \ |
| 43 --cursor; \ |
| 44 printf("got number\n"); \ |
| 45 size_t tokenSize = cursor-start; \ |
| 46 fwrite(start, tokenSize, 1, stdout); \ |
| 47 printf("\n"); \ |
| 48 SKIP(); } |
| 35 #define PUSH_IDENTIFIER() { \ | 49 #define PUSH_IDENTIFIER() { \ |
| 50 --cursor; \ |
| 36 printf("got identifier: "); \ | 51 printf("got identifier: "); \ |
| 37 size_t tokenSize = cursor-start; \ | 52 size_t tokenSize = cursor-start; \ |
| 38 fwrite(start, tokenSize, 1, stdout); \ | 53 fwrite(start, tokenSize, 1, stdout); \ |
| 39 printf("\n"); \ | 54 printf("\n"); \ |
| 40 SKIP(); } | 55 SKIP(); } |
| 41 #define PUSH_LINE_TERMINATOR() { printf("got line terminator\n"); SKIP();} | 56 #define PUSH_LINE_TERMINATOR() { printf("got line terminator\n"); SKIP();} |
| 42 #define TERMINATE_ILLEGAL() { return 1; } | 57 #define TERMINATE_ILLEGAL() { return 1; } |
| 43 | 58 |
| 44 #define TOKENS \ | 59 #define TOKENS \ |
| 45 TOK(EOS) \ | 60 TOK(EOS) \ |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 memcpy(limit, input, inputSize); | 259 memcpy(limit, input, inputSize); |
| 245 limit += inputSize; | 260 limit += inputSize; |
| 246 | 261 |
| 247 // The scanner starts here | 262 // The scanner starts here |
| 248 #define YYLIMIT limit | 263 #define YYLIMIT limit |
| 249 #define YYCURSOR cursor | 264 #define YYCURSOR cursor |
| 250 #define YYMARKER marker | 265 #define YYMARKER marker |
| 251 #define YYCTYPE uint8_t | 266 #define YYCTYPE uint8_t |
| 252 | 267 |
| 253 #define SKIP() { start = cursor; YYSETCONDITION(EConditionNorma
l); goto yy0; } | 268 #define SKIP() { start = cursor; YYSETCONDITION(EConditionNorma
l); goto yy0; } |
| 254 #define SEND(x) { send(x); SKIP(); } | |
| 255 #define YYFILL(n) { goto fill; } | 269 #define YYFILL(n) { goto fill; } |
| 256 | 270 |
| 257 #define YYGETSTATE() state | 271 #define YYGETSTATE() state |
| 258 #define YYSETSTATE(x) { state = (x); } | 272 #define YYSETSTATE(x) { state = (x); } |
| 259 | 273 |
| 260 #define YYGETCONDITION() condition | 274 #define YYGETCONDITION() condition |
| 261 #define YYSETCONDITION(x) { condition = (x); } | 275 #define YYSETCONDITION(x) { condition = (x); } |
| 262 | 276 |
| 263 start: | 277 start: |
| 264 | 278 |
| 265 printf("Starting a round; state: %d, condition: %d\n", state, condition)
; | 279 printf("Starting a round; state: %d, condition: %d\n", state, condition)
; |
| 266 | 280 |
| 267 /*!re2c | 281 /*!re2c |
| 268 re2c:indent:top = 1; | 282 re2c:indent:top = 1; |
| 269 re2c:yych:conversion = 0; | 283 re2c:yych:conversion = 0; |
| 270 re2c:condenumprefix = ECondition; | 284 re2c:condenumprefix = ECondition; |
| 271 re2c:define:YYCONDTYPE = Condition; | 285 re2c:define:YYCONDTYPE = Condition; |
| 272 | 286 |
| 273 eof = "\000"; | 287 eof = "\000"; |
| 274 any = [\000-\377]; | 288 any = [\000-\377]; |
| 275 whitespace_char = [ \t\v\f\r]; | 289 whitespace_char = [ \t\v\f\r]; |
| 276 whitespace = whitespace_char+; | 290 whitespace = whitespace_char+; |
| 277 identifier_start = [$_\\a-zA-z]; | 291 identifier_start = [$_\\a-zA-z]; |
| 278 identifier_char = [$_\\a-zA-z0-9]; | 292 identifier_char = [$_\\a-zA-z0-9]; |
| 279 number_start = [0-9]; | 293 number_start = [0-9]; |
| 280 number_char = [0-9\.e]; | 294 number_char = [0-9\.e]; |
| 281 line_terminator = [\n\r]+; | 295 line_terminator = [\n\r]+; |
| 282 | 296 |
| 283 <Normal> "(" { PUSH_T(LPAREN); } | 297 <Normal> "(" { PUSH_TOKEN(LPAREN); } |
| 284 <Normal> ")" { PUSH_T(RPAREN); } | 298 <Normal> ")" { PUSH_TOKEN(RPAREN); } |
| 285 <Normal> "[" { PUSH_T(LBRACK); } | 299 <Normal> "[" { PUSH_TOKEN(LBRACK); } |
| 286 <Normal> "]" { PUSH_T(RBRACK); } | 300 <Normal> "]" { PUSH_TOKEN(RBRACK); } |
| 287 <Normal> "{" { PUSH_T(LBRACE); } | 301 <Normal> "{" { PUSH_TOKEN(LBRACE); } |
| 288 <Normal> "}" { PUSH_T(RBRACE); } | 302 <Normal> "}" { PUSH_TOKEN(RBRACE); } |
| 289 <Normal> ":" { PUSH_T(COLON); } | 303 <Normal> ":" { PUSH_TOKEN(COLON); } |
| 290 <Normal> ";" { PUSH_T(SEMICOLON); } | 304 <Normal> ";" { PUSH_TOKEN(SEMICOLON); } |
| 291 <Normal> "." { PUSH_T(PERIOD); } | 305 <Normal> "." { PUSH_TOKEN(PERIOD); } |
| 292 <Normal> "?" { PUSH_T(CONDITIONAL); } | 306 <Normal> "?" { PUSH_TOKEN(CONDITIONAL); } |
| 293 <Normal> "++" { PUSH_T(INC); } | 307 <Normal> "++" { PUSH_TOKEN(INC); } |
| 294 <Normal> "--" { PUSH_T(DEC); } | 308 <Normal> "--" { PUSH_TOKEN(DEC); } |
| 295 | 309 |
| 296 <Normal> "|=" { PUSH_T(ASSIGN_BIT_OR); } | 310 <Normal> "|=" { PUSH_TOKEN(ASSIGN_BIT_OR); } |
| 297 <Normal> "^=" { PUSH_T(ASSIGN_BIT_XOR); } | 311 <Normal> "^=" { PUSH_TOKEN(ASSIGN_BIT_XOR); } |
| 298 <Normal> "&=" { PUSH_T(ASSIGN_BIT_AND); } | 312 <Normal> "&=" { PUSH_TOKEN(ASSIGN_BIT_AND); } |
| 299 <Normal> "<<=" { PUSH_T(ASSIGN_SHL); } | 313 <Normal> "<<=" { PUSH_TOKEN(ASSIGN_SHL); } |
| 300 <Normal> ">>=" { PUSH_T(ASSIGN_SAR); } | 314 <Normal> ">>=" { PUSH_TOKEN(ASSIGN_SAR); } |
| 301 <Normal> ">>>=" { PUSH_T(ASSIGN_SHR); } | 315 <Normal> ">>>=" { PUSH_TOKEN(ASSIGN_SHR); } |
| 302 <Normal> "+=" { PUSH_T(ASSIGN_ADD); } | 316 <Normal> "+=" { PUSH_TOKEN(ASSIGN_ADD); } |
| 303 <Normal> "-=" { PUSH_T(ASSIGN_SUB); } | 317 <Normal> "-=" { PUSH_TOKEN(ASSIGN_SUB); } |
| 304 <Normal> "*=" { PUSH_T(ASSIGN_MUL); } | 318 <Normal> "*=" { PUSH_TOKEN(ASSIGN_MUL); } |
| 305 <Normal> "/=" { PUSH_T(ASSIGN_DIV); } | 319 <Normal> "/=" { PUSH_TOKEN(ASSIGN_DIV); } |
| 306 <Normal> "%=" { PUSH_T(ASSIGN_MOD); } | 320 <Normal> "%=" { PUSH_TOKEN(ASSIGN_MOD); } |
| 307 | 321 |
| 308 <Normal> "," { PUSH_T(COMMA); } | 322 <Normal> "," { PUSH_TOKEN(COMMA); } |
| 309 <Normal> "||" { PUSH_T(OR); } | 323 <Normal> "||" { PUSH_TOKEN(OR); } |
| 310 <Normal> "&&" { PUSH_T(AND); } | 324 <Normal> "&&" { PUSH_TOKEN(AND); } |
| 311 <Normal> "|" { PUSH_T(BIT_OR); } | 325 <Normal> "|" { PUSH_TOKEN(BIT_OR); } |
| 312 <Normal> "^" { PUSH_T(BIT_XOR); } | 326 <Normal> "^" { PUSH_TOKEN(BIT_XOR); } |
| 313 <Normal> "&" { PUSH_T(BIT_AND); } | 327 <Normal> "&" { PUSH_TOKEN(BIT_AND); } |
| 314 <Normal> "<<" { PUSH_T(SHL); } | 328 <Normal> "<<" { PUSH_TOKEN(SHL); } |
| 315 <Normal> ">>" { PUSH_T(SAR); } | 329 <Normal> ">>" { PUSH_TOKEN(SAR); } |
| 316 <Normal> "+" { PUSH_T(ADD); } | 330 <Normal> "+" { PUSH_TOKEN(ADD); } |
| 317 <Normal> "-" { PUSH_T(SUB); } | 331 <Normal> "-" { PUSH_TOKEN(SUB); } |
| 318 <Normal> "*" { PUSH_T(MUL); } | 332 <Normal> "*" { PUSH_TOKEN(MUL); } |
| 319 <Normal> "/" { PUSH_T(DIV); } | 333 <Normal> "/" { PUSH_TOKEN(DIV); } |
| 320 <Normal> "%" { PUSH_T(MOD); } | 334 <Normal> "%" { PUSH_TOKEN(MOD); } |
| 321 | 335 |
| 322 <Normal> "===" { PUSH_T(EQ_STRICT); } | 336 <Normal> "===" { PUSH_TOKEN(EQ_STRICT); } |
| 323 <Normal> "==" { PUSH_T(EQ); } | 337 <Normal> "==" { PUSH_TOKEN(EQ); } |
| 324 <Normal> "!==" { PUSH_T(NE_STRICT); } | 338 <Normal> "!==" { PUSH_TOKEN(NE_STRICT); } |
| 325 <Normal> "!=" { PUSH_T(NE); } | 339 <Normal> "!=" { PUSH_TOKEN(NE); } |
| 326 <Normal> "<=" { PUSH_T(LTE); } | 340 <Normal> "<=" { PUSH_TOKEN(LTE); } |
| 327 <Normal> ">=" { PUSH_T(GTE); } | 341 <Normal> ">=" { PUSH_TOKEN(GTE); } |
| 328 <Normal> "<" { PUSH_T(LT); } | 342 <Normal> "<" { PUSH_TOKEN(LT); } |
| 329 <Normal> ">" { PUSH_T(GT); } | 343 <Normal> ">" { PUSH_TOKEN(GT); } |
| 330 | 344 |
| 331 <Normal> "=" { PUSH_T(ASSIGN); } | 345 <Normal> "=" { PUSH_TOKEN(ASSIGN); } |
| 332 | 346 |
| 333 <Normal> "!" { PUSH_T(NOT); } | 347 <Normal> "!" { PUSH_TOKEN(NOT); } |
| 334 <Normal> "~" { PUSH_T(BIT_NOT); } | 348 <Normal> "~" { PUSH_TOKEN(BIT_NOT); } |
| 335 | 349 |
| 336 <Normal> line_terminator+ { PUSH_LINE_TERMINATOR(); } | 350 <Normal> line_terminator+ { PUSH_LINE_TERMINATOR(); } |
| 337 <Normal> whitespace { SKIP();} | 351 <Normal> whitespace { SKIP();} |
| 338 | 352 |
| 339 <Normal> "//" :=> SingleLineComment | 353 <Normal> "//" :=> SingleLineComment |
| 340 <Normal> "/*" :=> MultiLineComment | 354 <Normal> "/*" :=> MultiLineComment |
| 341 <Normal> "<!--" :=> HtmlComment | 355 <Normal> "<!--" :=> HtmlComment |
| 342 | 356 |
| 343 <Normal> ["] :=> DoubleQuoteString | 357 <Normal> ["] :=> DoubleQuoteString |
| 344 <Normal> ['] :=> SingleQuoteString | 358 <Normal> ['] :=> SingleQuoteString |
| 345 | 359 |
| 346 <Normal> identifier_start :=> Identifier | 360 <Normal> identifier_start :=> Identifier |
| 347 <Normal> number_start :=> Number | 361 <Normal> number_start :=> Number |
| 348 | 362 |
| 349 <Normal> eof { PUSH_EOS(); return 1; } | 363 <Normal> eof { PUSH_EOS(); return 1; } |
| 350 <Normal> any { TERMINATE_ILLEGAL(); } | 364 <Normal> any { TERMINATE_ILLEGAL(); } |
| 351 | 365 |
| 352 <DoubleQuoteString> "\\\"" {} | 366 <DoubleQuoteString> "\\\"" { goto yy0; } |
| 353 <DoubleQuoteString> ["] { PUSH_STRING();} | 367 <DoubleQuoteString> '"' { PUSH_STRING();} |
| 354 <DoubleQuoteString> any {} | 368 <DoubleQuoteString> any { goto yy0; } |
| 355 | 369 |
| 356 <SingleQuoteString> "\\'" {} | 370 <SingleQuoteString> "\\'" { goto yy0; } |
| 357 <SingleQuoteString> "'" { PUSH_STRING();} | 371 <SingleQuoteString> "'" { PUSH_STRING();} |
| 358 <SingleQuoteString> any {} | 372 <SingleQuoteString> any { goto yy0; } |
| 359 | 373 |
| 360 <Identifier> identifier_char+ {} | 374 <Identifier> identifier_char+ { goto yy0; } |
| 361 <Identifier> any { PUSH_IDENTIFIER(); } | 375 <Identifier> any { PUSH_IDENTIFIER(); } |
| 362 | 376 |
| 363 <SingleLineComment> line_terminator | 377 <SingleLineComment> line_terminator { PUSH_LINE_TERMINATOR();} |
| 364 { PUSH_LINE_TERMINATOR();} | 378 <SingleLineComment> eof { PUSH_LINE_TERMINATOR();} |
| 365 | 379 <SingleLineComment> any :=> SingleLineComment |
| 366 <SingleLineComment> any+ {} | |
| 367 | 380 |
| 368 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();} | 381 <MultiLineComment> [*][//] { PUSH_LINE_TERMINATOR();} |
| 369 <MultiLineComment> eof { TERMINATE_ILLEGAL(); } | 382 <MultiLineComment> eof { TERMINATE_ILLEGAL(); } |
| 370 <MultiLineComment> any+ {} | 383 <MultiLineComment> any :=> MultiLineComment |
| 371 | 384 |
| 372 <HtmlComment> any+ {} | |
| 373 <HtmlComment> eof { TERMINATE_ILLEGAL(); } | 385 <HtmlComment> eof { TERMINATE_ILLEGAL(); } |
| 374 <HtmlComment> "-->" { } | 386 <HtmlComment> "-->" { PUSH_LINE_TERMINATOR();} |
| 387 <HtmlComment> any :=> HtmlComment |
| 375 | 388 |
| 376 <Number> number_char+ { } | 389 <Number> number_char+ { goto yy0; } |
| 377 <Number> any { PUSH_NUMBER(); } | 390 <Number> any { PUSH_NUMBER(); } |
| 378 | 391 |
| 379 */ | 392 */ |
| 380 | 393 |
| 381 fill: | 394 fill: |
| 382 ssize_t unfinishedSize = cursor-start; | 395 ssize_t unfinishedSize = cursor-start; |
| 383 printf( | 396 printf( |
| 384 "scanner needs a refill. Exiting for now with:\n" | 397 "scanner needs a refill. Exiting for now with:\n" |
| 385 " saved fill state = %d\n" | 398 " saved fill state = %d\n" |
| 386 " unfinished token size = %ld\n", | 399 " unfinished token size = %ld\n", |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 return 1; | 464 return 1; |
| 452 } | 465 } |
| 453 if(n<batchSize) break; | 466 if(n<batchSize) break; |
| 454 } | 467 } |
| 455 scanner.push(0, -1); | 468 scanner.push(0, -1); |
| 456 close(input); | 469 close(input); |
| 457 | 470 |
| 458 // Done | 471 // Done |
| 459 return 0; | 472 return 0; |
| 460 } | 473 } |
| OLD | NEW |