From: NeilBrown Date: Wed, 10 Mar 2021 00:12:50 +0000 (+1100) Subject: parsergen: split out heart-of-the-parser code X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=29614f479bd2539b7401dc2e5b0df649727a15d8 parsergen: split out heart-of-the-parser code This finishes the break up of the core parser code. Signed-off-by: NeilBrown --- diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 4708e0c..554e63c 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -2724,6 +2724,28 @@ Now we have the parser. For each token we might shift it, trigger a reduction, or start error handling. 2D tokens (IN, OUT, EOL) also need to be handled. +###### parser vars + + struct parser p = { 0 }; + struct token *tk = NULL; + int accepted = 0; + +###### heart of parser + + shift(&p, TK_eof, NULL, states); + while (!accepted && p.tos > 0) { + struct frame *tos = &p.stack[p.tos-1]; + if (!tk) + tk = tok_copy(token_next(tokens)); + parser_trace(trace, &p, + tk, states, non_term, config->known_count); + + ## try shift or ignore + ## try reduce + ## handle error + } + + We return whatever `asn` was returned by reducing production zero. When we find `TK_in` and `TK_out` tokens which report indents we need @@ -2899,23 +2921,10 @@ dropping tokens until either we manage to shift one, or reach end-of-file. FILE *trace, const char *non_term[], struct token_config *config) { - struct parser p = { 0 }; - struct token *tk = NULL; - int accepted = 0; ## parser vars - shift(&p, TK_eof, NULL, states); - while (!accepted && p.tos > 0) { - struct frame *tos = &p.stack[p.tos-1]; - if (!tk) - tk = tok_copy(token_next(tokens)); - parser_trace(trace, &p, - tk, states, non_term, config->known_count); + ## heart of parser - ## try shift or ignore - ## try reduce - ## handle error - } free(tk); pop(&p, p.tos, do_free); free(p.asn_stack);