int main(int argc, char **argv) { opt_nopeep = FALSE; uctran_off = 0; optimize =1; exceptions=1; // printf("c64 starting...\r\n"); while(--argc) { if( **++argv == '-') options(*argv); else { if (PreProcessFile(*argv) == -1) break; if( openfiles(*argv)) { lineno = 0; initsym(); compiler.compile(); // compile(); summary(); MBlk::ReleaseAll(); // ReleaseGlobalMemory(); closefiles(); } } dfs.printf("Next on command line (%d).\n", argc); } //getchar(); dfs.printf("Exiting\n"); dfs.close(); exit(0); return (0); }
int Compiler::main2(int argc, char **argv) { uctran_off = 0; optimize =1; exceptions=1; dfs.printf("c64 starting...\r\n"); while(--argc) { if( **++argv == '-') options(*argv); else { if (PreprocessFile(*argv) == -1) break; if( openfiles(*argv)) { lineno = 0; initsym(); lstackptr = 0; lastst = 0; NextToken(); compile(); summary(); // MBlk::ReleaseAll(); // ReleaseGlobalMemory(); CloseFiles(); } } } //getchar(); return 0; }
int main(int argc, char **argv) { uctran_off = 0; optimize =1; exceptions=1; // printf("c64 starting...\r\n"); while(--argc) { if( **++argv == '-') options(*argv); else { if (PreProcessFile(*argv) == -1) break; if( openfiles(*argv)) { lineno = 0; initsym(); memset(gsyms,0,sizeof(gsyms)); memset(&defsyms,0,sizeof(defsyms)); memset(&tagtable,0,sizeof(tagtable)); getch(); lstackptr = 0; lastst = 0; NextToken(); compile(); summary(); ReleaseGlobalMemory(); closefiles(); } } } //getchar(); return 0; }
int main(int argc, char **argv) { int ret; const char *file; const char *name = NULL; int optidx = 0; setprogname(argv[0]); if(getarg(args, num_args, argc, argv, &optidx)) usage(1); if(help_flag) usage(0); if(version_flag) { print_version(NULL); exit(0); } if (argc == optidx) { file = "stdin"; name = "stdin"; yyin = stdin; } else { file = argv[optidx]; yyin = fopen (file, "r"); if (yyin == NULL) err (1, "open %s", file); if (argc == optidx + 1) { char *p; name = estrdup(file); p = strrchr(name, '.'); if (p) *p = '\0'; } else name = argv[optidx + 1]; } init_generate (file, name); initsym (); ret = yyparse (); if(ret != 0 || error_flag != 0) exit(1); close_generate (); if (argc != optidx) fclose(yyin); return 0; }
int main(int argc, char **argv) { int ret; const char *file; const char *name = NULL; int optidx = 0; char **arg = NULL; size_t len = 0, i; setprogname(argv[0]); if(getarg(args, num_args, argc, argv, &optidx)) usage(1); if(help_flag) usage(0); if(version_flag) { print_version(NULL); exit(0); } if (argc == optidx) { file = "stdin"; name = "stdin"; yyin = stdin; } else { file = argv[optidx]; yyin = fopen (file, "r"); if (yyin == NULL) err (1, "open %s", file); if (argc == optidx + 1) { char *p; name = estrdup(file); p = strrchr(name, '.'); if (p) *p = '\0'; } else name = argv[optidx + 1]; } /* * Parse extra options file */ if (option_file) { char buf[1024]; FILE *opt; opt = fopen(option_file, "r"); if (opt == NULL) { perror("open"); exit(1); } arg = calloc(2, sizeof(arg[0])); if (arg == NULL) { perror("calloc"); exit(1); } arg[0] = option_file; arg[1] = NULL; len = 1; while (fgets(buf, sizeof(buf), opt) != NULL) { buf[strcspn(buf, "\n\r")] = '\0'; arg = realloc(arg, (len + 2) * sizeof(arg[0])); if (arg == NULL) { perror("malloc"); exit(1); } arg[len] = strdup(buf); if (arg[len] == NULL) { perror("strdup"); exit(1); } arg[len + 1] = NULL; len++; } fclose(opt); optidx = 0; if(getarg(args, num_args, len, arg, &optidx)) usage(1); if (len != optidx) { fprintf(stderr, "extra args"); exit(1); } } init_generate (file, name); if (one_code_file) generate_header_of_codefile(name); initsym (); ret = yyparse (); if(ret != 0 || error_flag != 0) exit(1); close_generate (); if (argc != optidx) fclose(yyin); if (one_code_file) close_codefile(); if (arg) { for (i = 1; i < len; i++) free(arg[i]); free(arg); } return 0; }
int syntaxan (int token,symbol * sym) { static unsigned char num_channel; static unsigned char channels[12]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; static symbol ptr; switch (status) { case STATUS_INIT: /* Initial status */ recst = STATUS_INIT; /*Save actual state for error handling */ switch (token) { case VAR: /* Begin variable declaration */ status = STATUS_BEGIN_VAR_DECL; return 0; case CHANNEL: /* Begin channel declaration */ status = STATUS_BEGIN_CHN_DECL; return 0; case IDEN: /* Begin assign statement */ status = STATUS_BEGIN_GLOBAL_ASGN; /* TODO: Join to local assign */ if ((*sym = searchsym(lexcad)) == NULL) rerror(ESYNTAX, EIDEN_NAME, 0); return 0; case LN: /* Empty sentence */ return 1; default: rerror(ESYNTAX, E_INI, 0); } /* Variable declaration states */ case STATUS_BEGIN_VAR_DECL: /* VAR ; variable declaration */ switch (token) { case IDEN: /* Name of the variable */ status = STATUS_NAME_VAR_DECL; *sym = newsymbol(lexcad); return 0; default: rerror(ESYNTAX, E_VAR_DECL, 0); } case STATUS_NAME_VAR_DECL: /* VAR IDEN ; variable declaration */ switch (token) { case LN: /* end of declaration */ status = STATUS_INIT; insvar(*sym); return 1; case COMA: /* multiple declaration */ status = STATUS_BEGIN_VAR_DECL; insvar(*sym); return 0; default: rerror(ESYNTAX, E_VAR_DECL, 0); } /* Channel declaration states */ case STATUS_BEGIN_CHN_DECL: /* CHANNEL ; channel declaration */ switch (token) { case NUMBER: /* Number of the channel */ status = STATUS_END_OF_CHANNEL; num_channel = atoi(lexcad) - 1; if(num_channel >= 12) rerror(ESYNTAX, E_BAD_CH, 0); else { ssymval(syms1, num_channel); *sym = syms1; } if(channels[num_channel]) rerror(ESYNTAX, E_DECL_CH, 0); channels[num_channel]=1; return 0; case IDEN: /* Variable with the name of the channel */ status = STATUS_END_OF_CHANNEL; if ((*sym = searchsym(lexcad)) == NULL) rerror(ESYNTAX, EIDEN_NAME, 0); else if ((num_channel = gsymval(*sym)) >= 12) rerror(ESYNTAX, E_BAD_CH, 0); if (channels[num_channel]) rerror(ESYNTAX, E_DECL_CH, 0); channels[num_channel] = 1; return 0; default: rerror(ESYNTAX, E_CHANNEL, 0); } /* end of channel declaration */ case STATUS_END_OF_CHANNEL: /* CHANNEL IDEN | NUMBER ; end of channl dcl*/ switch (token) { case LN: /* finish channel dcl */ status = STATUS_BEGIN_CHN_BODY; inscode2(CHANNEL, gsymval(*sym)); return 1; default: rerror(ESYNTAX, E_CHANNEL, 0); } /* Begin channel body */ case STATUS_BEGIN_CHN_BODY: /* CHANNEL IDEN | NUMBER LN ; chl body*/ recst = STATUS_BEGIN_CHN_BODY; /*Save state for error handling*/ switch (token) { case LN: return 1; case ENDC: /* end of channel statement */ status = STATUS_BEGIN_ENDC; initsym(syms1, token, token); *sym = syms1; return 0; case PLAY: status = 11; /* play statement */ initexpr(); initsym(syms1, token, token); *sym = syms1; return 0; case SIL: /* silence statement */ case DECOC: /* dec octave statement */ case INCOC: /* inc octave statement */ case ENDL: /* end of loop statement */ case DECV: /* dec volume */ case INCV: /* inc volume */ status = STATUS_END_OF_1CMD; initsym(syms1, token, token); *sym = syms1; return 0; case OCT: /* octave statement */ case VOL: /* volume statement */ case BAT: /* battery statement */ case INST: /* instrument statement */ case LOOP: /* loop statement */ case AMPL: case VIB: /* vibrato statement */ case TIMES: /* time short format statement */ case TIMEL: /* time long format statement */ case DIVSUS: case BATL: /* battery long format statement */ case INSTL: /* instrument long format statement */ case FREC: /* set frequency statement */ status = STATUS_BEGIN_EXP_2CMD; initexpr(); initsym(syms1, token, token); *sym = syms1; return 0; case TIMEP: status = 39; initexpr(); initsym(syms1, token, token); initsym(syms2, NUMBER, 0); ssymsig(syms2, syms1); *sym = syms2; return 0; case REGFM: /* write to fm register statement */ status = 8; initexpr(); initsym(syms1, token, token); *sym = syms1; return 0; case PAR: /* parameter statement */ status = 9; initsym(syms1, token, token); *sym = syms1; return 0; case IDEN: /* Begin a assign statement */ status = 10; if ((*sym = searchsym(lexcad)) == NULL) rerror(ESYNTAX, EIDEN_NAME, 0); return 0; default: rerror(ESYNTAX, E_UNK_COMM, 0); } /* End of 1 word statement */ case STATUS_END_OF_1CMD: switch (token) { case LN: status = STATUS_BEGIN_CHN_BODY; inscodeI(*sym, NULL, num_channel); return 1; default: rerror(ESYNTAX, E_BAD_COMM, 0); } case 8: switch (token) { case NUMBER: status = 21; initsym(syms3, NUMBER, 0); ssymsig(syms3,*sym); *sym = syms3; pushexp(NUMBER, atoi(lexcad)); return 0; case IDEN: status = 21; if((ptr = searchsym(lexcad)) == NULL) rerror(ESYNTAX, EIDEN_NAME, 0); initsym(syms3, NUMBER, 0); ssymsig(syms3,*sym); *sym = syms3; pushexp(NUMBER, gsymval(ptr)); return 0; case PARI: status = 22; ssymsig(syms3,*sym); *sym = syms3; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } case 9: switch (token) { case ENVLOFF: case ENVLON: case SUSON: case HFNUM: case LFNUM: case NOISE: case TONE: status = STATUS_END_OF_1CMD; initsym(syms2, token, token); ssymsig(syms2,*sym); *sym = syms2; return 0; case DECO: status = STATUS_BEGIN_EXP_2CMD; initexpr(); initsym(syms3, token, token); ssymsig(syms3,*sym); *sym = syms3; return 0; case TAMP: status = STATUS_BEGIN_EXP_2CMD; initexpr(); initsym(syms3, token, token); ssymsig(syms3,*sym); *sym = syms3; return 0; case RITMON: status = STATUS_END_OF_1CMD; initsym(syms2, token, token); ssymsig(syms2,*sym); *sym = syms2; return 0; case MELON: status = STATUS_END_OF_1CMD; initsym(syms2, token, token); ssymsig(syms2,*sym); *sym = syms2; return 0; default: rerror(ESYNTAX, E_PAR, 0); } case 10: switch (token) { case EQ: status = STATUS_BEGIN_EXP_2CMD; initexpr(); initsym(syms3, EQ, EQ); ssymsig(syms3, *sym); *sym = syms3; return 0; default: rerror(ESYNTAX, E_ASIG, 0); } case 11: switch(token) { case NUMBER: status = STATUS_PLAY_EXPRESION; initsym(syms2, NUMBER, 0); ssymsig(syms2,*sym); *sym = syms2; pushexp(NUMBER, atoi(lexcad)); return 0; case IDEN: status = STATUS_PLAY_EXPRESION; if((ptr = searchsym(lexcad)) == NULL) rerror(ESYNTAX, EIDEN_NAME, 0); initsym(syms2, NUMBER, 0); ssymsig(syms2,*sym); *sym = syms2; pushexp(NUMBER, gsymval(ptr)); return 0; case PARI: status = STATUS_PLAY_EXPRESION; ssymsig(syms2,*sym); *sym = syms2; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } /* Begin end of channel statement */ case STATUS_BEGIN_ENDC: /* ENDC ; endc command */ switch(token) { case LN: status = 13; inscode(gsymval(*sym)); execute(); return 1; default: rerror(ESYNTAX, E_BAD_COMM, 0); } case 13: recst = 13; switch(token) { case WRITE: status = 38; return 0; case CHANNEL: status = STATUS_BEGIN_CHN_DECL; return 0; case LN: return 1; default: rerror(ESYNTAX, E_INI, 0); } case STATUS_BEGIN_GLOBAL_ASGN: switch(token) { case EQ: status = 15; initexpr(); return 0; default: rerror(ESYNTAX, E_ASIG, 0); } case 15: switch(token) { case NUMBER: status = 26; {pushexp(NUMBER, atoi(lexcad));}; return 0; case IDEN: status = 26; (ptr = searchsym(lexcad))?pushexp(NUMBER, gsymval(ptr)):rerror(ESYNTAX, EIDEN_NAME, 0); return 0; case PARI: status = 27; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } /*******************************************************************/ case STATUS_BEGIN_EXP_2CMD: switch (token) { case PARI: status = STATUS_EXP2_OPERAND; ssymsig(syms2,*sym); *sym = syms2; pushexp(token, 0); return 0; case NUMBER: status = STATUS_EXP2_OPERAND; initsym(syms2, NUMBER, 0); ssymsig(syms2,*sym); *sym = syms2; pushexp(NUMBER, atoi(lexcad)); return 0; case IDEN: status = STATUS_EXP2_OPERAND; if(!(ptr = searchsym(lexcad))) rerror(ESYNTAX, EIDEN_NAME, 0); initsym(syms2, NUMBER, 0); ssymsig(syms2,*sym); *sym = syms2; pushexp(NUMBER, gsymval(ptr)); return 0; default: rerror(ESYNTAX, E_EXP, 0); } case STATUS_EXP2_OPERAND: switch(token) { case NUMBER: status = STATUS_EXP2_OPERAND; pushexp(NUMBER, atoi(lexcad)); return 0; case IDEN: status = STATUS_EXP2_OPERAND; if ((ptr = searchsym(lexcad)) == NULL) rerror(ESYNTAX, EIDEN_NAME, 0); pushexp(NUMBER, gsymval(ptr)); return 0; case ADD: case SUB: case MUL: case DIV: case PARD: case PARI: /* left parenthesis */ status = STATUS_EXP2_OPERAND; pushexp(token, 0); return 0; case LN: status = recst; pushexp(token, 0); ssymval(*sym, evalexpr()); inscodeI(*sym, NULL, num_channel); return 1; default: rerror(ESYNTAX, E_EXP, 0); } /***********************************************/ /* initial assign expression*/ case 26: switch(token) { case ADD: status = 15; pushexp(token, 0); return 0; case SUB: status = 15; pushexp(token, 0); return 0; case MUL: status = 15; pushexp(token, 0); return 0; case DIV: status = 15; pushexp(token, 0); return 0; case LN: status = STATUS_INIT;{pushexp(token, 0);ssymval(*sym, evalexpr());} return 1; default: rerror(ESYNTAX, E_EXP, 0); } case 27: switch(token) { case NUMBER: status = 28;{pushexp(NUMBER, atoi(lexcad));}return 0; case IDEN: status = 28;{symbol ptr;(ptr = searchsym(lexcad))?pushexp(NUMBER, gsymval(ptr)):rerror(ESYNTAX, EIDEN_NAME, 0);}return 0; case PARI: status = 27; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } case 28: switch(token) { case PARD: status = 28; pushexp(token, 0); return 0; case ADD: status = 27; pushexp(token, 0); return 0; case SUB: status = 27; pushexp(token, 0); return 0; case MUL: status = 27; pushexp(token, 0); return 0; case DIV: status = 27; pushexp(token, 0); return 0; case LN: status = STATUS_INIT;{pushexp(token, 0);ssymval(*sym, evalexpr());}return 1; default: rerror(ESYNTAX, E_EXP, 0); } case 30: /*Expresion de play*/ case STATUS_PLAY_EXPRESION: switch(token) { case ADD: case SUB: case MUL: case DIV: status = 32; pushexp(token, 0); return 0; case SOS: status = STATUS_PLAY_SOST; return 0; case BEMOL: status = STATUS_PLAY_BEMOL; return 0; case COMA: case LN: pushexp(LN, 0); ssymval(*sym, evalexpr()); inscodeI(*sym, NULL, num_channel); if (token == COMA) { status = 32; initexpr(); return 0; } else { status = STATUS_BEGIN_CHN_BODY; return 1; } default: rerror(ESYNTAX, E_EXP, 0); } case 32: switch(token) { case NUMBER: status = 33;{pushexp(NUMBER, atoi(lexcad));}return 0; case IDEN: status = 33;{symbol ptr;(ptr = searchsym(lexcad))?pushexp(NUMBER, gsymval(ptr)):rerror(ESYNTAX, EIDEN_NAME, 0);}return 0; case PARI: status = 32; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } case 33: switch(token) { case PARD: status = 33; pushexp(token, 0); return 0; case ADD: status = 34; pushexp(token, 0); return 0; case SUB: status = 34; pushexp(token, 0); return 0; case MUL: status = 34; pushexp(token, 0); return 0; case DIV: status = 34; pushexp(token, 0); return 0; case SOS: status = STATUS_PLAY_SOST;{pushexp(token, 0);ssymval(*sym, evalexpr());}return 0; case BEMOL: status = STATUS_PLAY_BEMOL;{pushexp(token, 0);ssymval(*sym, evalexpr());}return 0; case COMA: status = 32;{pushexp(LN, 0);ssymval(*sym, evalexpr());inscodeI(*sym, NULL, num_channel);initexpr();} return 0; case LN: status = STATUS_BEGIN_CHN_BODY;{pushexp(token, 0);ssymval(*sym, evalexpr());inscodeI(*sym, NULL, num_channel);}return 1; default: rerror(ESYNTAX, E_EXP, 0); } case 34: switch(token) { case NUMBER: status = STATUS_PLAY_EXPRESION;{pushexp(NUMBER, atoi(lexcad));}return 0; case IDEN: status = STATUS_PLAY_EXPRESION;{symbol ptr;(ptr = searchsym(lexcad))?pushexp(NUMBER, gsymval(ptr)):rerror(ESYNTAX, EIDEN_NAME, 0);}return 0; case PARI: status = 32; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } case STATUS_PLAY_BEMOL: switch(token) { case BEMOL: pushexp(SUB, 0); pushexp(NUMBER, 3); return 0; case COMA: case LN: pushexp(LN, 0); ssymval(*sym, evalexpr() - 3); inscodeI(*sym, NULL, num_channel); if (token == LN) { status = STATUS_BEGIN_CHN_BODY; return 1; } else { status = 32; initexpr(); return 0; } default: rerror(ESYNTAX, E_BEMOL, 0); } case STATUS_PLAY_SOST: switch(token) { case SOS: pushexp(ADD, 0); pushexp(NUMBER, 3); return 0; case COMA: case LN: pushexp(LN, 0); ssymval(*sym, evalexpr() + 3); inscodeI(*sym, NULL, num_channel); if (token == LN) { status = STATUS_BEGIN_CHN_BODY; return 1; } else { status = 32; initexpr(); return 0; } default: rerror(ESYNTAX, E_SOS, 0); } case 38: switch(token) { case LN: status = 37;{errorg?rerror(EERROR, 0, 0):writesong();}return 2; /*Fin de entrada*/ default: rerror(ESYNTAX, E_BAD_COMM, 0); } case 39: switch (token) { case NUMBER: status = 40;{pushexp(NUMBER, atoi(lexcad));}return 0; case IDEN: status = 40;{symbol ptr;(ptr = searchsym(lexcad))?pushexp(NUMBER, gsymval(ptr)):rerror(ESYNTAX, EIDEN_NAME, 0);}return 0; case PARI: status = 41; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } case 40: switch(token) { case ADD: status = 39; pushexp(token, 0); return 0; case SUB: status = 39; pushexp(token, 0); return 0; case MUL: status = 39; pushexp(token, 0); return 0; case DIV: status = 39; pushexp(token, 0); return 0; case POINT: status = 43;{pointp = point=32;}; return 0; case LN: status = STATUS_BEGIN_CHN_BODY; { float time; pushexp(token, 0); time = evalexpr(); time/=64.0; time*=(240.0*((float)(gsymval(hz))))/((float)(gsymval(tempo))); if((time-((float)((unsigned char)time))) > 0.5) time=((float)((unsigned char)time))+1.0; else time=(float)((unsigned char)time); ssymval(*sym,(unsigned char)time); inscodeI(*sym, NULL, num_channel); }return 1; default: rerror(ESYNTAX, E_EXP, 0); } case 41: switch(token) { case NUMBER: status = 42;{pushexp(NUMBER, atoi(lexcad));}return 0; case IDEN: status = 42;{symbol ptr;(ptr = searchsym(lexcad))?pushexp(NUMBER, gsymval(ptr)):rerror(ESYNTAX, EIDEN_NAME, 0);}return 0; case PARI: status = 41; pushexp(token, 0); return 0; default: rerror(ESYNTAX, E_EXP, 0); } case 42: switch(token) { case PARD: status = 42; pushexp(token, 0); return 0; case ADD: case SUB: case MUL: case DIV: status = 41; pushexp(token, 0); return 0; case POINT: status = 43;{pointp = point=32;} return 0; case LN: status = STATUS_BEGIN_CHN_BODY; { float time, timei; pushexp(token, 0); time = evalexpr(); time/=64.0; time*=(240.0*((float)(gsymval(hz))))/((float)(gsymval(tempo))); time = fabs(time); timei = floor(time); if(time-timei) time = timei+1.0; else time = timei; ssymval(*sym,(unsigned char)time); inscodeI(*sym, NULL, num_channel); }return 1; default: rerror(ESYNTAX, E_EXP, 0); } case 43: switch(token) { case POINT: pointp >>= 1; point += pointp; return 0; case LN: status = STATUS_BEGIN_CHN_BODY; { float time, timei; pushexp(token, 0); time = evalexpr(); time/=64; time*=(240.0*((float)(gsymval(hz))))/((float)(gsymval(tempo))); time = fabs(time); time+=time*(((float)point)/64.0); timei = floor(time); if(time-timei) time = timei+1.0; else time = timei; ssymval(*sym,(unsigned char)time); inscodeI(*sym, NULL, num_channel); }return 1; } default: rerror(ESYNTAX, E_POINT, 0); } }