Exemple #1
0
/**
加减类表达式
<additive_expression>::=<multiplicative_expression>
                        {<TK_PLUS><multiplicative_expression>
                        |<TK_MINUS><multiplicative_expression>}
*/
void additive_expression(){
    multiplicative_expression();
    while(TK_PLUS == token || TK_MINUS == token){
        get_token();
        multiplicative_expression();
    }
}
Exemple #2
0
struct Symbol* additive_expression(struct AdditiveExpression* node)
{
    if (node->type == 0)
        return multiplicative_expression(node->multiplicativeExpression);
    struct Symbol* symbol1 = load_symbol(additive_expression(node->additiveExpression));
    struct Symbol* symbol2 = load_symbol(multiplicative_expression(node->multiplicativeExpression));
    return additive_symbol(symbol1, symbol2, node->type);
}
Expression *ExpressionBuilder::multiplicative_expression()
{
    Expression *value = unary_expression();
    switch (next()) {
    case '*':
        return createBinaryExpression('*', value, multiplicative_expression());
    case '%':
        return createBinaryExpression('%', value, multiplicative_expression());
    case '/':
        return createBinaryExpression('/', value, multiplicative_expression());
    default:
        prev();
        return value;
    };
}
Exemple #4
0
int additive_expression(void) {
	if( multiplicative_expression() ) {
	} else if( additive_expression() ) {
		switch( lookaheadT.type ) {
			case PLUS:
				match(PLUS);
				break;
			case MINUS:
				match(MINUS);
				break;
		}
		multiplicative_expression();
	} else {
		abort();
	}
}
Exemple #5
0
// Parse an additive expression.
//
//    additive-expression:
//      multiplicative-expression:
//      additive-expression '+' multiplicative-expression
//      additive-expression '-' multiplicative-expression
Expr&
Parser::additive_expression()
{
  Expr* e1 = &multiplicative_expression();
  while (true) {
    if (Token tok = match_if(tk::plus_tok)) {
      Expr& e2 = multiplicative_expression();
      e1 = &on_add_expression(tok, *e1, e2);
    } else if (Token tok = match_if(tk::minus_tok)) {
      Expr& e2 = unary_expression();
      e1 = &on_sub_expression(tok, *e1, e2);
    } else {
      break;
    }
  }
  return *e1;
}
Exemple #6
0
struct Symbol* multiplicative_expression(struct MultiplicativeExpression* node)
{
    if (node->type == 0)
        return cast_expression(node->castExpression);
    struct Symbol* symbol1 = load_symbol(multiplicative_expression(node->multiplicativeExpression));
    struct Symbol* symbol2 = load_symbol(cast_expression(node->castExpression));
    return multiplicative_symbol(symbol1, symbol2, node->type);
}
Exemple #7
0
static struct block *additive_expression(struct block *block)
{
    struct var value;

    block = multiplicative_expression(block);
    while (1) {
        value = block->expr;
        if (peek().token == '+') {
            consume('+');
            block = multiplicative_expression(block);
            block->expr = eval_expr(block, IR_OP_ADD, value, block->expr);
        } else if (peek().token == '-') {
            consume('-');
            block = multiplicative_expression(block);
            block->expr = eval_expr(block, IR_OP_SUB, value, block->expr);
        } else break;
    }

    return block;
}
Exemple #8
0
int PP_Expression::multiplicative_expression()
{
    int value = unary_expression();
    switch (next()) {
    case PP_STAR:
        return value * multiplicative_expression();
    case PP_PERCENT:
    {
        int remainder = multiplicative_expression();
        return remainder ? value % remainder : 0;
    }
    case PP_SLASH:
    {
        int div = multiplicative_expression();
        return div ? value / div : 0;
    }
    default:
        prev();
        return value;
    };
}
Exemple #9
0
int PP_Expression::additive_expression()
{
    int value = multiplicative_expression();
    switch (next()) {
    case PP_PLUS:
        return value + additive_expression();
    case PP_MINUS:
        return value - additive_expression();
    default:
        prev();
        return value;
    }
}
Expression *ExpressionBuilder::additive_expression()
{
    Expression *value = multiplicative_expression();
    switch (next()) {
    case '+':
        return createBinaryExpression('+', value, additive_expression());
    case '-':
        return createBinaryExpression('-', value, additive_expression());
    default:
        prev();
        return value;
    }
}
Exemple #11
0
int multiplicative_expression(void) {
	if(	cast_expression() ) {
	} else if (	multiplicative_expression() ) {
		switch( lookaheadT.type ) {
			case ASTERIX:
				match(ASTERIX);
				break;
			case FSLASH:	
				match(FSLASH);
				break;
			case PERCENT:
				match(PERCENT);
				break;
		}
		cast_expression();
	} else {
		abort();
	}
}