diff options
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -91,6 +91,12 @@ typedef enum { BINARY_MUL, BINARY_DIV, BINARY_COMMA, + BINARY_GT, + BINARY_LT, + BINARY_GE, + BINARY_LE, + BINARY_EQ, + BINARY_NE, BINARY_AT_INDEX /* e.g. x[i] */ } BinaryOp; @@ -232,6 +238,12 @@ static const char *binary_op_to_str(BinaryOp b) { case BINARY_SET: return "="; case BINARY_COMMA: return ","; case BINARY_AT_INDEX: return "[]"; + case BINARY_LT: return "<"; + case BINARY_LE: return "<="; + case BINARY_GT: return ">"; + case BINARY_GE: return ">="; + case BINARY_EQ: return "=="; + case BINARY_NE: return "!="; } assert(0); return ""; @@ -386,6 +398,12 @@ static Expression *parser_new_expr(Parser *p) { static int op_precedence(Keyword op) { switch (op) { case KW_EQ: return 0; + case KW_LT: return 3; + case KW_GT: return 3; + case KW_LE: return 3; + case KW_GE: return 3; + case KW_EQEQ: return 3; + case KW_NE: return 3; case KW_COMMA: return 5; case KW_PLUS: return 10; case KW_MINUS: return 20; @@ -1125,6 +1143,24 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) { case KW_MINUS: op = BINARY_MINUS; break; + case KW_EQEQ: + op = BINARY_EQ; + break; + case KW_NE: + op = BINARY_NE; + break; + case KW_LT: + op = BINARY_LT; + break; + case KW_LE: + op = BINARY_LE; + break; + case KW_GT: + op = BINARY_GT; + break; + case KW_GE: + op = BINARY_GE; + break; case KW_EQ: op = BINARY_SET; break; |