sptr<SymFunc> Parser::ParseFunc(bool program) { Types t = currToken->type; if (program) { Expect(PROGRAM, -1); } else Expect(FUNCTION, PROCEDURE, -1); string name = currToken->lexeme; sptr<FuncSymType> functype(new FuncSymType(NextTable())); NextToken(); Expect(OPENBRAC, -1); if (!MatchSkip(CLOSEBRAC, -1)) { do { functype->PushArgs(ParseVarList(functype->symTable)); } while (MatchSkip(SEMICOLON, -1)); Expect(CLOSEBRAC, -1); } if (t == FUNCTION) { Expect(COLON, -1); functype->SetType(currSymTable->GetType(currToken->lexeme)); NextToken(); } else { functype->SetType(SymType::voidType); } Expect(SEMICOLON, -1); sptr<SymFunc> func(new SymFunc(name, functype, ParseBodyBlock())); LastTable()->Push(func); return func; }
int NPPluginExec(const char *var_list) { char *wurl = NULL; uint16_t stype = NP_NORMAL; char *svar_list = strdup(var_list); char *argn[100], *argv[100]; int count = ParseVarList(svar_list, argn, argv, 100); #ifdef VIEWER for (int i = 0; i < count; i++) if (stricmp("src", argn[i]) == 0) wurl = argv[i]; fprintf(stderr, "count: %s\n", wurl); if (count == 0 || wurl == NULL) { free(svar_list); return 0; } fprintf(stderr, "URL: %s\n", wurl); NPPlugin * plugin = new NPPlugin(__netscape_hwnd); __plugin_instance_list.insert(plugin); memset(plugin, 0, sizeof(NPP_t)); __pluginfunc.newp("application/x-shockwave-flash", plugin, 1, count, argn, argv, NULL); plugin->SetWindow(); plugin->AttachWindow(); NPN_GetURLNotify(plugin, wurl, NULL, NULL); #endif free(svar_list); return 0; }
void Parser::ParseVarSymbols(sptr<SymTable> table, bool is_record) { table = table ? table : currSymTable; do { if (Match(PROCEDURE, FUNCTION)) { if (is_record) throw ParserException("functions is not allowed in records"); ParseFunc(); } else { ParseVarList(table); } } while (MatchSkip(SEMICOLON, -1)); }
/* ===================================================== * Write down the code needed to call COMPARATOR(...) * ===================================================== */ void CallComponent(PARSER_CONFIG* conf, CSV_INPUT *data, FILE *flp, int nLn) { int i = 0; int ret = 0; int nIO = 0; EXPRESSION expr; bool foundComp = false; int nInp = 0, nOut = 0; COMPONENT comp; fprintf(stderr, " MakeComponentCall: \n"); fprintf(stderr, " MakeComponentCall: nom_row = %d\n", data->nom_row); fprintf(stderr, " MakeComponentCall: Id_compon = %d\n", data->Id_compon); fprintf(stderr, " MakeComponentCall: page_alg = %s\n", data->page_alg); fprintf(stderr, " MakeComponentCall: Type_compon = %s\n", data->Type_compon); fprintf(stderr, " MakeComponentCall: run_compon = %s\n", data->run_compon); fprintf(stderr, " MakeComponentCall: data_struct = %s\n", data->data_struct); fprintf(stderr, " MakeComponentCall: description = %s\n", data->description); fprintf(stderr, " MakeComponentCall: comments = %s\n", data->comments); fprintf(stderr, "\n"); fprintf(stderr, "nComp = %d\n", conf->nComp); // Fill component name and data structure name // We're going through preconfigured components one by one, // checking radiy's native names against the one given on CSV-data for (int i = 0; i < conf->nComp; i++) { fprintf(stderr, "%d: %s <-> %s\n", i, data->run_compon, conf->comp[i].radiyName); // "It's a kind of magic"(c) - we found what we need // Now let's fill local COMPONENT buffer with component's info // from configuration structure so we can use it for writing the code if (!strcmp(data->run_compon, conf->comp[i].radiyName)) { memcpy((char*)&comp, (char*)&(conf->comp[i]), sizeof(COMPONENT)); foundComp = true; conf->comp[i].nFound++; // increment number of found components break; } } if (!foundComp) { // Put a note into cscan code fprintf(flp, "\n\n/* Warning: component type %s mentioned in line %d not found in configuration*/\n\n", data->run_compon, data->nom_row); // And drop the same line into a log or onto a screen fprintf(stderr, "\n\n/* Warning: component type %s mentioned in line %d not found in configuration*/\n\n", data->run_compon, data->nom_row); // Sorry, done return; } // Put cleanup statement in front of component call fprintf(flp, "\tmemset(&%s, \'\\x0\', sizeof(%s));\n\n", comp.datastructName, comp.datatypeName); // Loop through all arguments, expressions are expected ////////////////////////////////////////////////////// // This is output loop ////////////////////////////////////////////////////// i = 0; while (strlen(data->args[i])) { fprintf(stderr, "MakeComponentCall: args[%d] = %s\n", i, data->args[i]); ret = ParseExpression(data->args[i], &expr); fprintf(stderr, "\nInput loop EXPRESSION: ret = %d\n", ret); fprintf(stderr, "signal = %d\n", expr.signal); fprintf(stderr, "number = %d\n", expr.number); fprintf(stderr, "list = %d\n", expr.list); fprintf(stderr, "error = %d\n", expr.error); fprintf(stderr, "lp = %s\n", expr.lp); fprintf(stderr, "rp = %s\n", expr.rp); fprintf(stderr, "mddname = %s\n", expr.mddname); fprintf(stderr, "inMDD = %d\\nn", expr.inMDD); if (ret == IAM_EXPRESSION) { //fprintf(flp, "/* Original: %s*/ \n", data->args[i]); // Here we make two loops through comp's IO array - the 1st one in serch of inputs, // the 2nd one in search of outputs // Get all inputs 1st nIO = 0; while (strlen(comp.inputNames[nIO])) { if (!strcmp(comp.inputNames[nIO], expr.lp)) { if (expr.signal) // mdd name appears on the right { if (expr.rp[0] == '!') GetSignalInfo(nLn, expr.rp + 1, expr.mddname); // function will update nSig and fill *(signals + nSig) else GetSignalInfo(nLn, expr.rp, expr.mddname); // function will update nSig and fill *(signals + nSig) if ((signals + nSig - 1)->found) fprintf(flp, "\t// Internal ID: %s External ID: %s\n", (signals + nSig - 1)->radiyname, (signals + nSig - 1)->extID); /* fprintf(flp, "\t// Coordinates: %s\n", (signals + nSig - 1)->coord); fprintf(flp, "\t// Descrption: %s\n", (signals + nSig - 1)->descr); }*/ if (expr.Not) // all that inputIsArray staff is a f*****g patch - force RADIY to get rid of that shit!! { //if ((comp.inputIsArray) && (!strcmp(comp.inputNames[nIO], "XIN"))) // PATCH!!!! if (comp.inputIsArray[nIO]) fprintf(flp, "\t%s.%s[0] = !%s;\t// PATCH %s\n", comp.datastructName, expr.lp, expr.mddname, comp.inputDesc[nIO]); else fprintf(flp, "\t%s.%s = !%s;\t// %s\n", comp.datastructName, expr.lp, expr.mddname, comp.inputDesc[nIO]); } else { //if ((comp.inputIsArray) && (!strcmp(comp.inputNames[nIO], "XIN"))) // PATCH!!!! if (comp.inputIsArray[nIO]) fprintf(flp, "\t%s.%s[0] = %s;\t// PATCH %s\n", comp.datastructName, expr.lp, expr.mddname, comp.inputDesc[nIO]); else fprintf(flp, "\t%s.%s = %s;\t// %s\n", comp.datastructName, expr.lp, expr.mddname, comp.inputDesc[nIO]); } strcpy(data->inputs[nInp], expr.rp ); nInp++; } else if (expr.number) // right part appears on the right as is { fprintf(flp, "\t%s.%s = %s;\t// %s\n", comp.datastructName, expr.lp, expr.rp, comp.inputDesc[nIO]); strcpy(data->inputs[nInp], expr.rp ); nInp++; } else if (expr.list) // we have a coma-sep list on the right. // Let's parse it and print as lp[n] = ... { fprintf(flp, "\t// %s\n", comp.inputDesc[nIO]); ParseVarList(nLn, flp, comp.datastructName, expr.lp, expr.rp); int nLst = 0; while (strlen(inputsLst[nLst])) { strcpy(data->inputs[nInp], inputsLst[nLst]); nInp++; nLst++; } } } nIO++; } } else fprintf(flp, "/*Not a valid expression: %s*/ \n", data->args[i]); i++; } // Write a component call as all inputs are set fprintf(flp, "\n\t%s(&%s);\n\n", comp.simexecName, comp.datastructName); ////////////////////////////////////////////////////// // This is output loop, exactly the same as the one // for inputs above ////////////////////////////////////////////////////// i = 0; while (strlen(data->args[i])) { ret = ParseExpression(data->args[i], &expr); if (ret == IAM_EXPRESSION) { //fprintf(flp, "/* Original: %s*/ \n", data->args[i]); // Here we make two loops through comp's IO array - the 1st one in serch of inputs, // the 2nd one in search of outputs // Get all outputs now nIO = 0; while (strlen(comp.outputNames[nIO])) { if (!strcmp(comp.outputNames[nIO], expr.lp)) { if (expr.signal) // mdd name appears on the left, that's fine { if (expr.rp[0] == '!') GetSignalInfo(nLn, expr.rp + 1, expr.mddname); // function will update nSig and fill *(signals + nSig) else GetSignalInfo(nLn, expr.rp, expr.mddname); // function will update nSig and fill *(signals + nSig) if ((signals + nSig - 1)->found) fprintf(flp, "\t// Internal ID: %s External ID: %s\n", (signals + nSig - 1)->radiyname, (signals + nSig - 1)->extID); /* fprintf(flp, "\t// Coordinates: %s\n", (signals + nSig - 1)->coord); fprintf(flp, "\t// Descrption: %s\n", (signals + nSig - 1)->descr); */ if (expr.Not) fprintf(flp, "\t%s = !%s.%s;\t//%s\n", expr.mddname, comp.datastructName, expr.lp, comp.outputDesc[nIO]); else fprintf(flp, "\t%s = %s.%s;\t//%s\n", expr.mddname, comp.datastructName, expr.lp, comp.outputDesc[nIO]); strcpy(data->outputs[nOut], expr.rp ); nOut++; } else if (expr.number) // This is error - invalid left part of the equation { fprintf(flp, "\t/* Error, wrong LP: %s = %s.%s;*/ \n", expr.rp, comp.datastructName, expr.lp); strcpy(data->outputs[nOut], expr.rp ); nOut++; } } nIO++; } } else fprintf(flp, "/*Not a valid expression: %s*/ \n", data->args[i]); i++; } fprintf(flp, "\n\n"); return; }