XMLElement* CManagerModel::ParseMesh(XMLElement *XMLMesh,CModel* Model) { // Parse a SINGLE Mesh // Parse XMLSources AND Triangles. CMesh Mesh; XMLElement *XMLSource = XMLMesh->FirstChildElement("source"); XMLElement *Tri = XMLMesh->FirstChildElement("triangles"); XMLElement *Input = Tri->FirstChildElement("input"); //Mesh.mTriangleCount = Tri->IntAttribute("count"); while (Input != NULL) { CSource Source; if (strcmp(Input->Attribute("semantic"),"VERTEX") == 0) { Source.mID = XMLMesh->FirstChildElement("vertices")->FirstChildElement("input")->Attribute("source"); } else { Source.mID = Input->Attribute("source"); } Source.mType = (char*) Input->Attribute("semantic"); Source.mOffset = Input->IntAttribute("offset"); Source.mID = Source.mID.erase(0, 1); // Remove the pound symbol. // This is actually <p>, aka an index list. Mesh.mIndex = gusVector_SplitString((char*)Tri->FirstChildElement("p")->GetText(),' '); ParseSource(SourceByID(XMLMesh,(char*)Source.mID.c_str()),&Mesh,&Source); Input = Input->NextSiblingElement("input"); } // [Matrix setup] // Let's hope we've added everything needed in these loops. Model->AddMesh(Mesh); return XMLMesh->NextSiblingElement("mesh"); }
static int ParseSource( SOURCEFILE *ps, char *Src, char *Dst, int *pIdx, int MaxLen ) { char c,word[TOKEN_MAX_LEN]; int i,srcIdx,dstIdx,wordIdx; int wordFlag; srcIdx = 0; dstIdx = *pIdx; wordIdx = 0; wordFlag=WF_READY; for(;;) { c = Src[srcIdx++]; /* See if we go into label or non-label mode */ if( wordFlag==WF_READY ) { if( c=='"' ) wordFlag=WF_QUOTED; else if( LabelChar(c,1) ) { wordFlag=WF_LABEL; wordIdx=0; word[wordIdx++]=c; continue; } else if( LabelChar(c,0) ) wordFlag=WF_NONLABEL; } /* See if we fall out of non-label mode */ else if( wordFlag==WF_NONLABEL ) { if( c=='"' ) wordFlag=WF_QUOTED; else if( !LabelChar(c,0) ) wordFlag=WF_READY; } /* See if we fall out of label mode */ else if( wordFlag==WF_LABEL ) { if( (wordIdx>=(TOKEN_MAX_LEN-1)) || !LabelChar(c,0) ) { /* Here we are teminating the word and checking it */ EQUATE *peq; if( c=='"' ) wordFlag=WF_QUOTED; else wordFlag=WF_READY; word[wordIdx]=0; peq = EquateFind(word); /* See if equate exists and is free */ if( peq && !peq->Busy ) { /* Mark as busy, process, then mark as free */ peq->Busy=1; i = ParseSource( ps, peq->data, Dst, &dstIdx, MaxLen ); peq->Busy=0; /* If there was an error, return now */ if( !i ) return(0); } else { /* The word is not a EQUATE */ for(i=0;i<wordIdx;i++) { if( dstIdx<(MaxLen-1) ) Dst[dstIdx++]=word[i]; else { Report(ps,REP_ERROR,"Line too long"); return(0); } } } } else { /* Here we are building the word */ word[wordIdx++]=c; continue; } } /* See if we fall out of quoted mode */ else if( wordFlag==WF_QUOTED ) { if( c=='"' ) wordFlag=WF_READY; } /* If this character terminated the line, break now */ if( !c ) { if( wordFlag==WF_QUOTED ) Report(ps,REP_ERROR,"Non-terminated string"); break; } /* We didn't consume this charater */ if( dstIdx<(MaxLen-1) ) Dst[dstIdx++]=c; else { Report(ps,REP_ERROR,"Line too long"); return(0); } } *pIdx = dstIdx; return(1); }
int GetSourceLine( SOURCEFILE *ps, char *Dst, int MaxLen ) { char c,Src[RAW_SOURCE_MAX],word[TOKEN_MAX_LEN]; int i,idx; int len,eof; NEXT_LINE: do { if( !GetTextLine(ps, Src, RAW_SOURCE_MAX, &len, &eof) ) return(-1); } while( !len && !eof ); if( !len && eof ) { if( ps->ccDepthIn != ccDepth ) { Report(ps,REP_ERROR,"#endif mismatch in file"); return(0); } return(0); } /* // Process any '#' directives */ if( Src[0]=='#' ) { idx = 1; c = Src[idx++]; if( (c<'A'||c>'Z') && (c<'a'||c>'z') ) { Report(ps,REP_ERROR,"Expected {a-z} after #"); return(-1); } i=0; word[i++]=c; while( i<(TOKEN_MAX_LEN-1) ) { c = Src[idx++]; if( c==' ' || c==0x9 || !c ) break; word[i++]=c; } word[i]=0; /* Make sure the process functions see the final NULL */ if( !c ) idx--; if( !stricmp( word, "ifdef" ) ) { if( !IfDefProcess( ps, Src+idx, 1 ) ) return(-1); goto NEXT_LINE; } if( !stricmp( word, "ifndef" ) ) { if( !IfDefProcess( ps, Src+idx, 0 ) ) return(-1); goto NEXT_LINE; } if( !stricmp( word, "else" ) ) { if( !ElseProcess( ps, Src+idx ) ) return(-1); goto NEXT_LINE; } if( !stricmp( word, "endif" ) ) { if( !EndifProcess( ps, Src+idx ) ) return(-1); goto NEXT_LINE; } if( ccDepth && !(ccStateFlags[ccDepth-1]&CCSTATEFLG_TRUE) ) goto NEXT_LINE; if( !stricmp( word, "error" ) ) { Report(ps,REP_ERROR,"%s",Src+idx); goto NEXT_LINE; } if( !stricmp( word, "warn" ) ) { Report(ps,REP_WARN1,"%s",Src+idx); goto NEXT_LINE; } if( !stricmp( word, "note" ) ) { Report(ps,REP_INFO,"%s",Src+idx); goto NEXT_LINE; } if( !stricmp( word, "include" ) ) { if( !LoadInclude( ps, Src+idx ) ) return(-1); goto NEXT_LINE; } if( !stricmp( word, "define" ) ) { EquateProcess( ps, Src+idx ); goto NEXT_LINE; } if( !stricmp( word, "undef" ) ) { UndefProcess( ps, Src+idx ); goto NEXT_LINE; } Report(ps,REP_ERROR,"Unknown # directive"); return(-1); } /* // Not '#' directive, process as string */ if( ccDepth && !(ccStateFlags[ccDepth-1]&CCSTATEFLG_TRUE) ) goto NEXT_LINE; idx = 0; if( !ParseSource( ps, Src, Dst, &idx, MaxLen ) ) return(0); Dst[idx] = 0; return(idx); }
VOID __cdecl main ( IN int argc, IN char **argv ) { // // Initialize // InitParse (); ParseArgs (argc, argv); InitializeListHead (&VerifyRef); if (!Source) { HelpAndExit (NULL); } printf ("ACPI Souce Language Assembler Version 0.1\n"); printf ("Copyright (C) Microsoft Corp 1996. All rights reserved.\n"); fflush (stdout); // // Build top level scope & ASL data package for which image // can be built in // DataImage = AllocAl(); DataImage->Name = AllocName(); DataImage->Flags |= F_AMLPACKAGE | F_PVARIABLE; DataImage->Term = &ImageTerm; DataImage->Parent = DataImage; DataImage->DataType = TypeRoot; InitializeListHead(&DataImage->FixedList); InitializeListHead(&DataImage->u1.VariableList); DataImage->Name->NameSeg = (ULONG) '\\'; AlLoc = DataImage; // // Parse source // while (Source) { ParseSource (); CloseSource (); } if (Verbose > 1) { printf ("NameSpaceDump:\n"); DumpNameSpace (DataImage->Name, 0); //not valid anymore... //if (Verbose > 2) { // DumpImage(); // printf ("AMLSize %d\n", AMLSize); //} } // // Enable AML for data image, and calculate package sizes // DataImage->Flags |= F_AMLENCODE; WriteDefinitionBlocks (DataImage); // // Remove AML package size from image Al // DataImage->Flags &= ~F_AMLENCODE; DataImage->u.Data.Length = 0; // // ... // Terminate (); }
/* eval(source) */ int DuckEval(int argument_count, void* data) { L_TOKEN* lexing; SYNTAX_TREE* ast; char* buffer; int error = 0; VALUE argument = GetRecord("source", gCurrentContext); gLastExpression.type = VAL_NIL; gLastExpression.data.primitive = 0; CLOSURE* currentContext; currentContext = gCurrentContext; int prev_line_error = line_error; SYNTAX_TREE* prev_failed_production = failed_production; // if (gCurrentContext->parent) gCurrentContext = gCurrentContext->parent; gCurrentContext = gGlobalContext; if (argument.type == VAL_STRING) { lexing = LexSourceBuffer(argument.data.string, &buffer, CONTEXT_FREE_GRAMMAR); if (lexing == NULL) { printf("Error lexing source or empty source string.\n"); FreeLexing(lexing, buffer); return 1; } ast = ParseSource(lexing, PARSE_TABLE, CONTEXT_FREE_GRAMMAR); if (ast == NULL) { printf("Error parsing source.\n"); FreeLexing(lexing, buffer); return 1; } /* ReduceProgramAST(&ast); */ error = InterpretNode(ast); if (error) { printf("%s\n", ErrorMessage(error)); PrintStackTrace(); FreeLexing(lexing, buffer); FreeParseTree(ast); ClearCallStack(&gStackTrace); line_error = prev_line_error; failed_production = prev_failed_production; return 1; } /* sanitize last expression for use in program */ //gLastExpression = ReallocStrings(gLastExpression); /* free lexing and parse tree */ //FreeLexing(lexing, buffer); //FreeParseTree(ast); GCAddLexing(lexing, buffer); GCAddParseTree(ast); } gCurrentContext = currentContext; return error; }
static KMETHOD Expression_ExtendedTextLiteral(KonohaContext *kctx, KonohaStack *sfp) { VAR_Expression(expr, tokenList, beginIdx, opIdx, endIdx); kNameSpace *ns = kNode_ns(expr); kToken *tk = tokenList->TokenItems[opIdx]; INIT_GCSTACK(); kString *text = remove_escapes(kctx, tk); if(beginIdx != opIdx) { /* FIXME */ assert(0 && "FIXME"); KReturnUnboxValue(-1); } if(text == NULL) { /* text contain unsupported escape sequences */ RESET_GCSTACK(); KReturnUnboxValue(-1); } const char *str = kString_text(text); const char *end = NULL; const char *start = strstr(str, "${"); if(start == NULL) { /* text does not contain Interpolation expressions */ RESET_GCSTACK(); KReturnUnboxValue(beginIdx+1); } kSyntax *addSyntax = kSyntax_(ns, KSymbol_("+")); kTokenVar *opToken = tokenList->TokenVarItems[beginIdx]; opToken->symbol = KSymbol_("+"); opToken->text = KLIB new_kString(kctx, OnGcStack, "+", 1, 0); KFieldSet(opToken, opToken->resolvedSyntaxInfo, addSyntax); SUGAR kNode_Op(kctx, expr, opToken, 0); /* [before] "aaa${bbb}ccc" * [after] "" + "aaa" + bbb + "ccc" */ SUGAR kNode_AddNode(kctx, expr, new_ConstNode(kctx, ns, NULL, UPCAST(TS_EMPTY))); while(true) { start = strstr(str, "${"); if(start == NULL) break; if(start == strstr(str, "${}")) { str += 3; continue; } end = strchr(start, '}'); if(end == NULL) break; kNode *newexpr = ParseSource(kctx, ns, start+2, end-(start+2)); if(start - str > 0) { kNode *first = new_ConstNode(kctx, ns, NULL, UPCAST(KLIB new_kString(kctx, OnGcStack, str, (start - str), 0))); SUGAR kNode_AddNode(kctx, expr, first); } SUGAR kNode_AddNode(kctx, expr, newexpr); str = end + 1; } if((start == NULL) || (start != NULL && end == NULL)) { kNode *rest = new_ConstNode(kctx, ns, KClass_String, UPCAST(KLIB new_kString(kctx, OnGcStack, str, strlen(str), 0))); SUGAR kNode_AddNode(kctx, expr, rest); } /* (+ 1 2 3 4) => (+ (+ (+ 1 2) 3 ) 4) */ int i, size = kNode_GetNodeListSize(kctx, expr); assert(size > 2); kNode *leftNode = kNode_At(expr, 1), *rightNode; for(i = 2; i < size-1; i++) { kNode *node = KNewNode(ns); rightNode = kNode_At(expr, i); SUGAR kNode_Op(kctx, node, opToken, 2, leftNode, rightNode); leftNode = node; } rightNode = kNode_At(expr, i); KLIB kArray_Clear(kctx, expr->NodeList, 1); KLIB kArray_Add(kctx, expr->NodeList, leftNode); KLIB kArray_Add(kctx, expr->NodeList, rightNode); RESET_GCSTACK(); KReturnUnboxValue(beginIdx+1); }