Beispiel #1
0
int conditional_expression(void) {
	if( logical_or_expression() ) {
	} else if( logical_or_expression() ) {
		match(QUESTION);
		expression();
		match(COLON);
		conditional_expression();
	}
}
Beispiel #2
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;
}
Beispiel #3
0
int logical_or_expression(void) {
	if( logical_and_expression() ) {
	} else if( logical_or_expression() ) {
		match(OR_OP);
		logical_and_expression();
	}
}
Beispiel #4
0
struct Symbol* conditional_expression(struct ConditionalExpression* node)
{
    struct Symbol* symbol = logical_or_expression(node->logicalOrExpression);
    if (node->type == 0)
        return symbol;
    ADDSTRING("  br i1 ");
    code_gen_symbol('%', symbol);
    struct Symbol* label1 = new_symbol("", 0, 0, 0, 0, 0, 0);
    ADDSTRING(", label ");
    code_gen_symbol('%', label1);
    ADDSTRING(", label ");
    char *ch = g_ptr;
    ADDSTRING("      ");
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label1);
    ADDSTRING("\n");
    struct Symbol* symbol1 = load_symbol(expression_func(node->expression));
    ADDSTRING("  br label ");
    char *ch1 = g_ptr;
    ADDSTRING("      ");
    ADDSTRING("\n; <label>:");
    struct Symbol* label2 = new_symbol("", 0, 0, 0, 0, 0, 0);
    code_gen_symbol(0, label2);
    ADDSTRING("\n");
    struct Symbol* symbol2 = load_symbol(expression_func(node->expression));
    ADDSTRING("  br label ");
    struct Symbol* label3 = new_symbol("", 0, 0, 0, 0, 0, 0);
    code_gen_symbol('%', label3);
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label3);
    ADDSTRING("\n");
    symbol = new_symbol("", symbol2->storage, symbol2->qualifier, symbol2->specifier, symbol2->stars, 0, symbol2->length);
    code_gen_symbol('%', symbol);
    ADDSTRING(" = phi ");
    code_gen_type_specifier(symbol->specifier,0,symbol->length,symbol->stars);
    ADDSTRING(" [ ");
    code_gen_symbol('%', symbol1);
    ADDSTRING(", ");
    code_gen_symbol('%', label1);
    ADDSTRING(" ], [ ");
    code_gen_symbol('%', symbol2);
    ADDSTRING(", ");
    code_gen_symbol('%', label2);
    ADDSTRING(" ]\n");
    push_buffer(ch);
    code_gen_symbol('%', label2);
    *g_ptr = ' ';
    pop_buffer();
    push_buffer(ch1);
    code_gen_symbol('%', label3);
    *g_ptr = ' ';
    pop_buffer();
    return symbol;
}
Beispiel #5
0
static struct block *logical_or_expression(struct block *block)
{
    struct block *right;

    block = logical_and_expression(block);
    if (peek().token == LOGICAL_OR) {
        consume(LOGICAL_OR);
        right = cfg_block_init();
        block = eval_logical_or(block, right, logical_or_expression(right));
    }

    return block;
}
Beispiel #6
0
struct Symbol* logical_or_expression(struct LogicalOrExpression* node)
{
    if (node->type == 0)
        return logical_and_expression(node->logicalAndExpression);
    struct Symbol* symbol1 = load_symbol(logical_or_expression(node->logicalOrExpression));
    struct Symbol* symbol2 = load_symbol(logical_and_expression(node->logicalAndExpression));
    struct Symbol* symbol3 = test_calculable2(&symbol1, &symbol2, 'a');
    if (symbol3)
        return symbol3;
    symbol3 = new_symbol("0", 0, 2, 16, 0, 2, 0);
    symbol3 = equality_symbol(symbol1, symbol3, 2, 1);
    ADDSTRING("  br i1 ");
    code_gen_symbol('%', symbol3);
    struct Symbol* label1 = new_symbol("", 0, 0, 0, 0, 0, 0);
    struct Symbol* label2 = new_symbol("", 0, 0, 0, 0, 0, 0);
    ADDSTRING(", label ");
    char *ch = g_ptr;
    ADDSTRING("      ");
    ADDSTRING(", label ");
    code_gen_symbol('%', label1);
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label1);
    ADDSTRING("\n");
    symbol1 = equality_symbol(symbol2, symbol3, 2, 1);
    ADDSTRING("  br label ");
    code_gen_symbol('%', label2);
    ADDSTRING("\n; <label>:");
    code_gen_symbol(0, label2);
    ADDSTRING("\n");
    ADDSTRING("  ");
    symbol2 = new_symbol("", 0, 2, 2, 0, 0, 0);
    code_gen_symbol('%', symbol2);
    ADDSTRING(" = phi i1 [ true, %0 ], [ ");
    code_gen_symbol('%', symbol1);
    ADDSTRING(", ");
    code_gen_symbol('%', label2);
    ADDSTRING(" ]\n");
    push_buffer(ch);
    code_gen_symbol('%', label2);
    *g_ptr = ' ';
    pop_buffer();
    return symbol2;
}
Beispiel #7
0
// Parse a where clause:
//
//    where-clause:
//      'requires' logical-or-expression
Expr&
Parser::requires_clause()
{
  require(tk::requires_tok);
  return logical_or_expression();
}
/*
 * Production: Conditional Expression
 * FIRST set: { AVID_T, FPL_T, INL_T, SVID_T, STR_T }
 */
void conditional_expression(void) {
    logical_or_expression();
    gen_incode("PLATY: Conditional expression parsed");
}
Beispiel #9
0
// Parse an expression.
//
//    expression:
//      logical-or-expression -- FIXME: Probably wrong
Expr&
Parser::expression()
{
  return logical_or_expression();
}