Add parser state code and skeleton for the parsing procedure.
This commit is contained in:
parent
03f27bda18
commit
6d836a5513
|
@ -8,7 +8,7 @@ project(libabacus)
|
||||||
|
|
||||||
add_compile_options(-pedantic -Wall)
|
add_compile_options(-pedantic -Wall)
|
||||||
|
|
||||||
add_library(abacus STATIC src/lexer.c src/libabacus_util.c src/table.c)
|
add_library(abacus STATIC src/lexer.c src/libabacus_util.c src/table.c src/parser.c)
|
||||||
add_executable(libabacus src/main.c)
|
add_executable(libabacus src/main.c)
|
||||||
add_subdirectory(external/liblex)
|
add_subdirectory(external/liblex)
|
||||||
|
|
||||||
|
|
16
include/parser.h
Normal file
16
include/parser.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef LIBABACUS_PARSER_H
|
||||||
|
#define LIBABACUS_PARSER_H
|
||||||
|
|
||||||
|
#include "table.h"
|
||||||
|
#include "ll.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given list of tokens into the given tree pointer.
|
||||||
|
* @param tokens the tokens to use for parsing.
|
||||||
|
* @param string the string to use for determining token values.
|
||||||
|
* @param store_into tree pointer to store the new data into.
|
||||||
|
*/
|
||||||
|
libab_result parse_tokens(ll* tokens, const char* string, tree** store_into);
|
||||||
|
|
||||||
|
#endif
|
29
src/parser.c
Normal file
29
src/parser.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
struct parser_state {
|
||||||
|
ll_node* current_node;
|
||||||
|
lexer_match* current_match;
|
||||||
|
const char* string;
|
||||||
|
};
|
||||||
|
|
||||||
|
void _parser_state_update(struct parser_state* state) {
|
||||||
|
state->current_match = state->current_node ? state->current_node->data : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _parser_state_init(struct parser_state* state, ll* tokens, const char* string) {
|
||||||
|
state->current_node = tokens->head;
|
||||||
|
state->string = string;
|
||||||
|
_parser_state_update(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _parser_state_step(struct parser_state* state) {
|
||||||
|
if(state->current_node) {
|
||||||
|
state->current_node = state->current_node->next;
|
||||||
|
}
|
||||||
|
_parser_state_update(state);
|
||||||
|
}
|
||||||
|
libab_result parse_tokens(ll* tokens, const char* string, tree** store_into) {
|
||||||
|
libab_result result = LIBAB_SUCCESS;
|
||||||
|
struct parser_state state;
|
||||||
|
_parser_state_init(&state, tokens, string);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user