예제 #1
0
void addNewRule(vector<SPExpression> symbolAndExpr) {
    
    auto oldCount = countRules();
    auto newRule = makeExpression(ruleSymbol, std::move(symbolAndExpr));
    assert(symbolAndExpr.empty());
    auto ruleset = getAndDetachEachSubexpressionAndDeallocate(std::move(rules));

    ruleset.push_back(std::move(newRule));
    rules = makeExpression(rulesSymbol, std::move(ruleset));
    assert(ruleset.empty());

    assert(countRules() == oldCount + 1);
    
    store();
}
예제 #2
0
void init() {
    assert(!rules);
    if (!(rules = fileDepersist(rulesFilename))) {
        rules = makeExpression(rulesSymbol);
        assert(!countRules());
    }
    validateRules();
}
예제 #3
0
static AIExpType_t *Primary( pc_token_list **list )
{
	pc_token_list *current = *list;
	AIExpType_t *tree = nullptr;

	if ( isUnaryOp( opTypeFromToken( &current->token ) ) )
	{
		AIExpType_t *t;
		AIOp_t *op = newOp( current );
		*list = current->next;
		t = ReadConditionExpression( list, op->opType );

		if ( !t )
		{
			Log::Warn( "Missing right operand for %s on line %d", opTypeToString( op->opType ), current->token.line );
			FreeOp( op );
			return nullptr;
		}

		tree = makeExpression( op, t, nullptr );
	}
	else if ( current->token.string[0] == '(' )
	{
		*list = current->next;
		tree = ReadConditionExpression( list, OP_NONE );
		if ( !expectToken( ")", list, true ) )
		{
			return nullptr;
		}
	}
	else if ( current->token.type == tokenType_t::TT_NUMBER )
	{
		tree = ( AIExpType_t * ) newValueLiteral( list );
	}
	else if ( current->token.type == tokenType_t::TT_NAME )
	{
		tree = ( AIExpType_t * ) newValueFunc( list );
	}
	else
	{
		Log::Warn( "token %s on line %d is not valid", current->token.string, current->token.line );
	}
	return tree;
}
예제 #4
0
static AIExpType_t *ReadConditionExpression( pc_token_list **list, AIOpType_t op2 )
{
	AIExpType_t *t;
	AIOpType_t  op;

	if ( !*list )
	{
		Log::Warn( "Unexpected end of file" );
		return nullptr;
	}

	t = Primary( list );

	if ( !t )
	{
		return nullptr;
	}

	op = opTypeFromToken( &(*list)->token );

	while ( isBinaryOp( op ) && opCompare( op, op2 ) >= 0 )
	{
		AIExpType_t *t1;
		pc_token_list *prev = *list;
		AIOp_t *exp = newOp( *list );
		*list = (*list)->next;
		t1 = ReadConditionExpression( list, op );

		if ( !t1 )
		{
			Log::Warn( "Missing right operand for %s on line %d", opTypeToString( op ), prev->token.line );
			FreeExpression( t );
			FreeOp( exp );
			return nullptr;
		}

		t = makeExpression( exp, t, t1 );

		op = opTypeFromToken( &(*list)->token );
	}

	return t;
}