void Parse3DMatrix (int z, int y, int x, vec_t *m) { int i; MatchToken( "(" ); for (i = 0 ; i < z ; i++) { Parse2DMatrix (y, x, m + i * x*y); } MatchToken( ")" ); }
void Parse2DMatrix (int y, int x, vec_t *m) { int i; MatchToken( "(" ); for (i = 0 ; i < y ; i++) { Parse1DMatrix (x, m + i * x); } MatchToken( ")" ); }
void Parse1DMatrix (int x, vec_t *m) { int i; MatchToken( "(" ); for (i = 0 ; i < x ; i++) { GetToken( qfalse ); m[i] = atof(token); } MatchToken( ")" ); }
void ParsedObject::GetOtherSide(LispInt aNrArgsToCombine, LispInt depth) { const LispString* theOperator = iLookAhead; MatchToken(iLookAhead); ReadExpression(depth); InsertAtom(theOperator); Combine(aNrArgsToCombine); }
static void FormalParam(void) { SymPtr sym; Pointer param; MatchToken(tVARIABLE); param = GetIdent(); sym = SymAdd(param); sym->kind = LOCAL_KIND; NextToken(); }
int ParseParamGroup( ParseContext* ctx ) { ConfigToken ParamTokens[] = { Token_IP, Token_Port, Token_KeyFile, Token_Pwd, Token_PwdFile, Token_RightBrace }; ConfigToken token = Token_Unknown; char token_checks[TOKEN_COUNT]; int rc = 0; memset( token_checks, 0, sizeof(token_checks) ); if( MatchToken( ctx, Token_LeftBrace ) == CONFIG_PARSE_ERROR ) return CONFIG_PARSE_ERROR; do { /* get the parameter */ token = ParseOneOf( ctx, ParamTokens, ARRAY_SIZE( ParamTokens ) ); if( token == CONFIG_PARSE_ERROR ) rc = CONFIG_PARSE_ERROR; if( rc == 0 && token != Token_RightBrace ) { token_checks[token] = 1; /* get the value */ Advance( ctx ); if( ctx->token == NULL ) { sprintf( error_buffer, "%s: unexpected EOF found near '%s'", ERROR_PREFIX, TokenToString( token ) ); rc = CONFIG_PARSE_ERROR; } /* assign the parameter value */ if( rc == 0 ) rc = AssignParam( ctx, token, ctx->token ); } } while( rc == 0 && token != Token_RightBrace ); if( rc == 0 ) { /* validate the current server settings */ if( !token_checks[Token_IP] ) rc = FormatMissingServerParamError( Token_IP ); if( rc == 0 && !token_checks[Token_KeyFile] ) rc = FormatMissingServerParamError( Token_KeyFile ); if( rc == 0 && !token_checks[Token_Port] ) rc = FormatMissingServerParamError( Token_Port ); if( rc == 0 && token_checks[Token_Pwd] && token_checks[Token_PwdFile] ) { sprintf( error_buffer, "%s: Error in server definition: Either 'pwdfile' (recommended) or 'pwd' parameter is expected, but not both", ERROR_PREFIX ); rc = CONFIG_PARSE_ERROR; } } return rc; }
void Parse1DMatrix (int x, vec_t *m) { int i; MatchToken( "(" ); for (i = 0 ; i < x ; i++) { GetToken( qfalse ); m[i] = atof(token); } #if 0 MatchToken( ")" ); #else // su44: MoHAA patchDef2's sometimes have here additional keywords while(1) { GetToken( qtrue ); if(!stricmp(token,"subdivisions")) { GetToken( qtrue ); // value } else if(!stricmp(token,"surfaceDensity")) { GetToken( qtrue ); // value } else if(!stricmp(token,"+surfaceparm")) { GetToken( qtrue ); // flagname } else if(!stricmp(token,"-surfaceparm")) { GetToken( qtrue ); // flagname } else if(!stricmp(token,"surfaceColor")) { GetToken( qtrue ); GetToken( qtrue ); GetToken( qtrue ); } else { break; } } if ( strcmp( token, ")" ) ) { Error( "Parse1DMatrix: MatchToken( \"%s\" ) failed at line %i", ")", scriptline ); } #endif }
void ParsedObject::ReadAtom() { LispOperators::const_iterator opi = iParser.iPrefixOperators.find(iLookAhead); if (opi != iParser.iPrefixOperators.end()) { const LispString* theOperator = iLookAhead; MatchToken(iLookAhead); { ReadExpression(opi->second.iPrecedence); InsertAtom(theOperator); Combine(1); } } // Else parse brackets else if (iLookAhead == iParser.iEnvironment.iBracketOpen->String()) { MatchToken(iLookAhead); ReadExpression(KMaxPrecedence); // least precedence MatchToken(iParser.iEnvironment.iBracketClose->String()); } //Parse lists else if (iLookAhead == iParser.iEnvironment.iListOpen->String()) { LispInt nrargs = 0; MatchToken(iLookAhead); while (iLookAhead != iParser.iEnvironment.iListClose->String()) { ReadExpression(KMaxPrecedence); // least precedence nrargs++; if (iLookAhead == iParser.iEnvironment.iComma->String()) { MatchToken(iLookAhead); } else if (iLookAhead != iParser.iEnvironment.iListClose->String()) { throw LispErrGeneric(std::string("Expecting a } close bracket for program block, but got ") + *iLookAhead + std::string(" instead")); } } MatchToken(iLookAhead); const LispString* theOperator = iParser.iEnvironment.iList->String(); InsertAtom(theOperator); Combine(nrargs); } // Parse prog bodies else if (iLookAhead == iParser.iEnvironment.iProgOpen->String()) { LispInt nrargs = 0; MatchToken(iLookAhead); while (iLookAhead != iParser.iEnvironment.iProgClose->String()) { ReadExpression(KMaxPrecedence); // least precedence nrargs++; if (iLookAhead == iParser.iEnvironment.iEndStatement->String()) { MatchToken(iLookAhead); } else { throw LispErrGeneric(std::string("Expecting ; end of statement in program block, but got ") + *iLookAhead + std::string(" instead")); } } MatchToken(iLookAhead); const LispString* theOperator = iParser.iEnvironment.iProg->String(); InsertAtom(theOperator); Combine(nrargs); } // Else we have an atom. else { const LispString* theOperator = iLookAhead; MatchToken(iLookAhead); LispInt nrargs = -1; if (iLookAhead == iParser.iEnvironment.iBracketOpen->String()) { nrargs = 0; MatchToken(iLookAhead); while (iLookAhead != iParser.iEnvironment.iBracketClose->String()) { ReadExpression(KMaxPrecedence); // least precedence nrargs++; if (iLookAhead == iParser.iEnvironment.iComma->String()) { MatchToken(iLookAhead); } else if (iLookAhead != iParser.iEnvironment.iBracketClose->String()) { throw LispErrGeneric(std::string("Expecting a ) closing bracket for sub-expression, but got ") + *iLookAhead + std::string(" instead")); } } MatchToken(iLookAhead); opi = iParser.iBodiedOperators.find(theOperator); if (opi != iParser.iBodiedOperators.end()) { ReadExpression(opi->second.iPrecedence); // KMaxPrecedence nrargs++; } } InsertAtom(theOperator); if (nrargs >= 0) Combine(nrargs); } // Parse postfix operators while (iParser.iPostfixOperators.find(iLookAhead) != iParser.iPostfixOperators.end()) { InsertAtom(iLookAhead); MatchToken(iLookAhead); Combine(1); } }
void ParsedObject::ReadExpression(LispInt depth) { ReadAtom(); for (;;) { //Handle special case: a[b]. a is matched with lowest precedence!! if (iLookAhead == iParser.iEnvironment.iProgOpen->String()) { // Match opening bracket MatchToken(iLookAhead); // Read "index" argument ReadExpression(KMaxPrecedence); // Match closing bracket if (iLookAhead != iParser.iEnvironment.iProgClose->String()) throw LispErrGeneric(std::string("Expecting a ] close bracket for program block, but got ") + *iLookAhead + std::string(" instead")); MatchToken(iLookAhead); // Build into Ntn(...) const LispString* theOperator = iParser.iEnvironment.iNth->String(); InsertAtom(theOperator); Combine(2); } else { LispOperators::const_iterator opi = iParser.iInfixOperators.find(iLookAhead); if (opi == iParser.iInfixOperators.end()) { if (!IsSymbolic((*iLookAhead)[0])) return; const std::size_t origlen = iLookAhead->size(); std::size_t len = origlen; while (len > 1) { len -= 1; const LispString* lookUp = iParser.iEnvironment.HashTable().LookUp(iLookAhead->substr(0, len)); opi = iParser.iInfixOperators.find(lookUp); if (opi != iParser.iInfixOperators.end()) { const LispString* lookUpRight = iParser.iEnvironment.HashTable().LookUp(iLookAhead->substr(len, origlen - len)); if (iParser.iPrefixOperators.find(lookUpRight) != iParser.iPrefixOperators.end()) { iLookAhead = lookUp; LispInput& input = iParser.iInput; LispInt newPos = input.Position() - (origlen - len); input.SetPosition(newPos); break; } opi = iParser.iInfixOperators.end(); } } if (opi == iParser.iInfixOperators.end()) return; } if (depth < opi->second.iPrecedence) return; LispInt upper = opi->second.iPrecedence; if (!opi->second.iRightAssociative) upper--; GetOtherSide(2, upper); } } }
void ParsePatch( qboolean onlyLights ) { vec_t info[ 5 ]; int i, j, k; parseMesh_t *pm; char texture[ MAX_QPATH ]; char shader[ MAX_QPATH ]; mesh_t m; bspDrawVert_t *verts; epair_t *ep; vec4_t delta, delta2, delta3; qboolean degenerate; float longestCurve; int maxIterations; MatchToken( "{" ); /* get texture */ GetToken( qtrue ); strcpy( texture, token ); Parse1DMatrix( 5, info ); m.width = info[0]; m.height = info[1]; m.verts = verts = (bspDrawVert_t *)safe_malloc( m.width * m.height * sizeof( m.verts[0] ) ); if( m.width < 0 || m.width > MAX_PATCH_SIZE || m.height < 0 || m.height > MAX_PATCH_SIZE ) Error( "ParsePatch: bad size" ); MatchToken( "(" ); for( j = 0; j < m.width ; j++ ) { MatchToken( "(" ); for( i = 0; i < m.height ; i++ ) { Parse1DMatrix( 5, verts[ i * m.width + j ].xyz ); /* ydnar: fix colors */ for( k = 0; k < MAX_LIGHTMAPS; k++ ) { verts[ i * m.width + j ].color[ k ][ 0 ] = 255; verts[ i * m.width + j ].color[ k ][ 1 ] = 255; verts[ i * m.width + j ].color[ k ][ 2 ] = 255; verts[ i * m.width + j ].color[ k ][ 3 ] = 255; } } MatchToken( ")" ); } MatchToken( ")" ); // if brush primitives format, we may have some epairs to ignore here GetToken(qtrue); if (g_bBrushPrimit!=BPRIMIT_OLDBRUSHES && strcmp(token,"}")) { // NOTE: we leak that! ep = ParseEPair(); } else UnGetToken(); MatchToken( "}" ); MatchToken( "}" ); /* short circuit */ if( noCurveBrushes || onlyLights ) return; /* ydnar: delete and warn about degenerate patches */ j = (m.width * m.height); VectorClear( delta ); delta[ 3 ] = 0; degenerate = qtrue; /* find first valid vector */ for( i = 1; i < j && delta[ 3 ] == 0; i++ ) { VectorSubtract( m.verts[ 0 ].xyz, m.verts[ i ].xyz, delta ); delta[ 3 ] = VectorNormalize( delta, delta ); } /* secondary degenerate test */ if( delta[ 3 ] == 0 ) degenerate = qtrue; else { /* if all vectors match this or are zero, then this is a degenerate patch */ for( i = 1; i < j && degenerate == qtrue; i++ ) { VectorSubtract( m.verts[ 0 ].xyz, m.verts[ i ].xyz, delta2 ); delta2[ 3 ] = VectorNormalize( delta2, delta2 ); if( delta2[ 3 ] != 0 ) { /* create inverse vector */ VectorCopy( delta2, delta3 ); delta3[ 3 ] = delta2[ 3 ]; VectorNegate( delta3, delta3 ); /* compare */ if( VectorCompare( delta, delta2 ) == qfalse && VectorCompare( delta, delta3 ) == qfalse ) degenerate = qfalse; } } } /* warn and select degenerate patch */ if( degenerate ) { Sys_Warning( mapEnt->mapEntityNum, entitySourceBrushes, "Degenerate patch" ); free( m.verts ); return; } /* find longest curve on the mesh */ longestCurve = 0.0f; maxIterations = 0; for( j = 0; j + 2 < m.width; j += 2 ) { for( i = 0; i + 2 < m.height; i += 2 ) { ExpandLongestCurve( &longestCurve, verts[ i * m.width + j ].xyz, verts[ i * m.width + (j + 1) ].xyz, verts[ i * m.width + (j + 2) ].xyz ); /* row */ ExpandLongestCurve( &longestCurve, verts[ i * m.width + j ].xyz, verts[ (i + 1) * m.width + j ].xyz, verts[ (i + 2) * m.width + j ].xyz ); /* col */ ExpandMaxIterations( &maxIterations, patchSubdivisions, verts[ i * m.width + j ].xyz, verts[ i * m.width + (j + 1) ].xyz, verts[ i * m.width + (j + 2) ].xyz ); /* row */ ExpandMaxIterations( &maxIterations, patchSubdivisions, verts[ i * m.width + j ].xyz, verts[ (i + 1) * m.width + j ].xyz, verts[ (i + 2) * m.width + j ].xyz ); /* col */ } } /* allocate patch mesh */ pm = (parseMesh_t *)safe_malloc( sizeof( *pm ) ); memset( pm, 0, sizeof( *pm ) ); /* ydnar: add entity/brush numbering */ pm->entityNum = mapEnt->mapEntityNum; pm->mapEntityNum = mapEnt->mapEntityNum; pm->brushNum = entitySourceBrushes; /* set shader */ sprintf( shader, "textures/%s", texture ); pm->shaderInfo = ShaderInfoForShader( shader ); /* set mesh */ pm->mesh = m; /* set longest curve */ pm->longestCurve = longestCurve; pm->maxIterations = maxIterations; /* link to the entity */ pm->next = mapEnt->patches; mapEnt->patches = pm; }
/* ================= ParsePatch Creates a mapDrawSurface_t from the patch text ================= */ void ParsePatch( void ) { vec_t info[5]; int i, j; parseMesh_t *pm; char texture[MAX_QPATH]; char shader[MAX_QPATH]; mesh_t m; drawVert_t *verts; epair_t *ep; MatchToken( "{" ); // get texture GetToken (qtrue); strcpy( texture, token ); // save the shader name for retexturing if ( numMapIndexedShaders == MAX_MAP_BRUSHSIDES ) { Error( "MAX_MAP_BRUSHSIDES" ); } strcpy( mapIndexedShaders[numMapIndexedShaders], texture ); numMapIndexedShaders++; Parse1DMatrix( 5, info ); m.width = info[0]; m.height = info[1]; m.verts = verts = malloc( m.width * m.height * sizeof( m.verts[0] ) ); if ( m.width < 0 || m.width > MAX_PATCH_SIZE || m.height < 0 || m.height > MAX_PATCH_SIZE ) { Error("ParsePatch: bad size"); } MatchToken( "(" ); for ( j = 0 ; j < m.width ; j++ ) { MatchToken( "(" ); for ( i = 0 ; i < m.height ; i++ ) { Parse1DMatrix( 5, verts[i*m.width+j].xyz ); } MatchToken( ")" ); } MatchToken( ")" ); // if brush primitives format, we may have some epairs to ignore here GetToken(qtrue); if (g_bBrushPrimit!=BPRIMIT_OLDBRUSHES && strcmp(token,"}")) { // NOTE: we leak that! ep = ParseEpair(); } else UnGetToken(); MatchToken( "}" ); MatchToken( "}" ); if ( noCurveBrushes ) { return; } // find default flags and values pm = malloc( sizeof( *pm ) ); memset( pm, 0, sizeof( *pm ) ); sprintf( shader, "textures/%s", texture ); pm->shaderInfo = ShaderInfoForShader( shader ); pm->mesh = m; // link to the entity pm->next = mapent->patches; mapent->patches = pm; }
static void ClassDefinition(void) { char *name; Int32 label,l1; Int32 field_num=0; SymPtr clas,clas_init; SkipToken(tCLASS); MatchToken(tCONST); name = GetIdent(); clas = SymAdd(name); clas->kind = CLASS_KIND; NextToken(); in_class=TRUE; base_class=clas; cur_scope=SYM_PUBLIC; /* clas->super=NULL; */ /* super_class=NULL; */ clas->super=SymFind("Object"); super_class=clas->super; if( Token==tLSS ) { SkipToken(tLSS); MatchToken(tCONST); name = GetIdent(); clas->super = SymFind(name); if( clas->super==NULL ) { compileError("super class not found"); return; } super_class = clas->super; field_num = clas->super->nlocs; NextToken(); } SymEnterScope(); /* default class constructor prologue */ l1 = vm_genI(op_link,0); clas_init = SymAdd(NEW); clas_init->kind = FUNCTION_KIND; clas_init->object.u.ival = l1; clas_init->flags |= SYM_PUBLIC; /* class fields and functions */ while( TokenIn(class_statements) ) { if( Token==tPUBLIC ) { PublicStatement(); } else if( Token==tPROTECTED ) { ProtectedStatement(); } else if( Token==tPRIVATE ) { PrivateStatement(); } else if( Token==tDEF ) { label = vm_genI(op_jmp,0); MethodDefinition(); vm_patch(label,vm_addr()); } else { local_num = field_num++; AssignmentStatement(); } if( Token==tSEMI ) SkipToken(tSEMI); } clas->nlocs = field_num; /* default class constructor epilogue */ vm_gen0(op_nop); vm_genI(op_rts,2); SymExitScope(clas); /* end of class */ in_class=FALSE; base_class=NULL; super_class=NULL; SkipToken(tEND); if( Token==tSEMI ) SkipToken(tSEMI); }