Start work on implementing parser runtime
This commit is contained in:
parent
0985fa3008
commit
5813816179
8 changed files with 249 additions and 160 deletions
|
|
@ -1,49 +1,63 @@
|
|||
#include "runtime.h"
|
||||
|
||||
|
||||
static int INITIAL_STATE_STACK_SIZE = 100;
|
||||
static int INITIAL_SYMBOL_STACK_SIZE = 100;
|
||||
#include "parser.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static int INITIAL_STACK_SIZE = 100;
|
||||
|
||||
TSParser TSParserMake(const char *input) {
|
||||
TSState *state_stack = calloc(INITIAL_STATE_STACK_SIZE, sizeof(*state_stack));
|
||||
TSSymbol *symbol_stack = calloc(INITIAL_SYMBOL_STACK_SIZE, sizeof(*symbol_stack));
|
||||
TSParser result = {
|
||||
.input = input,
|
||||
.tree = TSTreeMake(),
|
||||
.input = input,
|
||||
.position = 0,
|
||||
.state_stack = state_stack,
|
||||
.symbol_stack = symbol_stack,
|
||||
.state_count = 0,
|
||||
.symbol_count = 0
|
||||
.lookahead_sym = 0,
|
||||
.lex_state = 0,
|
||||
.stack = calloc(INITIAL_STACK_SIZE, sizeof(TSStackEntry)),
|
||||
.stack_size = 0,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
void TSParserShift(TSParser *parser, TSState state) {
|
||||
|
||||
void TSParserShift(TSParser *parser, TSState parse_state) {
|
||||
TSStackEntry *entry = (parser->stack + parser->stack_size);
|
||||
entry->state = parse_state;
|
||||
entry->symbol = parser->lookahead_sym;
|
||||
parser->lookahead_sym = -1;
|
||||
parser->stack_size++;
|
||||
}
|
||||
|
||||
void TSParserReduce(TSParser *parser, TSSymbol symbol, int child_count) {
|
||||
|
||||
parser->lookahead_sym = symbol;
|
||||
parser->stack_size -= child_count;
|
||||
}
|
||||
|
||||
void TSParserError(TSParser *parser) {
|
||||
|
||||
}
|
||||
|
||||
TSSymbol TSParserLookahead(const TSParser *parser) {
|
||||
return 1;
|
||||
void TSParserAdvance(TSParser *parser, TSState lex_state) {
|
||||
parser->position++;
|
||||
parser->lex_state = lex_state;
|
||||
}
|
||||
|
||||
char TSParserLookaheadChar(const TSParser *parser) {
|
||||
return parser->input[parser->position];
|
||||
}
|
||||
|
||||
TSSymbol TSParserLookaheadSym(const TSParser *parser) {
|
||||
return parser->lookahead_sym;
|
||||
}
|
||||
|
||||
void TSParserSetLookaheadSym(TSParser *parser, TSSymbol symbol) {
|
||||
parser->lookahead_sym = symbol;
|
||||
}
|
||||
|
||||
TSState TSParserParseState(const TSParser *parser) {
|
||||
return 5;
|
||||
return parser->stack[parser->stack_size - 1].state;
|
||||
}
|
||||
|
||||
TSState TSParserLexState(const TSParser *parser) {
|
||||
return 5;
|
||||
return parser->lex_state;
|
||||
}
|
||||
|
||||
void TSParserSetLexState(const TSParser *parser, TSState lex_state) {
|
||||
|
||||
void TSParserSetLexState(TSParser *parser, TSState lex_state) {
|
||||
parser->lex_state = lex_state;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue