int main(void) { struct t_scanner scanner; struct t_token *token; int i = 0; if (scanner_init(&scanner, stdin)) { fprintf(stderr, "Failed to initialize scanner\n"); return 1; } do { if ((token = scanner_next(&scanner)) == NULL) { fprintf(stderr, "An error occurred during parsing: errno: %d\n", scanner.error); break; } printf("%s\n", token_format(token)); i++; } while (token->type != TT_EOF && i < 30); scanner_close(&scanner); printf("Done.\n"); return 0; }
static void freeze_main(struct value *args, struct value *result) { struct process *p; struct scanner *sc; struct reporter *r; struct value term; struct value *termfile, *binfile; struct value termfile_sym, binfile_sym; value_symbol_new(&termfile_sym, "termfile", 8); value_symbol_new(&binfile_sym, "binfile", 7); termfile = value_dict_fetch(args, &termfile_sym); binfile = value_dict_fetch(args, &binfile_sym); r = reporter_new("Freezing", NULL, 1); /* * Parse. */ sc = scanner_new(r); if (!scanner_open(sc, value_symbol_get_token(termfile))) { value_integer_set(result, 1); return; } if (!value_discern(&term, sc)) { report(r, REPORT_ERROR, "Could not parse input term"); } /* * Write out. */ p = file_open(value_symbol_get_token(binfile), "w"); if (!value_save(p, &term)) { report(r, REPORT_ERROR, "Could not write term to '%s'", binfile); } stream_close(NULL, p); /* * Finish up. */ scanner_close(sc); scanner_free(sc); value_integer_set(result, reporter_has_errors(r) ? 1 : 0); reporter_free(r); }
char nextchar() { int c = 0; while (LEX_in) { c = Getc(LEX_in); if (c == EOF) { scanner_close(); } else { break; } } if (!LEX_in) return 0; if (yylen >= YYBSIZE) { Printf(stderr,"** FATAL ERROR. Buffer overflow in scanner.cxx.\nReport this to [email protected].\n"); exit (EXIT_FAILURE); } yytext[yylen] = c; yylen++; if (c == '\n') { cparse_line++; } return(c); }