Make distinction between prefix and postfix unary operators in trees.
This commit is contained in:
parent
4e86ccc253
commit
7ab5eba529
|
@ -15,7 +15,8 @@ enum libab_tree_variant_e {
|
|||
TREE_NUM,
|
||||
TREE_OP,
|
||||
TREE_RESERVED_OP,
|
||||
TREE_UNARY_OP,
|
||||
TREE_PREFIX_OP,
|
||||
TREE_POSTFIX_OP,
|
||||
TREE_BLOCK,
|
||||
TREE_VOID,
|
||||
TREE_IF,
|
||||
|
|
|
@ -10,7 +10,8 @@ const char* _debug_node_name(libab_tree_variant var) {
|
|||
"num",
|
||||
"op",
|
||||
"reserved_op",
|
||||
"unary_op",
|
||||
"prefix_op",
|
||||
"postfix_op",
|
||||
"block",
|
||||
"void",
|
||||
"if",
|
||||
|
|
|
@ -721,8 +721,10 @@ libab_result _parser_construct_op(struct parser_state* state, libab_lexer_match*
|
|||
(*into)->variant = TREE_OP;
|
||||
} else if(match->type == TOKEN_OP_RESERVED) {
|
||||
(*into)->variant = TREE_RESERVED_OP;
|
||||
} else if(match->type == TOKEN_OP_PREFIX) {
|
||||
(*into)->variant = TREE_PREFIX_OP;
|
||||
} else {
|
||||
(*into)->variant = TREE_UNARY_OP;
|
||||
(*into)->variant = TREE_POSTFIX_OP;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -828,7 +830,7 @@ libab_result _parser_expression_tree(struct parser_state* state, ll* source, lib
|
|||
free(top);
|
||||
top = NULL;
|
||||
}
|
||||
} else if(top->variant == TREE_UNARY_OP || top->variant == TREE_CALL) {
|
||||
} else if(top->variant == TREE_PREFIX_OP || top->variant == TREE_POSTFIX_OP || top->variant == TREE_CALL) {
|
||||
libab_tree* child = NULL;
|
||||
|
||||
result = _parser_expression_tree(state, source, &child);
|
||||
|
@ -839,7 +841,7 @@ libab_result _parser_expression_tree(struct parser_state* state, ll* source, lib
|
|||
|
||||
if(result != LIBAB_SUCCESS) {
|
||||
if(child) libab_tree_free_recursive(child);
|
||||
if(top->variant == TREE_UNARY_OP) {
|
||||
if(top->variant == TREE_PREFIX_OP || top->variant == TREE_POSTFIX_OP) {
|
||||
libab_tree_free(top);
|
||||
free(top);
|
||||
} else {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
int libab_tree_has_vector(libab_tree_variant variant) {
|
||||
return variant == TREE_BASE || variant == TREE_OP ||
|
||||
variant == TREE_UNARY_OP || variant == TREE_BLOCK ||
|
||||
variant == TREE_PREFIX_OP || variant == TREE_POSTFIX_OP || variant == TREE_BLOCK ||
|
||||
variant == TREE_IF || variant == TREE_CALL || variant == TREE_WHILE ||
|
||||
variant == TREE_DOWHILE || variant == TREE_FUN ||
|
||||
variant == TREE_RETURN || variant == TREE_RESERVED_OP;
|
||||
|
@ -11,7 +11,7 @@ int libab_tree_has_vector(libab_tree_variant variant) {
|
|||
|
||||
int libab_tree_has_string(libab_tree_variant variant) {
|
||||
return variant == TREE_ID || variant == TREE_NUM ||
|
||||
variant == TREE_OP || variant == TREE_UNARY_OP ||
|
||||
variant == TREE_OP || variant == TREE_PREFIX_OP || variant == TREE_POSTFIX_OP ||
|
||||
variant == TREE_FUN || variant == TREE_FUN_PARAM ||
|
||||
variant == TREE_RESERVED_OP;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user