示例#1
0
int PP_Expression::conditional_expression()
{
    int value = logical_OR_expression();
    if (test(PP_QUESTION)) {
        int alt1 = conditional_expression();
        int alt2 = test(PP_COLON) ? conditional_expression() : 0;
        return value ? alt1 : alt2;
    }
    return value;
}
Expression *ExpressionBuilder::conditional_expression()
{
    Expression *value = logical_OR_expression();
    if (test('?')) {
        Expression *leftExpression = conditional_expression();
        Expression *rightExpression;
        if(test(':'))
            rightExpression = conditional_expression();
        else
            rightExpression = createIntLiteral(0);
        return createConditionalExpression(value, leftExpression, rightExpression);
    }
    return value;
}
示例#3
0
文件: parser.c 项目: palmerc/lab
int assignment_expression(void) {
	if( conditional_expression() ) {
	} else if( unary_expression() ) {
		assignment_operator();
		assignment_expression();
	}
}
示例#4
0
static struct block *conditional_expression(struct block *block)
{
    block = logical_or_expression(block);
    if (peek().token == '?') {
        struct var condition = block->expr;
        struct block
            *t = cfg_block_init(),
            *f = cfg_block_init(),
            *next = cfg_block_init();

        consume('?');
        block->jump[0] = f;
        block->jump[1] = t;

        t = expression(t);
        t->jump[0] = next;

        consume(':');
        f = conditional_expression(f);
        f->jump[0] = next;

        next->expr = eval_conditional(condition, t, f);
        block = next;
    }

    return block;
}
Rpp::Expression *ExpressionBuilder::parse()
{
    if(unary_expression_lookup())
        return conditional_expression();
    else
        return createIntLiteral(0);
}
示例#6
0
struct block *assignment_expression(struct block *block)
{
    struct var target;

    block = conditional_expression(block);
    target = block->expr;
    switch (peek().token) {
    case '=':
        consume('=');
        block = assignment_expression(block);
        break;
    case MUL_ASSIGN:
        consume(MUL_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_MUL, target, block->expr);
        break;
    case DIV_ASSIGN:
        consume(DIV_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_DIV, target, block->expr);
        break;
    case MOD_ASSIGN:
        consume(MOD_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_MOD, target, block->expr);
        break;
    case PLUS_ASSIGN:
        consume(PLUS_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_ADD, target, block->expr);
        break;
    case MINUS_ASSIGN:
        consume(MINUS_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_SUB, target, block->expr);
        break;
    case AND_ASSIGN:
        consume(AND_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_AND, target, block->expr);
        break;
    case OR_ASSIGN:
        consume(OR_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_OR, target, block->expr);
        break;
    case XOR_ASSIGN:
        consume(XOR_ASSIGN);
        block = assignment_expression(block);
        block->expr = eval_expr(block, IR_OP_XOR, target, block->expr);
        break;
    default:
        return block;
    }

    block->expr = eval_assign(block, target, block->expr);
    return block;
}
示例#7
0
文件: parser.c 项目: palmerc/lab
int conditional_expression(void) {
	if( logical_or_expression() ) {
	} else if( logical_or_expression() ) {
		match(QUESTION);
		expression();
		match(COLON);
		conditional_expression();
	}
}
示例#8
0
int PP_Expression::primary_expression()
{
    int value;
    if (test(PP_LPAREN)) {
        value = conditional_expression();
        test(PP_RPAREN);
    } else {
        next();
        value = lexem().toInt(0, 0);
    }
    return value;
}
/*
 * Production: Selection Statement
 * FIRST set: { KW_T (only IF) }
 */
void selection_statement(void) {
    match(KW_T, IF);
    match(LPR_T, NO_ATTR);
    conditional_expression();
    match(RPR_T, NO_ATTR);
    match(KW_T, THEN);
    opt_statements();
    match(KW_T, ELSE);
    match(LBR_T, NO_ATTR);
    opt_statements();
    match(RBR_T, NO_ATTR);
    match(EOS_T, NO_ATTR);
    gen_incode("PLATY: IF statement parsed");
}
示例#10
0
struct var constant_expression(void)
{
    struct block
        *head = cfg_block_init(),
        *tail;

    tail = conditional_expression(head);
    if (tail != head || tail->expr.kind != IMMEDIATE) {
        error("Constant expression must be computable at compile time.");
        exit(1);
    }

    return tail->expr;
}
示例#11
0
/* FIRST(selection statement)={IF}
<selection statement> ->
	IF (<conditional expression>) THEN <opt_statements> 
	ELSE { <opt_statements> } ; 
Author: Kyle Hinskens */
void selection_statement(void){
	if (lookahead_token.attribute.get_int == IF){
		match(KW_T,IF);
		match(LPR_T,NO_ATTR);
		conditional_expression();
		match(RPR_T,NO_ATTR);
		match(KW_T,THEN);
		opt_statements();
		match(KW_T,ELSE);
		match(LBR_T,NO_ATTR);
		opt_statements();
		match(RBR_T,NO_ATTR);
		match(EOS_T,NO_ATTR);
		gen_incode("IF statement parsed");
	}
}
示例#12
0
/*
 * Production: Iteration Statement
 * FIRST set: { KW_T (only USING) }
 */
void iteration_statement(void) {
    match(KW_T, USING);
    match(LPR_T, NO_ATTR);
    assignment_expression();
    match(COM_T, NO_ATTR);
    conditional_expression();
    match(COM_T, NO_ATTR);
    assignment_expression();
    match(RPR_T, NO_ATTR);
    match(KW_T, REPEAT);
    match(LBR_T, NO_ATTR);
    opt_statements();
    match(RBR_T, NO_ATTR);
    match(EOS_T, NO_ATTR);
    gen_incode("PLATY: USING statement parsed");
}
示例#13
0
/* FIRST(iteration statement)={USING}
<iteration statement> ->
	USING (<assignment expression>, <conditional expression>, <assignment expression>) 
		REPEAT {
			< opt_statements>
		};
Author: Kwok Hong Kelvin Chan */
void iteration_statement(void) {
	if (lookahead_token.code == KW_T && lookahead_token.attribute.get_int == USING) {
		match(KW_T,USING);
		match(LPR_T,NO_ATTR);
		assignment_expression();
		match(COM_T, NO_ATTR);
		conditional_expression();
		match(COM_T, NO_ATTR);
		assignment_expression();
		match(RPR_T,NO_ATTR);
		match(KW_T,REPEAT);
		match(LBR_T,NO_ATTR);
		opt_statements();
		match(RBR_T,NO_ATTR);
		match(EOS_T,NO_ATTR);
		gen_incode("USING statement parsed");
	}
}
Expression *ExpressionBuilder::primary_expression()
{
    Expression *value;
    if (test('(')) {
        if (moreTokens(1))
            value = conditional_expression();
        else
            value = createIntLiteral(0); // Syntax error.
        test(')');
    } else {
        next();
        bool ok;
        int val  = QString::fromLatin1(lexem()).toInt(&ok, 0);
        if(ok)
            value = createIntLiteral(val);
        else
            value = createMacroReference(MacroReference::ValueRef, createTokenList(i -1));
    }
    return value;
}
示例#15
0
struct Symbol* assignment_expression(struct AssignmentExpression* node)
{
    if (node->type == 0)
        return conditional_expression(node->conditionalExpression);
    // to do
    struct Symbol* orig_symbol;
    struct Symbol* symbol2 = load_symbol(assignment_expression(node->assignmentExpression));
    struct Symbol* symbol1 = unary_expression(node->unaryExpression, &orig_symbol);
    struct Symbol* symbol3 = 0;
    int specifier = symbol1->specifier;

    test_changeable(orig_symbol);
    if (node->assignmentOperator > 1)
    {
        switch (node->assignmentOperator) {
            case 2:
                symbol3 = multiplicative_symbol(symbol1, symbol2, 1);
                break;
            case 3:
                symbol3 = multiplicative_symbol(symbol1, symbol2, 2);
                break;
            case 4:
                symbol3 = multiplicative_symbol(symbol1, symbol2, 3);
                break;
            case 5:
                symbol3 = additive_symbol(symbol1, symbol2, 1);
                break;
            case 6:
                symbol3 = additive_symbol(symbol1, symbol2, 2);
                break;
            case 7:
                symbol3 = shift_symbol(symbol1, symbol2, 1);
                break;
            case 8:
                symbol3 = shift_symbol(symbol1, symbol2, 2);
                break;
            case 9:
                symbol3 = and_symbol(symbol1, symbol2, 1);
                break;
            case 10:
                symbol3 = exclusive_or_symbol(symbol1, symbol2, 1);
                break;
            case 11:
                symbol3 = inclusive_or_symbol(symbol1, symbol2, 1);
                break;
            default:
                break;
        }
    }
    else
        symbol3 = symbol2;
    
    symbol3 = cast_symbol(symbol3, orig_symbol->specifier, orig_symbol->stars);
    ADDSTRING("  store ");
    code_gen_type_specifier(symbol1->specifier,0,symbol1->length,symbol1->stars);
    ADDSTRING(" ");
    code_gen_symbol('%', symbol3);
    ADDSTRING(", ");
    code_gen_type_specifier(orig_symbol->specifier,0,orig_symbol->length,orig_symbol->stars);
    ADDSTRING("* ");
    code_gen_symbol('%',orig_symbol);
    ADDSTRING(", align ");
    int l = len_gen_type_specifier(specifier);
    sprintf(buf, "%d", l);
    ADDSTRING(buf);
    ADDSTRING("\n");
    return symbol3;
}
示例#16
0
 int value() { index = 0; return unary_expression_lookup() ?  conditional_expression() : 0; }
示例#17
0
文件: parser.c 项目: palmerc/lab
int constant_expression(void) {
	conditional_expression();
}
示例#18
0
struct Symbol* constant_expression(struct ConstantExpression* node)
{
    return conditional_expression(node->conditionalExpression);
}