sigsym * opcodelink(tnode * tptr) { sigsym * opdef; sigsym * newsym = NULL; sigsym * templatevars = NULL; tnode * t_code; if ((opdef = getvsym(&opcodenametable,tptr->val)) == NULL) return NULL; /* create clone of opcode table entry */ addvsym(&newsym, tptr->val, opdef->kind); newsym->rate = opdef->rate; newsym->kind = opdef->kind; newsym->width = opdef->width; newsym->maxifstate = opdef->maxifstate; /* create clone of opcode definition */ newsym->defnode = make_tnode("<opcodedecl>",S_OPCODEDECL); newsym->defnode->sptr = locsymtable = sclone(tlocsymtable = opdef->defnode->sptr); locopcodecalls = tclone(tlocopcodecalls = opdef->defnode->optr); locdyncalls = tclone(tlocdyncalls = opdef->defnode->dptr); newsym->defnode->down = treeclone(opdef->defnode->down,&templatevars,DOSUB); newsym->defnode->optr = locopcodecalls; newsym->defnode->dptr = locdyncalls; /* hook up variable declarations */ t_code = newsym->defnode->down ->next->next->next->next->next->next->down; varupdate(t_code,&locsymtable); /* hook up main code block */ t_code = newsym->defnode->down ->next->next->next->next->next->next->next->down; varupdate(t_code,&locsymtable); /* hook up pfield entries -- varupdate won't do this correctly */ t_code = newsym->defnode->down->next->next->next->down; while (t_code != NULL) { if (t_code->ttype == S_PARAMDECL) { t_code->sptr = t_code->down->next->sptr = t_code->down->next->down->sptr = getsym(&locsymtable, t_code->down->next->down); t_code->sptr->defnode = t_code->down->next->down; } t_code = t_code->next; } installopnames(newsym->defnode->optr); installdyninstr(newsym->defnode->dptr); return newsym; }
/* go past the symbol */ static void chk_skip_get(struct rnc_source *sp,int sym) { (void)chkskip(sp,sym,sym); getsym(sp); }
void compile(void) { LEXEME *lex = NULL ; SetGlobalFlag(TRUE); helpinit(); errorinit(); constoptinit(); declare_init(); init_init(); inlineinit(); lambda_init(); rtti_init(); expr_init(); libcxx_init(); statement_ini(); syminit(); preprocini(infile, inputFile); lexini(); setglbdefs(); templateInit(); #ifndef PARSER_ONLY SSAInit(); outcodeini(); conflictini(); iexpr_init(); iinlineInit(); flow_init(); genstmtini(); #endif ParseBuiltins(); if (chosenAssembler->intrinsicInit) chosenAssembler->intrinsicInit(); if (chosenAssembler->inlineAsmInit) chosenAssembler->inlineAsmInit(); if (chosenAssembler->outcode_init) chosenAssembler->outcode_init(); if (chosenAssembler->enter_filename) chosenAssembler->enter_filename(clist->data); if (cparams.prm_debug && chosenDebugger && chosenDebugger->init) chosenDebugger->init(); if (cparams.prm_browse && chosenDebugger && chosenDebugger->init_browsedata) chosenDebugger->init_browsedata(clist->data); browse_init(); browse_startfile(infile, 0); if (cparams.prm_assemble) { lex = getsym(); if (lex) { BLOCKDATA block; memset(&block, 0, sizeof(block)); block.type = begin; while ((lex = statement_asm(lex, NULL, &block)) != NULL) ; #ifndef PARSER_ONLY genASM(block.head); #endif } } else { #ifndef PARSER_ONLY asm_header(clist->data, version); #endif lex = getsym(); if (lex) { while ((lex = declare(lex, NULL, NULL, sc_global, lk_none, NULL, TRUE, FALSE, FALSE, FALSE, ac_public)) != NULL) ; } } #ifdef PARSER_ONLY ccDumpSymbols(); #endif if (!total_errors) { dumpInlines(); dumpInitializers(); dumpInlines(); dumpStartups(); #ifndef PARSER_ONLY dumpLits(); #endif /* rewrite_icode(); */ if (chosenAssembler->gen->finalGen) chosenAssembler->gen->finalGen(); if (!cparams.prm_assemble && cparams.prm_debug) if (chosenDebugger && chosenDebugger->outputtypedef) debug_dumptypedefs(globalNameSpace); #ifndef PARSER_ONLY putexterns(); #endif if (!cparams.prm_asmfile) if (chosenAssembler->output_obj_file) chosenAssembler->output_obj_file(); } findUnusedStatics(globalNameSpace); dumperrs(stdout); if (cparams.prm_debug && chosenDebugger && chosenDebugger->rundown) chosenDebugger->rundown(); if (cparams.prm_browse && chosenDebugger && chosenDebugger->rundown_browsedata) chosenDebugger->rundown_browsedata(); #ifndef PARSER_ONLY if (!cparams.prm_assemble) asm_trailer(); #endif }
// // Recursive descent parser, old-school style. // void getfactor(void) { numvar thesymval = symval; byte thesym = sym; getsym(); // eat the sym we just saved switch (thesym) { case s_nval: vpush(thesymval); break; case s_nvar: if (sym == s_equals) { // assignment, push is after the break; getsym(); assignVar(thesymval, getnum()); } else if (sym == s_incr) { // postincrement nvar++ vpush(getVar(thesymval)); assignVar(thesymval, getVar(thesymval) + 1); getsym(); break; } else if (sym == s_decr) { // postdecrement nvar-- vpush(getVar(thesymval)); assignVar(thesymval, getVar(thesymval) - 1); getsym(); break; } vpush(getVar(thesymval)); // both assignment and reference get pushed here break; case s_nfunct: dofunctioncall(thesymval); // get its value onto the stack break; // Script-function-returning-value used as a factor case s_script_eeprom: // macro returning value callscriptfunction(SCRIPT_EEPROM, findend(thesymval)); break; case s_script_progmem: callscriptfunction(SCRIPT_PROGMEM, thesymval); break; case s_script_file: callscriptfunction(SCRIPT_FILE, (numvar) 0); // name implicitly in idbuf! break; case s_apin: // analog pin reference like a0 if (sym == s_equals) { // digitalWrite or analogWrite getsym(); analogWrite(thesymval, getnum()); vpush(expval); } else vpush(analogRead(thesymval)); break; case s_dpin: // digital pin reference like d1 if (sym == s_equals) { // digitalWrite or analogWrite getsym(); digitalWrite(thesymval, getnum()); vpush(expval); } else vpush(digitalRead(thesymval)); break; case s_incr: if (sym != s_nvar) expected(M_var); assignVar(symval, getVar(symval) + 1); vpush(getVar(symval)); getsym(); break; case s_decr: // pre decrement if (sym != s_nvar) expected(M_var); assignVar(symval, getVar(symval) - 1); vpush(getVar(symval)); getsym(); break; case s_arg: // arg(n) - argument value if (sym != s_lparen) expectedchar(s_lparen); getsym(); // eat '(' vpush(getarg(getnum())); if (sym != s_rparen) expectedchar(s_rparen); getsym(); // eat ')' break; case s_lparen: // expression in parens getexpression(); if (exptype != s_nval) expected(M_number); if (sym != s_rparen) missing(M_rparen); vpush(expval); getsym(); // eat the ) break; // // The Family of Unary Operators, which Bind Most Closely to their Factor // case s_add: // unary plus (like +3) is kind of a no-op getfactor(); // scan a factor and leave its result on the stack break; // done case s_sub: // unary minus (like -3) getfactor(); vpush(-vpop()); // similar to above but we adjust the stack value break; case s_bitnot: getfactor(); vpush(~vpop()); break; case s_logicalnot: getfactor(); vpush(!vpop()); break; case s_bitand: // &var gives address-of-var; ¯o gives eeprom address of macro if (sym == s_nvar) vpush((numvar) &vars[symval]); else if (sym == s_script_eeprom) vpush(symval); else expected(M_var); getsym(); // eat the var reference break; case s_mul: // *foo is contents-of-address-foo; *foo=bar is byte poke assignment /***** // what is really acceptable for an lvalue here? ;) // *y = 5 is failing now by assigning 5 to y before the * is dereferenced // due to calling getfactor // everything else works :( *****/ getfactor(); #if 0 if (sym == s_equals) { getsym(); // eat '=' getexpression(); * (volatile byte *) vpop() = (byte) expval; vpush((numvar) (byte) expval); } else #endif vpush((numvar) (* (volatile byte *) vpop())); break; default: unexpected(M_number); } }
/* parser helpers: weak symbols, syntax errors */ static void skipto(struct rnc_source *sp,int sym) { while(CUR(sp).sym!=sym&&CUR(sp).sym!=SYM_EOF) getsym(sp); }
HOT void returnFromMethod(VMGlobals *g) { PyrFrame *returnFrame, *curframe, *homeContext; PyrMethod *meth; PyrMethodRaw *methraw; curframe = g->frame; //assert(slotRawFrame(&curframe->context) == NULL); /*if (gTraceInterpreter) { post("returnFromMethod %s:%s\n", slotRawClass(&g->method->ownerclass)->name.us->name, g->slotRawSymbol(&method->name)->name); post("tailcall %d\n", g->tailCall); }*/ #ifdef GC_SANITYCHECK g->gc->SanityCheck(); #endif homeContext = slotRawFrame(&slotRawFrame(&curframe->context)->homeContext); if (homeContext == NULL) { null_return: #if TAILCALLOPTIMIZE if (g->tailCall) return; // do nothing. #endif /* static bool once = true; if (once || gTraceInterpreter) { once = false; post("return all the way out. sd %d\n", g->sp - g->gc->Stack()->slots); postfl("%s:%s\n", slotRawClass(&g->method->ownerclass)->name.us->name, g->slotRawSymbol(&method->name)->name ); post("tailcall %d\n", g->tailCall); post("homeContext %p\n", homeContext); post("returnFrame %p\n", returnFrame); dumpObjectSlot(&homeContext->caller); DumpStack(g, g->sp); DumpBackTrace(g); } gTraceInterpreter = false; */ //if (IsNil(&homeContext->caller)) return; // do nothing. // return all the way out. PyrSlot *bottom = g->gc->Stack()->slots; slotCopy(bottom, g->sp); g->sp = bottom; // ??!! pop everybody g->method = NULL; g->block = NULL; g->frame = NULL; longjmp(g->escapeInterpreter, 2); } else { returnFrame = slotRawFrame(&homeContext->caller); if (returnFrame == NULL) goto null_return; // make sure returnFrame is a caller and find earliest stack frame { PyrFrame *tempFrame = curframe; while (tempFrame != returnFrame) { tempFrame = slotRawFrame(&tempFrame->caller); if (!tempFrame) { if (isKindOf((PyrObject*)g->thread, class_routine) && NotNil(&g->thread->parent)) { // not found, so yield to parent thread and continue searching. PyrSlot value; slotCopy(&value, g->sp); int numArgsPushed = 1; switchToThread(g, slotRawThread(&g->thread->parent), tSuspended, &numArgsPushed); // on the other side of the looking glass, put the yielded value on the stack as the result.. g->sp -= numArgsPushed - 1; slotCopy(g->sp, &value); curframe = tempFrame = g->frame; } else { slotCopy(&g->sp[2], &g->sp[0]); slotCopy(g->sp, &g->receiver); g->sp++; SetObject(g->sp, g->method); g->sp++; sendMessage(g, getsym("outOfContextReturn"), 3); return; } } } } { PyrFrame *tempFrame = curframe; while (tempFrame != returnFrame) { meth = slotRawMethod(&tempFrame->method); methraw = METHRAW(meth); PyrFrame *nextFrame = slotRawFrame(&tempFrame->caller); if (!methraw->needsHeapContext) { SetInt(&tempFrame->caller, 0); } else { if (tempFrame != homeContext) SetInt(&tempFrame->caller, 0); } tempFrame = nextFrame; } } // return to it g->ip = (unsigned char *)slotRawPtr(&returnFrame->ip); g->frame = returnFrame; g->block = slotRawBlock(&returnFrame->method); homeContext = slotRawFrame(&returnFrame->homeContext); meth = slotRawMethod(&homeContext->method); methraw = METHRAW(meth); #if DEBUGMETHODS if (gTraceInterpreter) { postfl("%s:%s <- %s:%s\n", slotRawSymbol(&slotRawClass(&meth->ownerclass)->name)->name, slotRawSymbol(&meth->name)->name, slotRawSymbol(&slotRawClass(&g->method->ownerclass)->name)->name, slotRawSymbol(&g->method->name)->name ); } #endif g->method = meth; slotCopy(&g->receiver, &homeContext->vars[0]); } #ifdef GC_SANITYCHECK g->gc->SanityCheck(); #endif }
int yylex (void) { int c; /* Ignore white space, get first nonwhite character. */ while ((c = getchar ()) == ' ' || c == '\t') continue; if (c == EOF) return 0; /* Char starts a number => parse the number. */ if (c == '.' || isdigit (c)) { ungetc (c, stdin); scanf ("%lf", &yylval.NUM); return NUM; } /* Char starts an identifier => read the name. */ if (isalpha (c)) { /* Initially make the buffer long enough for a 40-character symbol name. */ static size_t length = 40; static char *symbuf = 0; symrec *s; int i; if (!symbuf) symbuf = (char *) malloc (length + 1); i = 0; do { /* If buffer is full, make it bigger. */ if (i == length) { length *= 2; symbuf = (char *) realloc (symbuf, length + 1); } /* Add this character to the buffer. */ symbuf[i++] = c; /* Get another character. */ c = getchar (); } while (isalnum (c)); ungetc (c, stdin); symbuf[i] = '\0'; s = getsym (symbuf); if (s == 0) s = putsym (symbuf, VAR); *((symrec**) &yylval) = s; return s->type; } /* Any other character is a token by itself. */ return c; }
int prEvent_Delta(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, key, dur, stretch, delta; double fdur, fstretch; int err; PyrClass *restClass = getsym("Rest")->u.classobj; PyrSlot *slot; a = g->sp; // dict SetSymbol(&key, s_delta); identDict_lookup(slotRawObject(a), &key, calcHash(&key), &delta); if (NotNil(&delta)) { if (isKindOfSlot(&delta, restClass)) { slot = slotRawObject(&delta)->slots; err = slotDoubleVal(slot, &fdur); } else { err = slotDoubleVal(&delta, &fdur); } if (err) { return err; } else { SetFloat(a, fdur); return errNone; } } else { SetSymbol(&key, s_dur); identDict_lookup(slotRawObject(a), &key, calcHash(&key), &dur); err = slotDoubleVal(&dur, &fdur); if (err) { if (IsNil(&dur)) { SetNil(g->sp); return errNone; } else if (isKindOfSlot(&dur, restClass)) { slot = slotRawObject(&dur)->slots; err = slotDoubleVal(slot, &fdur); if (err) return err; } else { return errWrongType; } } SetSymbol(&key, s_stretch); identDict_lookup(slotRawObject(a), &key, calcHash(&key), &stretch); err = slotDoubleVal(&stretch, &fstretch); if (err) { if (NotNil(&stretch)) { if (isKindOfSlot(&stretch, restClass)) { slot = slotRawObject(&stretch)->slots; err = slotDoubleVal(slot, &fstretch); if (err) return err; } else { return errWrongType; } } else { SetFloat(a, fdur); return errNone; } } SetFloat(a, fdur * fstretch); } return errNone; }
void initPatterns() { PyrSymbol *sym; ivxIdentDict_array = instVarOffset("IdentityDictionary", "array"); ivxIdentDict_size = instVarOffset("IdentityDictionary", "size"); ivxIdentDict_parent = instVarOffset("IdentityDictionary", "parent"); ivxIdentDict_proto = instVarOffset("IdentityDictionary", "proto"); ivxIdentDict_know = instVarOffset("IdentityDictionary", "know"); sym = getsym("IdentityDictionary"); class_identdict = sym ? sym->u.classobj : NULL; class_identdict_index = slotRawInt(&class_identdict->classIndex); class_identdict_maxsubclassindex = slotRawInt(&class_identdict->maxSubclassIndex); class_array_index = slotRawInt(&class_array->classIndex); class_array_maxsubclassindex = slotRawInt(&class_array->maxSubclassIndex); s_parent = getsym("parent"); s_proto = getsym("proto"); s_delta = getsym("delta"); s_dur = getsym("dur"); s_stretch = getsym("stretch"); // used in prEvent_IsRest s_type = getsym("type"); s_rest = getsym("rest"); s_empty = getsym(""); s_r = getsym("r"); s_isRest = getsym("isRest"); class_rest = getsym("Rest")->u.classobj; class_metarest = getsym("Meta_Rest")->u.classobj; }
static void chk_get(int v,int erno) {if(sym!=SYM_CHR||val!=v) error(erno); getsym();}
static void bind(int r) { r0=ri=r; sym=-1; errors=0; getsym(); }
void pragvararg(void) { Sym *s; int n, c; char *t; Rune r; Type *ty; if(!debug['F']) goto out; s = getsym(); if(s && strcmp(s->name, "argpos") == 0) goto ckpos; if(s && strcmp(s->name, "type") == 0) goto cktype; if(s && strcmp(s->name, "flag") == 0) goto ckflag; yyerror("syntax in #pragma varargck"); goto out; ckpos: /*#pragma varargck argpos warn 2*/ s = getsym(); if(s == S) goto bad; n = getnsn(); if(n < 0) goto bad; newname(s->name, n); goto out; ckflag: /*#pragma varargck flag 'c'*/ c = getnsc(); if(c != '\'') goto bad; c = getr(); if(c == '\\') c = getr(); else if(c == '\'') goto bad; if(c == '\n') goto bad; if(getc() != '\'') goto bad; argflag(c, Fignor); goto out; cktype: /*#pragma varargck type O int*/ c = getnsc(); if(c != '"') goto bad; t = fmtbuf; for(;;) { r = getr(); if(r == ' ' || r == '\n') goto bad; if(r == '"') break; t += runetochar(t, &r); } *t = 0; t = strdup(fmtbuf); s = getsym(); if(s == S) goto bad; ty = s->type; while((c = getnsc()) == '*') ty = typ(TIND, ty); unget(c); newprot(s, ty, t); goto out; bad: yyerror("syntax in #pragma varargck"); out: while(getnsc() != '\n') ; }
/*ARGSUSED*/ static int process_aggregate(const dtrace_aggdata_t **aggsdata, int naggvars, void *arg) { const dtrace_recdesc_t *rec; uintptr_t lock; uint64_t *stack; caddr_t data; pid_t pid; struct ps_prochandle *P; char buf[256]; int i, j; uint64_t sum, count, avg; if ((*(uint_t *)arg)++ >= g_nent) return (DTRACE_AGGWALK_NEXT); rec = aggsdata[0]->dtada_desc->dtagd_rec; data = aggsdata[0]->dtada_data; /*LINTED - alignment*/ lock = (uintptr_t)*(uint64_t *)(data + rec[1].dtrd_offset); /*LINTED - alignment*/ stack = (uint64_t *)(data + rec[2].dtrd_offset); if (!g_opt_s) { /*LINTED - alignment*/ sum = *(uint64_t *)(aggsdata[1]->dtada_data + aggsdata[1]->dtada_desc->dtagd_rec[3].dtrd_offset); /*LINTED - alignment*/ count = *(uint64_t *)(aggsdata[2]->dtada_data + aggsdata[2]->dtada_desc->dtagd_rec[3].dtrd_offset); } else { uint64_t *a; /*LINTED - alignment*/ a = (uint64_t *)(aggsdata[1]->dtada_data + aggsdata[1]->dtada_desc->dtagd_rec[3].dtrd_offset); print_bar(); print_legend(); for (count = sum = 0, i = DTRACE_QUANTIZE_ZEROBUCKET, j = 0; i < DTRACE_QUANTIZE_NBUCKETS; i++, j++) { count += a[i]; sum += a[i] << (j - 64); } } avg = sum / count; (void) printf("%5llu %8llu ", (u_longlong_t)count, (u_longlong_t)avg); pid = stack[0]; P = dtrace_proc_grab(g_dtp, pid, PGRAB_RDONLY); (void) getsym(P, lock, buf, sizeof (buf), 0); (void) printf("%-28s ", buf); for (i = 2; i <= 5; i++) { if (getsym(P, stack[i], buf, sizeof (buf), 1) == 0) break; } (void) printf("%s\n", buf); if (g_opt_s) { int stack_done = 0; int quant_done = 0; int first_bin, last_bin; uint64_t bin_size, *a; /*LINTED - alignment*/ a = (uint64_t *)(aggsdata[1]->dtada_data + aggsdata[1]->dtada_desc->dtagd_rec[3].dtrd_offset); print_histogram_header(); for (first_bin = DTRACE_QUANTIZE_ZEROBUCKET; a[first_bin] == 0; first_bin++) continue; for (last_bin = DTRACE_QUANTIZE_ZEROBUCKET + 63; a[last_bin] == 0; last_bin--) continue; for (i = 0; !stack_done || !quant_done; i++) { if (!stack_done) { (void) getsym(P, stack[i + 2], buf, sizeof (buf), 0); } else { buf[0] = '\0'; } if (!quant_done) { bin_size = a[first_bin]; (void) printf("%10llu |%-24.*s| %5llu %s\n", 1ULL << (first_bin - DTRACE_QUANTIZE_ZEROBUCKET), (int)(24.0 * bin_size / count), "@@@@@@@@@@@@@@@@@@@@@@@@@@", (u_longlong_t)bin_size, buf); } else { (void) printf("%43s %s\n", "", buf); } if (i + 1 >= g_nframes || stack[i + 3] == 0) stack_done = 1; if (first_bin++ == last_bin) quant_done = 1; } } dtrace_proc_release(g_dtp, P); return (DTRACE_AGGWALK_NEXT); }
static long ieprimary(TYP **tp) /* * PRimary integer * defined(MACRO) * id * iconst * (cast )intexpr * (intexpr) */ { long temp=0; SYM *sp; if (tp) *tp = &stdint; if(lastst == id) { char *lid = lastid; if (prm_cmangle) lid++; sp = gsearch(lastid); if(sp == NULL) { gensymerror(ERR_UNDEFINED,lastid); getsym(); return 0; } if(sp->storage_class != sc_const && sp->tp->type != bt_enum) { generror(ERR_NEEDCONST,0,0); getsym(); return 0; } getsym(); return sp->value.i; } else if(lastst == iconst) { temp = ival; getsym(); return temp; } else if(lastst == lconst) { if (tp) *tp = &stdlong; temp = ival; getsym(); return temp; } else if(lastst == iuconst) { if (tp) *tp = &stduns; temp = ival; getsym(); return temp; } else if(lastst == luconst) { if (tp) *tp = &stdunsigned; temp = ival; getsym(); return temp; } else if(lastst == cconst) { if (tp) *tp = &stdchar; temp = ival; getsym(); return temp; } else if (lastst == openpa) { getsym(); if (castbegin(lastst)) { decl(0); decl1(); needpunc(closepa,0); if (tp) *tp = head; return intexpr(0); } else { temp = intexpr(tp); return(temp); } } getsym(); generror(ERR_NEEDCONST,0,0); return 0; }
static int arx(char *fn) { if((arxfd=open(arxfn=fn,O_RDONLY))==-1) { (*er_printf)("error (%s): %s\n",arxfn,strerror(errno)); return 0; } else { errors=0; len_b=read(arxfd,buf,BUFSIZE); i_b=u_bom(buf,len_b); prevline=-1; line=1; col=0; rnc=0; cc=' '; getsym(); chk_get(SYM_GRMS); chk_get(SYM_LCUR); do { if(i_2==len_2) t2s=(int(*)[2])m_stretch(t2s,len_2=i_2*2,i_2,sizeof(int[2])); if(chksym(SYM_IDNT)) t2s[i_2][0]=add_s(value); getsym(); chk_get(SYM_ASGN); if(chksym(SYM_LTRL)) { if(path2abs) { int len=strlen(arxfn)+strlen(value)+1; if(len>len_v) {value=(char*)m_stretch(value,len,len_v,sizeof(char)); len_v=len;} s_abspath(value,arxfn); } t2s[i_2][1]=add_s(value); } getsym(); ++i_2; } while(sym==SYM_IDNT); chk_get(SYM_RCUR); for(;;) { if(i_r==len_r) rules=(int(*)[3])m_stretch(rules,len_r=i_r*2,i_r,sizeof(int[3])); switch(sym) { case SYM_MTCH: rules[i_r][0]=MATCH; goto REGEXP; case SYM_NMTC: rules[i_r][0]=NOMAT; goto REGEXP; REGEXP: getsym(); if(chksym(SYM_RGXP)) { if(!rx_check(value)) error(ARX_ER_REX); rules[i_r][1]=add_s(value); } getsym(); if(chksym(SYM_IDNT)) rules[i_r][2]=typ2str(); goto NEXT; case SYM_VALD: rules[i_r][0]=VALID; goto RNG; case SYM_NVAL: rules[i_r][0]=INVAL; goto RNG; RNG: getsym(); if(chksym(SYM_RENG)) { char *rncfn=(char*)m_alloc(strlen(arxfn)+strlen("#rnc[]")+12,sizeof(char)); sprintf(rncfn,"%s#rnc[%i]",arxfn,rnc++); if(!(rules[i_r][1]=rnl_s(rncfn,value,strlen(value)))) error(ARX_ER_RNG); m_free(rncfn); } getsym(); if(chksym(SYM_IDNT)) rules[i_r][2]=typ2str(); goto NEXT; default: goto LAST; } NEXT: ++i_r; getsym(); } LAST: chk_get(SYM_EOF); close(arxfd); return !errors; } }
void pragvararg(void) { Sym *s; int n, c; char *t; if(1) goto out; s = getsym(); if(s && strcmp(s->name, "argpos") == 0) goto ckpos; if(s && strcmp(s->name, "type") == 0) goto cktype; yyerror("syntax in #pragma varargck"); goto out; ckpos: /*#pragma varargck argpos warn 2*/ s = getsym(); if(s == S) goto bad; n = getnsn(); if(n < 0) goto bad; newname(s->name, n); goto out; cktype: /*#pragma varargck type O int*/ c = getnsc(); if(c != '"') goto bad; t = fmtbuf; for(;;) { c = getc(); if(c == ' ' || c == '\n') goto bad; if(c == '"') break; *t++ = c; } *t = 0; t = strdup(fmtbuf); s = getsym(); if(s == S) goto bad; c = getnsc(); unget(c); if(c == '*') newprot(s, typ(TIND, s->type), t); else newprot(s, s->type, t); goto out; bad: yyerror("syntax in #pragma varargck"); out: while(getnsc() != '\n') ; }
static int oct_parser_lex (){ int c; char *symbuf = 0; int length = 0; /* Ignore whitespace, get first nonwhite character. */ while ((c = par_string[par_pos++]) == ' ' || c == '\t'); if (c == '\0') return '\n'; /* Char starts a number => parse the number. */ if (c == '.' || isdigit (c)){ par_pos--; par_pos += get_real(&par_string[par_pos], &GSL_REAL(yylval.val)); return NUM; } /* get the logical operators */ if (c == '<' && par_string[par_pos] == '='){ par_pos++; return LE; } if (c == '>' && par_string[par_pos] == '='){ par_pos++; return GE; } if (c == '=' && par_string[par_pos] == '='){ par_pos++; return EQUAL; } /* if (c == ':' && par_string[par_pos] == '='){ par_pos++; return SET; } */ if (c == '&' && par_string[par_pos] == '&'){ par_pos++; return LAND; } if (c == '|' && par_string[par_pos] == '|'){ par_pos++; return LOR; } /* Char starts an identifier => read the name. */ if (isalpha (c) || c == '\'' || c == '\"'){ symrec *s; char startc = c; int i; /* Initially make the buffer long enough for a 40-character symbol name. */ if (length == 0) length = 40, symbuf = (char *)malloc (length + 1); if(startc == '\'' || startc == '\"') c = par_string[par_pos++]; else startc = 0; /* false */ i = 0; do{ /* If buffer is full, make it larger. */ if (i == length){ length *= 2; symbuf = (char *)realloc (symbuf, length + 1); } /* Add this character to the buffer. */ symbuf[i++] = c; /* Get another character. */ c = par_string[par_pos++]; }while (c != '\0' && ((startc && c!=startc) || (!startc && (isalnum(c) || c == '_' )))); if(!startc) par_pos--; symbuf[i] = '\0'; if(!startc){ s = getsym (symbuf); if (s == 0){ int jj; for (jj = 0; reserved_symbols[jj] != 0; jj++){ if(strcmp(symbuf, reserved_symbols[jj]) == 0){ fprintf(stderr, "Error: trying to redefine reserved symbol '%s'", symbuf); exit(1); } } s = putsym (symbuf, S_CMPLX); } yylval.tptr = s; free(symbuf); if(s->type == S_CMPLX) return VAR; else return FNCT; }else{ yylval.str = strdup(symbuf); free(symbuf); return STR; } } /* Any other character is a token by itself. */ return c; }
int yylex (void) { int c; /* Skip white space. */ while ((c = getchar ()) == ' ' || c == '\t') ++yylloc.last_column; /* Store starting location . */ yylloc.first_line = yylloc.last_line; yylloc.first_column = yylloc.last_column; /* Process numbers. */ if (isdigit (c)) { yylval.val = c - '0'; ++yylloc.last_column; while (isdigit(c = getchar())) { ++yylloc.last_column; yylval.val = yylval.val * 10 + c - '0'; } if (c == '.') { double tens = 1.0; while (isdigit(c = getchar())) { ++yylloc.last_column; tens *= 0.1; yylval.val += tens * (c - '0'); } } ungetc (c, stdin); return NUM; } if (isalpha(c)) { symrec *s; static char *symbuf = 0; static int length = 0; int i; /* Initially make buffer long enough for 50 char name. */ if (length == 0) { length = 50; symbuf = (char *)malloc(length+1); } i = 0; do { ++yylloc.last_column; if (i == length) { length *= 2; symbuf = (char *)realloc(symbuf, length+1); } symbuf[i++] = c; c = getchar(); } while (isalnum(c)); ungetc(c, stdin); symbuf[i] = 0; s = getsym(symbuf); if (s == NULL) s = putsym(symbuf, VAR); yylval.tptr = s; return s->type; } /* Return end-of-input. */ if (c == EOF) return 0; /* Handle single character stuff including location. */ if (c == '\n') { ++yylloc.last_line; yylloc.last_column = 0; } else ++yylloc.last_column; return c; }
void SC_LanguageClient::runLibrary(const char* methodName) { lock(); ::runLibrary(getsym(methodName)); unlock(); }
double process_query( const char* pquery ) { if (pquery==NULL) return 0; //DEBUG only if (dumpOutFile.is_open()) { debugDumper(std::string("call to process_query: ") + pquery); } //dump stuff on alli call, or is this a bad idea if we can only call? don't think so if (strncmp(pquery,"dll$alli",8)==0) { isAllInMsg = true; handsplayed = (int) getsym("handsplayed"); //DEBUG only char handStr[10]; sprintf(handStr, "%d", handsplayed); debugDumper(std::string("cur handsplayed: ") + handStr); if (!setCurAction()) { //something went wrong dumpOutFile << "ERROR: did not find next TestSuite2 action for test file " << curTestFilename << std::endl; } else if (!curTestSuiteAction.fold && !curTestSuiteAction.call && !curTestSuiteAction.raise && !curTestSuiteAction.raiseTo && !curTestSuiteAction.allIn) { dumpOutFile << "ERROR: no result on parsing FCKRA for TestSuite2 action in test file " << curTestFilename << std::endl; } //DEBUG only debugDumper(std::string("cur test file: ") + curTestFilename); char cardBuf0[5], cardBuf1[5]; convertCardToString((int) getsym("$$pc0"), cardBuf0); convertCardToString((int) getsym("$$pc1"), cardBuf1); debugDumper(std::string("cards: ") + cardBuf0 + " " + cardBuf1); prevHandsplayed = handsplayed; printCurAction(); dumpSymbols(); //dump previous state holdem_state* prev_state = &m_holdem_state[ (m_ndx) & 0xff ]; dumpState(prev_state); if (curTestSuiteAction.allIn && !(curTestSuiteAction.raise || curTestSuiteAction.raiseTo || curTestSuiteAction.call)) { debugDumper(std::string("process_query: alli=1")); return 1.0; //maybe don't do it if other is set too //return 0; } } else if (strncmp(pquery,"dll$call",8)==0) { if (curTestSuiteAction.call) { debugDumper(std::string("process_query: call=1")); return 1.0; } } else if (strncmp(pquery,"dll$fold",8)==0) { if (curTestSuiteAction.fold) { debugDumper(std::string("process_query: fold=1")); //does it even exist: return 1.0; //return 0; } } else if (strncmp(pquery,"dll$rais",8)==0) { if (curTestSuiteAction.raise || curTestSuiteAction.raiseTo) { debugDumper(std::string("process_query: rais=1")); return 1.0; } //debug: //return 1.0; } else if (strncmp(pquery,"dll$swag",8)==0 || strncmp(pquery,"dll$betsize",11)==0) { if (curTestSuiteAction.raiseTo) { //DEBUG only char valueStr[10]; sprintf(valueStr, "%f", curTestSuiteAction.raiseToVal); debugDumper(std::string("process_query: ") + pquery + "=" + valueStr); return curTestSuiteAction.raiseToVal; } } return 0; }
// Skip to next nonblank and return the symbol therefrom void skpwhite(void) { while (chartype(inchar) == 0) fetchc(); getsym(); }
// Check if next symbol is a comma. Get next symbol and return true if found; otherwise, set error if "required" is true and // return false. bool getcomma(bool required) { return havesym(s_comma,required) && (getsym() == SUCCESS || havesym(s_any,true)); }
void initMIDIPrimitives() { int base, index; base = nextPrimitiveIndex(); index = 0; gSysexData.reserve(1024); s_midiin = getsym("MIDIIn"); s_domidiaction = getsym("doAction"); s_midiNoteOnAction = getsym("doNoteOnAction"); s_midiNoteOffAction = getsym("doNoteOffAction"); s_midiTouchAction = getsym("doTouchAction"); s_midiControlAction = getsym("doControlAction"); s_midiPolyTouchAction = getsym("doPolyTouchAction"); s_midiProgramAction = getsym("doProgramAction"); s_midiBendAction = getsym("doBendAction"); s_midiSysexAction = getsym("doSysexAction"); s_midiInvalidSysexAction = getsym("doInvalidSysexAction"); // client can handle incorrect case s_midiSysrtAction = getsym("doSysrtAction"); s_midiSMPTEAction = getsym("doSMPTEaction"); s_numMIDIDev = getsym("prSetNumberOfDevices"); s_midiclient = getsym("MIDIClient"); definePrimitive(base, index++, "_ListMIDIEndpoints", prListMIDIEndpoints, 1, 0); definePrimitive(base, index++, "_InitMIDI", prInitMIDI, 3, 0); definePrimitive(base, index++, "_InitMIDIClient", prInitMIDIClient, 1, 0); definePrimitive(base, index++, "_ConnectMIDIIn", prConnectMIDIIn, 3, 0); definePrimitive(base, index++, "_DisconnectMIDIIn", prDisconnectMIDIIn, 3, 0); definePrimitive(base, index++, "_DisposeMIDIClient", prDisposeMIDIClient, 1, 0); definePrimitive(base, index++, "_RestartMIDI", prRestartMIDI, 1, 0); definePrimitive(base, index++, "_SendMIDIOut", prSendMIDIOut, 9, 0); definePrimitive(base, index++, "_SendSysex", prSendSysex, 3, 0); if(gMIDIClient) midiCleanUp(); }
int main() { //初始化部分变量 kk = al; cc = 0; ll = 0; ch = ' '; //初始化符号类型表 for(int i=0;i<256;i++) strcpy_s(ssym[i], al+1, nul); strcpy_s(ssym['+'], al+1, plus); strcpy_s(ssym['-'], al+1, minus); strcpy_s(ssym['*'], al+1, times); strcpy_s(ssym['/'], al+1, slash); strcpy_s(ssym['('], al+1, lparen); strcpy_s(ssym[')'], al+1, rparen); strcpy_s(ssym['='], al+1, eql); strcpy_s(ssym[','], al+1, comma); strcpy_s(ssym['.'], al+1, period); strcpy_s(ssym['<'], al+1, lss); strcpy_s(ssym['>'], al+1, gtr); strcpy_s(ssym[';'], al+1, semicolon); //初始化保留字表 strcpy_s(word[0], al+1, "begin "); strcpy_s(word[1], al+1, "call "); strcpy_s(word[2], al+1, "const "); strcpy_s(word[3], al+1, "do "); strcpy_s(word[4], al + 1, "else "); strcpy_s(word[5], al+1, "end "); strcpy_s(word[6], al+1, "if "); strcpy_s(word[7], al+1, "odd "); strcpy_s(word[8], al+1, "procedure "); strcpy_s(word[9], al+1, "read "); strcpy_s(word[10], al+1, "then "); strcpy_s(word[11], al+1, "var "); strcpy_s(word[12], al+1, "while "); strcpy_s(word[13], al+1, "write "); //初始化保留字类型表 strcpy_s(wsym[0], al+1, "beginsym "); strcpy_s(wsym[1], al+1, "callsym "); strcpy_s(wsym[2], al+1, "constsym "); strcpy_s(wsym[3], al+1, "dosym "); strcpy_s(wsym[4], al+1, "elsesym "); strcpy_s(wsym[5], al+1, "endsym "); strcpy_s(wsym[6], al+1, "ifsym "); strcpy_s(wsym[7], al+1, "oddsym "); strcpy_s(wsym[8], al+1, "prosym "); strcpy_s(wsym[9], al+1, "readsym "); strcpy_s(wsym[10], al+1, "thensym "); strcpy_s(wsym[11], al+1, "varsym "); strcpy_s(wsym[12], al+1, "whilesym "); strcpy_s(wsym[13], al+1, "writesym "); //读取文件 printf("please input source program file name : \n"); scanf_s("%s",infilename,80); if ((ferr = fopen_s(&infile, infilename, "r")) != 0) { error(1); exit(1); } //分词输出{序号,分词类型,单词值}(一符一类的单词值为空,因此数字和标识符需要输出单词值) for (int i = 1;;i++){ getsym(); if (strcmp(sym, number)==0) printf("%d %s %d\n",i,sym,num); else if (strcmp(sym, ident) == 0) printf("%d %s %s\n", i, sym, id); else printf("%d %s\n", i, sym); } fclose(infile); return 0; }
/* check and skip to the symbol if failed */ static void chk_skip(struct rnc_source *sp,int symc,int syms) { if(chkskip(sp,symc,syms)) getsym(sp); }
int processident(char *token) { char c; PyrSymbol *sym; PyrSlot slot; PyrParseNode *node; c = token[0]; zzval = -1; #if DEBUGLEX if (gDebugLexer) postfl("word: '%s'\n",token); #endif /* strcpy(uptoken, token); for (str = uptoken; *str; ++str) { if (*str >= 'a' && *str <= 'z') *str += 'A' - 'a'; }*/ if (token[0] == '_') { if (token[1] == 0) { node = newPyrCurryArgNode(); zzval = (long)node; return CURRYARG; } else { sym = getsym(token); SetSymbol(&slot, sym); node = newPyrSlotNode(&slot); zzval = (long)node; return PRIMITIVENAME; } } if (token[0] >= 'A' && token[0] <= 'Z') { sym = getsym(token); SetSymbol(&slot, sym); node = newPyrSlotNode(&slot); zzval = (long)node; #if DEBUGLEX if (gDebugLexer) postfl("CLASSNAME: '%s'\n",token); #endif return CLASSNAME; } if (strcmp("var",token) ==0) return VAR; if (strcmp("arg",token) ==0) return ARG; if (strcmp("classvar",token) ==0) return CLASSVAR; if (strcmp("const",token) ==0) return SC_CONST; if (strcmp("while",token) ==0) { sym = getsym(token); SetSymbol(&slot, sym); node = newPyrSlotNode(&slot); zzval = (long)node; return WHILE; } if (strcmp("pi",token) ==0) { SetFloat(&slot, pi); node = newPyrSlotNode(&slot); zzval = (long)node; return PIE; } if (strcmp("true",token) ==0) { SetTrue(&slot); node = newPyrSlotNode(&slot); zzval = (long)node; return TRUEOBJ; } if (strcmp("false",token) ==0) { SetFalse(&slot); node = newPyrSlotNode(&slot); zzval = (long)node; return FALSEOBJ; } if (strcmp("nil",token) ==0) { SetNil(&slot); node = newPyrSlotNode(&slot); zzval = (long)node; return NILOBJ; } if (strcmp("inf",token) ==0) { SetFloat(&slot, std::numeric_limits<double>::infinity()); node = newPyrSlotNode(&slot); zzval = (long)node; return SC_FLOAT; } sym = getsym(token); SetSymbol(&slot, sym); node = newPyrSlotNode(&slot); zzval = (long)node; return NAME; }
LEXEME *expression_lambda(LEXEME *lex, SYMBOL *funcsp, TYPE *atp, TYPE **tp, EXPRESSION **exp, int flags) { LAMBDA *self; SYMBOL *vpl, *ths; HASHREC *hrl; TYPE *ltp; STRUCTSYM ssl; if (funcsp) funcsp->noinline = TRUE; IncGlobalFlag(); self = Alloc(sizeof(LAMBDA)); ltp = Alloc(sizeof(TYPE)); ltp->type = bt_struct; ltp->syms = CreateHashTable(1); ltp->tags = CreateHashTable(1); ltp->size = 0; self->captured = CreateHashTable(1); self->oldSyms = localNameSpace->syms; self->oldTags = localNameSpace->tags; self->index = lambdaIndex; self->captureMode = cmNone; self->isMutable = FALSE; self->captureThis = FALSE; self->cls = makeID(sc_type, ltp, NULL, LambdaName()); ltp->sp = self->cls; SetLinkerNames(self->cls, lk_cdecl); self->cls->islambda = TRUE; self->cls->structAlign = getAlign(sc_global, &stdpointer); self->func = makeID(sc_member, ltp, NULL, "$internalFunc"); self->func->parentClass = self->cls; self->functp = &stdauto; self->enclosingFunc = theCurrentFunc; if (lambdas) lambdas->prev = self; self->next = lambdas; lambdas = self; localNameSpace->syms = CreateHashTable(1); localNameSpace->tags = CreateHashTable(1); if (lambdas->next) { self->lthis = lambdas->next->lthis; } else if (funcsp && funcsp->parentClass) { self->lthis = ((SYMBOL *)funcsp->tp->syms->table[0]->p); } lex = getsym(); // past [ if (funcsp) { // can have a capture list; if (MATCHKW(lex, assign)) { lex = getsym(); if (MATCHKW(lex, comma) || MATCHKW(lex, closebr)) { self->captureMode = cmValue; skip(&lex, comma); } else { lex = backupsym(); } } else if (MATCHKW(lex, and)) { lex = getsym(); if (MATCHKW(lex, comma) || MATCHKW(lex, closebr)) { self->captureMode = cmRef; skip(&lex, comma); } else { lex = backupsym(); } } if (!MATCHKW(lex, comma) && !MATCHKW(lex, closebr)) { do { enum e_cm localMode = self->captureMode; if (MATCHKW(lex, comma)) skip(&lex, comma); if (MATCHKW(lex, kw_this)) { lex = getsym(); if (localMode == cmValue || !self->lthis) { error(ERR_CANNOT_CAPTURE_THIS); } else { if (self->captureThis) { error(ERR_CAPTURE_ITEM_LISTED_MULTIPLE_TIMES); } self->captureThis = TRUE; lambda_capture(NULL, cmThis, TRUE); } continue; } else if (MATCHKW(lex, and)) { if (localMode == cmRef) { error(ERR_INVALID_LAMBDA_CAPTURE_MODE); } localMode = cmRef; lex = getsym(); } else { if (localMode == cmValue) { error(ERR_INVALID_LAMBDA_CAPTURE_MODE); } localMode = cmValue; } if (ISID(lex)) { SYMBOL *sp = search(lex->value.s.a, localNameSpace->syms); LAMBDA *current = lambdas; while (current && !sp) { sp = search(lex->value.s.a, current->oldSyms); current = current->next; } lex = getsym(); if (sp) { if (sp->packed) { if (!MATCHKW(lex, ellipse)) error(ERR_PACK_SPECIFIER_REQUIRED_HERE); else lex = getsym(); } if (sp->packed) { int n; TEMPLATEPARAMLIST * templateParam = sp->tp->templateParam->p->byPack.pack; HASHREC *hr; for (n=0; templateParam; templateParam = templateParam->next, n++); hr = funcsp->tp->syms->table[0]; while (hr && ((SYMBOL *)hr->p) != sp) hr = hr->next; while (hr && n) { lambda_capture((SYMBOL *)hr->p, localMode, TRUE); hr = hr->next; n--; } } else { lambda_capture(sp, localMode, TRUE); } } else errorstr(ERR_UNDEFINED_IDENTIFIER, lex->value.s.a); } else { error(ERR_INVALID_LAMBDA_CAPTURE_MODE); } } while (MATCHKW(lex, comma)); } needkw(&lex, closebr); } else { if (!MATCHKW(lex, closebr)) { error(ERR_LAMBDA_CANNOT_CAPTURE); } else { lex = getsym(); } } if (MATCHKW(lex, openpa)) { TYPE *tpx = &stdvoid; HASHREC *hr; lex = getFunctionParams(lex, NULL, &self->func, &tpx, FALSE, sc_auto); self->funcargs = self->func->tp->syms->table[0]; hr = self->func->tp->syms->table[0]; while (hr) { SYMBOL *sym = (SYMBOL *)hr->p; if (sym->init) { error(ERR_CANNOT_DEFAULT_PARAMETERS_WITH_LAMBDA); } hr = hr->next; } if (MATCHKW(lex, kw_mutable)) { HASHREC *hr = self->captured->table[0]; while (hr) { LAMBDASP *lsp = (LAMBDASP *)hr->p; if (lsp->sym->lambdaMode == cmValue) { lsp->sym->tp = basetype(lsp->sym->tp); } hr = hr->next; } self->isMutable = TRUE; lex = getsym(); } ParseAttributeSpecifiers(&lex, funcsp, TRUE); if (MATCHKW(lex, pointsto)) { lex = getsym(); lex = get_type_id(lex, &self->functp, funcsp, sc_cast, FALSE, TRUE); } } else { TYPE *tp1 = Alloc(sizeof(TYPE)); SYMBOL *spi; tp1->type = bt_func; tp1->size = getSize(bt_pointer); tp1->btp = &stdvoid; tp1->sp = self->func; self->func->tp = tp1; spi = makeID(sc_parameter, tp1, NULL, AnonymousName()); spi->anonymous = TRUE; spi->tp = Alloc(sizeof(TYPE)); spi->tp->type = bt_void; insert(spi, localNameSpace->syms); SetLinkerNames(spi, lk_cpp); self->func->tp->syms = localNameSpace->syms; self->funcargs = self->func->tp->syms->table[0]; self->func->tp->syms->table[0] = NULL; } vpl = makeID(sc_parameter, &stdpointer, NULL, AnonymousName()); vpl->assigned = vpl->used = TRUE; SetLinkerNames(vpl, lk_cdecl); hrl = Alloc(sizeof(HASHREC)); hrl->p = (struct _hrintern_ *)vpl; hrl->next = lambdas->func->tp->syms->table[0]; lambdas->func->tp->syms->table[0] = hrl; vpl = makeID(sc_parameter, &stdpointer, NULL, AnonymousName()); vpl->assigned = vpl->used = TRUE; SetLinkerNames(vpl, lk_cdecl); hrl = Alloc(sizeof(HASHREC)); hrl->p = (struct _hrintern_ *)vpl; hrl->next = lambdas->func->tp->syms->table[0]; lambdas->func->tp->syms->table[0] = hrl; SetLinkerNames(lambdas->func, lk_cdecl); injectThisPtr(lambdas->func, basetype(lambdas->func->tp)->syms); lambdas->func->tp->btp = self->functp; lambdas->func->linkage = lk_virtual; lambdas->func->isInline = TRUE; ssl.str = self->cls; ssl.tmpl = NULL; addStructureDeclaration(&ssl); ths = makeID(sc_member, &stdpointer, NULL, "$this"); lambda_insert(ths, lambdas); if (MATCHKW(lex, begin)) { lex = body(lex, self->func); } else { error(ERR_LAMBDA_FUNCTION_BODY_EXPECTED); } dropStructureDeclaration(); localNameSpace->syms = self->oldSyms; localNameSpace->tags = self->oldTags; inferType(); finishClass(); *exp = createLambda(0); *tp = lambdas->cls->tp; lambdas = lambdas->next; if (lambdas) lambdas->prev = NULL; DecGlobalFlag(); return lex; }
static void chk_get(int x) { (void)chksym(x); getsym(); }
int push_val(int type) { unsigned int mul, val; int op; char c; val = 0; c = *expr; switch (type) { /* program counter */ case T_PC: if (data_loccnt == -1) val = (loccnt + (page << 13)); else val = (data_loccnt + (page << 13)); expr++; break; /* char ascii value */ case T_CHAR: expr++; val = *expr++; if ((*expr != c) || (val == 0)) { error("Syntax Error!"); return (0); } expr++; break; /* symbol */ case T_SYMBOL: /* extract it */ if (!getsym()) return (0); /* an user function? */ if (func_look()) { if (!func_getargs()) return (0); expr_stack[func_idx++] = expr; expr = (unsigned char *)func_ptr->line; return (1); } /* a predefined function? */ op = check_keyword(); if (op) { if (!push_op(op)) return (0); else return (1); } /* search the symbol */ expr_lablptr = stlook(1); /* check if undefined, if not get its value */ if (expr_lablptr == NULL) return (0); else if (expr_lablptr->type == UNDEF) undef++; else if (expr_lablptr->type == IFUNDEF) undef++; else val = expr_lablptr->value; /* remember we have seen a symbol in the expression */ expr_lablcnt++; break; /* binary number %1100_0011 */ case T_BINARY: mul = 2; goto extract; /* hexa number $15AF */ case T_HEXA: mul = 16; goto extract; /* decimal number 48 (or hexa 0x5F) */ case T_DECIMAL: if((c == '0') && (toupper(expr[1]) == 'X')) { mul = 16; expr++; } else { mul = 10; val = c - '0'; } /* extract a number */ extract: for (;;) { expr++; c = *expr; if (isdigit(c)) c -= '0'; else if (isalpha(c)) { c = toupper(c); if (c < 'A' && c > 'F') break; else { c -= 'A'; c += 10; } } else if (c == '_' && mul == 2) continue; else break; if (c >= mul) break; val = (val * mul) + c; } break; } /* check for too big expression */ if (val_idx == 63) { error("Expression too complex!"); return (0); } /* push the result on the value stack */ val_idx++; val_stack[val_idx] = val; /* next must be an operator */ need_operator = 1; /* ok */ return (1); }
tnode * treeclone(tnode * tptr, sigsym ** matchlist, int dosub) { tnode * retptr = NULL; tnode * cptr = NULL; /* initialization not needed */ tnode * lptr; sigsym * match; while (tptr != NULL) { if (retptr == NULL) { vmcheck(retptr = cptr = (tnode*) malloc(sizeof(tnode))); } else { vmcheck(cptr->next = (tnode*) malloc(sizeof(tnode))); cptr = cptr->next; } cptr->down = treeclone(tptr->down, matchlist, dosub); cptr->vartype = tptr->vartype; cptr->sptr = NULL; /* special case of locsymtable definition */ if ((tptr->sptr != NULL) && (tptr->sptr->defnode == tptr)) { tptr->sptr->defnode = cptr; cptr->sptr = tptr->sptr; /* patch up original symbol table pointer */ tptr->sptr = getvsym(&tlocsymtable,tptr->sptr->val); } cptr->special = tptr->special; cptr->width = tptr->width; cptr->ibus = NULL; cptr->arrayidx = tptr->arrayidx; cptr->usesinput = tptr->usesinput; cptr->usesingroup = tptr->usesingroup; cptr->dptr = tptr->dptr; if (cptr->dptr != NULL) { cptr->dptr->dptr = cptr; /* patch original table pointer */ tptr->dptr = dptrmatch(tlocdyncalls, tptr); } cptr->optr = tptr->optr; if ((cptr->optr == &maplistopcall) || /* maplist calls */ (cptr->optr == &maplistoparraycall)) { if (tptr->down == NULL) { if (locopcodecalls == NULL) { if (cptr->optr == &maplistopcall) locopcodecalls = make_tnode(tptr->val, S_OPCALL); else locopcodecalls = make_tnode(tptr->val, S_OPARRAYCALL); cptr->optr = locopcodecalls; locopcodecalls->optr = cptr; } else { lptr = locopcodecalls; while (lptr->next != NULL) lptr = lptr->next; if (cptr->optr == &maplistopcall) lptr->next = make_tnode(tptr->val, S_OPCALL); else lptr->next = make_tnode(tptr->val, S_OPARRAYCALL); lptr = lptr->next; cptr->optr = lptr; lptr->optr = cptr; } } else { lptr = locopcodecalls; while (lptr != NULL) { if (lptr->optr == cptr->down) { lptr->optr = cptr; cptr->optr = lptr; lptr = NULL; } else lptr = lptr->next; } } } else if (cptr->optr != NULL) { /* patch original table pointer*/ tptr->optr = optrmatch(tlocopcodecalls, tptr); if (cptr->down != NULL) /* if its the retptr of the opcode call */ { tptr->down->optr = tptr->optr; /* patch original table */ cptr->optr->optr = cptr; /* update locsymtable pointer */ if (cptr->down->next->ttype == S_LB) /* oparray */ { lptr = locopcodecalls; while ((lptr != NULL) && (lptr->ttype == S_OPARRAYDECL) && (strcmp(lptr->val, cptr->down->val) != 0)) lptr = lptr->next; if ((lptr == NULL) || (lptr->opwidth == 0)) { printf("Error: Undeclared oparray call %s\n", cptr->down->val); showerrorplace(cptr->down->linenum, cptr->down->filename); } cptr->optr->ibus = lptr; } } } cptr->opwidth = tptr->opwidth; cptr->staterate = tptr->staterate; cptr->extra = NULL; cptr->extrarate = tptr->extrarate; cptr->time = tptr->time; cptr->linenum = tptr->linenum; cptr->filename = tptr->filename; cptr->next = NULL; match = getsym(matchlist,tptr); if ( (match == NULL) || (!dosub) ) { cptr->val = dupval(tptr->val); cptr->ttype = tptr->ttype; cptr->res = tptr->res; cptr->rate = tptr->rate; cptr->vol = tptr->vol; } else { switch (match->defnode->down->ttype) { case S_IDENT: if (match->defnode->down->next == NULL) /* simple identifier */ { cptr->val = dupval(match->defnode->down->val); cptr->ttype = match->defnode->down->ttype; cptr->res = match->defnode->down->res; cptr->rate = match->defnode->down->rate; cptr->vol = match->defnode->down->vol; } else { if ((tptr->next != NULL)||(tptr->down != NULL)) { printf("Error: Inappropriate template substitution.\n"); showerrorplace(tptr->linenum, tptr->filename); } if (match->defnode->down->next->ttype == S_LB) { if (match->defnode->down->next->next->next->next == NULL) { /* indexed array */ cptr->val = dupval(match->defnode->down->val); cptr->ttype = match->defnode->down->ttype; cptr->res = match->defnode->down->res; cptr->rate = match->defnode->down->rate; cptr->vol = match->defnode->down->vol; cptr->next = treeclone( match->defnode->down->next, matchlist, NOSUB); } else { /* oparray call */ cptr->val = "("; cptr->ttype = S_LP; cptr->next = treeclone(match->defnode, matchlist, NOSUB); cptr = cptr->next; cptr->next = make_tnode(")",S_RP); cptr = cptr->next; } } else { /* opcode call */ cptr->val = "("; cptr->ttype = S_LP; cptr->next = treeclone(match->defnode, matchlist, NOSUB); cptr = cptr->next; cptr->next = make_tnode(")",S_RP); cptr = cptr->next; } } break; case S_NUMBER: case S_INTGR: cptr->val = dupval(match->defnode->down->val); cptr->ttype = match->defnode->down->ttype; cptr->res = match->defnode->down->res; cptr->rate = match->defnode->down->rate; cptr->vol = match->defnode->down->vol; break; default: if ((tptr->next != NULL)||(tptr->down != NULL)) { printf("Error: Inappropriate template"); printf(" substitution.\n"); showerrorplace(tptr->linenum, tptr->filename); } /* expression */ cptr->val = "("; cptr->ttype = S_LP; cptr->next = treeclone(match->defnode, matchlist, NOSUB); cptr = cptr->next; cptr->next = make_tnode(")",S_RP); cptr = cptr->next; break; } } tptr = tptr->next; } return retptr; }