void parsetypeexpr(char s[]) { setchecktypevariables(NOCHECK); openinput(s); checkmemlarge(); tokenoffside = 0; gettoken(); parsetype(TYPEEXPR); closeinput(); }
void parse() { char c, a = 'a'; bool preflag = 0; signed cparam = 0, pf = 1, minus = 1, pre = 0, con = 0; double ret; while (true) { if (scanf("%c", &c) == EOF) c = EOF; //printf("%c\: ", c); switch (parsetype(c)) { case 1: { cparam = cparam * 10 + (c - 48); //printf("number \> cparam = %d\n", cparam); } break; case 2: { preflag = true; a = c; //printf("object \> preflag = %d\n", preflag); } break; case 3: case 4: case 5: { //printf("operator \> pf = %d, minus = %d, pre = %d, con = %d, cparam = %d\n", pf, minus, pre, con, cparam); if (preflag) pre += cparam * pf * minus; else con += cparam * pf * minus; preflag = false; cparam = 0; minus = 1; //printf(" pf = %d, minus = %d, pre = %d, con = %d, cparam = %d\n", pf, minus, pre, con, cparam); if (c == '-') minus = -1; if (c == '=') pf = -1; } break; } if (c == EOF) { break; } } ret = double(-con) / double(pre); printf("%c=%.3f", a, ret); }
/** * open_existing - open an existing file * @path : path handle * @dent : pointer to cbmdirent struct with name of the file * @type : type of the file (not checked) * @buf : buffer to be used * @appendflag: Flags if the file should be opened for appending * * This function searches the file name in an M2I file and opens it * either in read or append mode according to appendflag by calling * the appropiate fat_* functions. */ static void open_existing(path_t *path, cbmdirent_t *dent, uint8_t type, buffer_t *buf, uint8_t appendflag) { if (load_entry(path->part, dent->pvt.m2i.offset)) { set_error(ERROR_FILE_NOT_FOUND); return; } if (parsetype()) { set_error(ERROR_FILE_NOT_FOUND); return; } ustrcpy(dent->pvt.fat.realname, ops_scratch + M2I_FATNAME_OFFSET); if (appendflag) fat_open_write(path, dent, type, buf, 1); else fat_open_read(path, dent, buf); }
int main(int argc,char **argv) { uint16 u16; if (!*argv) usage(); if (!*++argv) usage(); if (!parsetype(*argv,type)) usage(); if (!*++argv) usage(); if (!dns_domain_fromdot(&q,*argv,str_len(*argv))) oops(); if (*++argv) { if (!ip4_scan(*argv,ip)) usage(); } if (!stralloc_copys(&out,"")) oops(); /* uint16_unpack_big(type,&u16); if (!stralloc_catulong0(&out,u16,0)) oops(); if (!stralloc_cats(&out," ")) oops(); if (!dns_domain_todot_cat(&out,q)) oops(); if (!stralloc_cats(&out,":\n")) oops(); */ if (!response_query(q,type,DNS_C_IN)) oops(); response[3] &= ~128; response[2] &= ~1; response[2] |= 4; case_lowerb(q,dns_domain_length(q)); if (byte_equal(type,2,DNS_T_AXFR)) { response[3] &= ~15; response[3] |= 4; } else if (!respond(q,type,ip)) goto DONE; if (!printpacket_cat(&out,response,response_len)) oops(); DONE: buffer_putflush(buffer_1,out.s,out.len); _exit(0); }
static void parsetypesynonym(void) { Cell *head = pop(); setchecktypevariables(COLLECT); push(template_match); for(; head->tag==APPLY; head=head->left) { if(head->right->tag != UNDEFINED && head->right->tag != FUNC) parseerror(9); push(maketypevariable(getfunction(head->right->value)->name)); make(STRUCT); } if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(10); makeconstant(FUNC, head->value); make(STRUCT); setchecktypevariables(CHECK); gettoken(); parsetype(TYPEEXPR); makeinverse(TYPESYNONYM); if(!inserttypeexpr(getfunction(head->value)->name, pop())) parseerror(12); setchecktypevariables(NOCHECK); }
int main(int argc,char **argv) { uint16 u16; dns_random_init(seed); if (!*argv) usage(); if (!*++argv) usage(); if (!parsetype(*argv,type)) usage(); if (!*++argv) usage(); if (!dns_domain_fromdot(&q,*argv,str_len(*argv))) oops(); if (!*++argv) usage(); if (!stralloc_copys(&out,*argv)) oops(); if (dns_ip6_qualify(&ip,&fqdn,&out) == -1) oops(); if (ip.len >= 256) ip.len = 256; byte_zero(servers,256); byte_copy(servers,ip.len,ip.s); if (!stralloc_copys(&out,"")) oops(); uint16_unpack_big(type,&u16); if (!stralloc_catulong0(&out,u16,0)) oops(); if (!stralloc_cats(&out," ")) oops(); if (!dns_domain_todot_cat(&out,q)) oops(); if (!stralloc_cats(&out,":\n")) oops(); if (resolve(q,type,servers) == -1) { if (!stralloc_cats(&out,error_str(errno))) oops(); if (!stralloc_cats(&out,"\n")) oops(); } else { if (!printpacket_cat(&out,tx.packet,tx.packetlen)) oops(); } buffer_putflush(buffer_1,out.s,out.len); _exit(0); }
static void parseabstype(void) { Cell *head, *abstype; int globaltokenoffside; gettoken(); parselefthandside(); abstype = pop(); while(abstype->tag == APPLY) abstype = abstype->left; if(abstype->tag != UNDEFINED && abstype->tag != FUNC) parseerror(13); if(!insertabstype(getfunction(abstype->value)->name, abstype)) parseerror(12); if(tokentype != WITH) parseerror(14); globaltokenoffside = tokenoffside; tokenoffside = tokenindent + 1; gettoken(); while(tokentype == IDENTIFIER || tokentype == OPERATOR || tokentype == LPAR) { int temptokenoffside = tokenoffside; parselefthandside(); tokenoffside = tokenindent + 1; if(tokentype != COLONS) parseerror(15); head = pop(); if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(13); gettoken(); parsetype(TYPEEXPR); if(!inserttypeexpr(getfunction(head->value)->name, pop())) parseerror(12); if(!insertabstype(getfunction(head->value)->name, abstype)) parseerror(12); while(tokentype == SEP) gettoken(); tokenoffside = temptokenoffside; if(tokentype == offside) gettoken(); } tokenoffside = globaltokenoffside; if(tokentype == offside) gettoken(); }
int Compiler::parsefile(int ifdef) { int k; while(parser->next(0)) { if (!strcmp(parser->token,"fun")) { if ((!parser->next(0))||(!islabel(parser->token))) { if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found '%s')\n",parser->token); else PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found EOF)\n"); return MTLERR_SN; } if (k=STRPUSH(m,parser->token)) return k; int* s=VALTOPNT(STACKGET(m,0)); if (k=parsefun()) { PRINTF(m)(LOG_COMPILER,"Compiler : error compiling function '%s'\n",STRSTART(s)); return k; } } else if (!strcmp(parser->token,"type")) { if ((!parser->next(0))||(!islabel(parser->token))) { if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of type expected (found '%s')\n",parser->token); else PRINTF(m)(LOG_COMPILER,"Compiler : name of type expected (found EOF)\n"); return MTLERR_SN; } if (k=STRPUSH(m,parser->token)) return k; int* s=VALTOPNT(STACKGET(m,0)); if (k=parsetype()) { PRINTF(m)(LOG_COMPILER,"Compiler : error compiling type '%s'\n",STRSTART(s)); return k; } } else if (!strcmp(parser->token,"var")) { if ((!parser->next(0))||(!islabel(parser->token))) { if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found '%s')\n",parser->token); else PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found EOF)\n"); return MTLERR_SN; } if (k=STRPUSH(m,parser->token)) return k; int* s=VALTOPNT(STACKGET(m,0)); if (k=parsevar()) { PRINTF(m)(LOG_COMPILER,"Compiler : error compiling var '%s'\n",STRSTART(s)); return k; } } else if (!strcmp(parser->token,"const")) { if ((!parser->next(0))||(!islabel(parser->token))) { if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found '%s')\n",parser->token); else PRINTF(m)(LOG_COMPILER,"Compiler : name of reference expected (found EOF)"); return MTLERR_SN; } if (k=STRPUSH(m,parser->token)) return k; int *s=VALTOPNT(STACKGET(m,0)); if (k=parseconst()) { PRINTF(m)(LOG_COMPILER,"Compiler : error compiling const '%s'\n",STRSTART(s)); return k; } } else if (!strcmp(parser->token,"proto")) { if ((!parser->next(0))||(!islabel(parser->token))) { if (parser->token) PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found '%s')\n",parser->token); else PRINTF(m)(LOG_COMPILER,"Compiler : name of function expected (found EOF)\n"); return MTLERR_SN; } if (k=STRPUSH(m,parser->token)) return k; int* s=VALTOPNT(STACKGET(m,0)); if (k=parseproto()) { PRINTF(m)(LOG_COMPILER,"Compiler : error compiling proto '%s'\n",STRSTART(s)); return k; } } else if (!strcmp(parser->token,"ifdef")) { if (k=parseifdef(0)) return k; } else if (!strcmp(parser->token,"ifndef")) { if (k=parseifdef(1)) return k; } else if ((ifdef)&&(!strcmp(parser->token,"}"))) { parser->giveback(); return 0; } else { PRINTF(m)(LOG_COMPILER,"Compiler : unknown token %s\n",parser->token); return MTLERR_SN; } } return 0; }
static int8_t m2i_readdir(dh_t *dh, cbmdirent_t *dent) { uint8_t i; while (1) { i = load_entry(dh->part, dh->dir.m2i); if (i) { if (i == 255) return 1; else return -1; } memset(dent, 0, sizeof(cbmdirent_t)); dent->pvt.m2i.offset = dh->dir.m2i; dh->dir.m2i += M2I_ENTRY_LEN; /* Check file type */ if (parsetype()) continue; dent->opstype = OPSTYPE_M2I; dent->typeflags = ops_scratch[0]; /* Copy CBM file name */ name_repad(' ', 0); memcpy(dent->name, ops_scratch + M2I_CBMNAME_OFFSET, CBM_NAME_LENGTH); /* Get file size */ if (dent->typeflags != TYPE_DEL) { /* Let's annoy some users */ FILINFO finfo; FRESULT res = f_stat(&partition[dh->part].fatfs, ops_scratch + M2I_FATNAME_OFFSET, &finfo); if (res != FR_OK) { if (res == FR_NO_FILE) continue; else { parse_error(res,1); return 1; } } if (finfo.fsize > 16255746) /* File too large -> size 63999 blocks */ dent->blocksize = 63999; else dent->blocksize = (finfo.fsize+253) / 254; dent->remainder = finfo.fsize % 254; } else dent->blocksize = 0; /* Fake Date/Time */ dent->date.year = 82; dent->date.month = 8; dent->date.day = 31; return 0; } }
static void parsedefinition(bool globallevel) { Cell *head; int globaltokenoffside = tokenindent, posCode; bool generic = False; if(tokentype == ABSTYPE && globallevel) { parseabstype(); while(tokentype == SEP) gettoken(); return; } else if(tokentype == GENERIC && globallevel) { generic = True; gettoken(); } parselefthandside(); posCode = getPositionCode(); tokenoffside = tokenindent + 1; if(tokentype == COLONS && globallevel) { head = pop(); if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(13); gettoken(); parsetype(TYPEEXPR); if(!inserttypeexpr(getfunction(head->value)->name, pop())) parseerror(12); getfunction(head->value)->generic = generic; while(tokentype == SEP) gettoken(); } else if(tokentype == DEF && globallevel) { parsestructdef(); while(tokentype == SEP) gettoken(); } else if(tokentype == SYN && globallevel) { parsetypesynonym(); while(tokentype == SEP) gettoken(); } else { head = top(); if(head->tag == APPLY || globallevel) { for(; head->tag==APPLY; head=head->left) checkpattern(head->right); if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(17); if(globallevel) storefunctionname(getfunction(head->value)->name); } else checkpattern(head); parseexpressionclause(); if(tokentype == WHERE) { gettoken(); parsewhereclause(); } else if(tokentype == offside) { tokenoffside = globaltokenoffside; gettoken(); if(tokentype == WHERE) { tokenoffside = tokenindent + 1; gettoken(); parsewhereclause(); } } makeinverse(LIST); top()->value = posCode; if(globallevel) { Cell *def = pop(); int argcount = 0; char *funname; head = def; for(head=head->left; head->tag==APPLY; head=head->left) argcount++; funname = getfunction(head->value)->name; initrename(funname); def = renamerec(FUN, def); if(!insert(funname, argcount, FUNC, def, NULL)) parseerror(18); } } }
static void parsestructdef(void) { char structname[stringsize]; char *headname; int count; Cell *head = pop(); setchecktypevariables(COLLECT); push(template_match); for(; head->tag==APPLY; head=head->left) { if(head->right->tag != UNDEFINED && head->right->tag != FUNC) parseerror(9); push(maketypevariable(getfunction(head->right->value)->name)); make(STRUCT); } if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(10); headname = getfunction(head->value)->name; makeconstant(FUNC, head->value); make(STRUCT); setchecktypevariables(CHECK); gettoken(); head = top(); if(tokentype == LACC) { count = 0; do { gettoken(); if(tokentype != IDENTIFIER) parseerror(25); push(gettemplate(tokenval)); gettoken(); if(tokentype != COLONS) parseerror(15); gettoken(); parsetype(TYPEEXPR); makerecordfield(head, getN(2), getN(1)); makeinverse(TYPEDEF); count++; } while(tokentype == COMMA); makecompound(RECORD, count); makeinverse(TYPEDEF); if(tokentype != RACC) parseerror(33); gettoken(); } else { for(;;) { if(tokentype != TYPEID) parseerror(11); strcpy(structname, tokenval); count = 0; gettoken(); while(tokentype == IDENTIFIER || tokentype == OPERATOR || tokentype == LBRACK || tokentype == LPAR) { parsetype(TYPETERM); count++; } push(head); while(count-- > 0) makeinverse(APPLY); if(!inserttypeexpr(structname, pop())) parseerror(12); if(tokentype != BAR) break; gettoken(); } } if(!inserttypeexpr(headname, pop())) parseerror(12); setchecktypevariables(NOCHECK); }
static void parsetype(TypeType typetype) { switch(tokentype) { case IDENTIFIER: if(strcmp(tokenval, "num") == 0) { push(newcell(INT)); gettoken(); } else if(strcmp(tokenval, "char") == 0) { push(newcell(CHAR)); gettoken(); } else if(strcmp(tokenval, "bool") == 0) { push(newcell(BOOLEAN)); gettoken(); } else { int count = 1; push(gettemplate(tokenval)); gettoken(); if(typetype == TYPEEXPR) while(tokentype == IDENTIFIER || tokentype == OPERATOR || tokentype == LBRACK || tokentype == LPAR) { parsetype(TYPETERM); count++; } makecompound(STRUCT, count); } break; case OPERATOR: push(maketypevariable(tokenval)); gettoken(); break; case LPAR: gettoken(); if(tokentype == RPAR) push(newcell(NULLTUPLE)); else { parsetype(TYPEEXPR); if(tokentype == COMMA) { int count = 1; while(tokentype == COMMA) { gettoken(); parsetype(TYPEEXPR); count++; } makecompound(PAIR, count); } } if(tokentype != RPAR) parseerror(2); gettoken(); break; case LBRACK: gettoken(); parsetype(TYPEEXPR); push(template_nil); makeinverse(LIST); if(tokentype != RBRACK) parseerror(1); gettoken(); break; default: parseerror(8); } if(typetype == TYPEEXPR && tokentype == ARROW) { gettoken(); parsetype(TYPEEXPR); makeinverse(APPLY); } }