Add initial code for statement parsing.
This commit is contained in:
parent
0958ecd1eb
commit
31329a13a6
33
src/parser.c
33
src/parser.c
|
@ -32,6 +32,10 @@ int _parser_is_char(struct parser_state* state, char to_expect) {
|
|||
state->string[state->current_match->from] == to_expect);
|
||||
}
|
||||
|
||||
int _parser_is_type(struct parser_state* state, lexer_token to_expect) {
|
||||
return (state->current_match && state->current_match->type == to_expect);
|
||||
}
|
||||
|
||||
int _parser_eof(struct parser_state* state) {
|
||||
return state->current_match == NULL;
|
||||
}
|
||||
|
@ -49,11 +53,36 @@ libab_result _parser_consume_char(struct parser_state* state, char to_consume) {
|
|||
return result;
|
||||
}
|
||||
|
||||
libab_result _parse_block(struct parser_state*, tree**, int);
|
||||
|
||||
libab_result _parse_expression(struct parser_state* state, tree** store_into) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
return result;
|
||||
}
|
||||
|
||||
libab_result _parse_statement(struct parser_state* state, tree** store_into) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
|
||||
if(_parser_is_char(state, '{')) result = _parse_block(state, store_into, 1);
|
||||
else if(_parser_is_type(state, TOKEN_ID) ||
|
||||
_parser_is_type(state, TOKEN_NUM) ||
|
||||
_parser_is_type(state, TOKEN_STR) ||
|
||||
_parser_is_type(state, TOKEN_CHAR_LIT) ||
|
||||
_parser_is_type(state, TOKEN_TRUE) ||
|
||||
_parser_is_type(state, TOKEN_FALSE) ||
|
||||
_parser_is_char(state, '(') ||
|
||||
_parser_is_type(state, TOKEN_OP_PREFIX)) {
|
||||
result = _parse_expression(state, store_into);
|
||||
if(result == LIBAB_SUCCESS) result = _parser_consume_char(state, ';');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
libab_result _parse_block(struct parser_state* state,
|
||||
tree** store_into, int expect_braces) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
*store_into = malloc(sizeof(**store_into));
|
||||
if(*store_into == NULL) result = LIBAB_MALLOC;
|
||||
if((*store_into = malloc(sizeof(**store_into))) == NULL) result = LIBAB_MALLOC;
|
||||
|
||||
if(expect_braces && result == LIBAB_SUCCESS) result = _parser_consume_char(state, '{');
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user