#include "syntax.h" #include #include #include #include #include #include enum bshell_status bshell_parse_ctx_init(struct bshell_parse_ctx *ctx, struct bshell_lex_ctx *src) { memset(ctx, 0x0, sizeof *ctx); ctx->p_src = src; return BSHELL_SUCCESS; } void bshell_parse_ctx_cleanup(struct bshell_parse_ctx *ctx) { } struct bshell_ast_node *bshell_parse_ctx_read_node(struct bshell_parse_ctx *ctx) { parse_symbol(ctx, BSHELL_SYM_SEMICOLON); parse_linefeed(ctx); struct bshell_ast_node *result = NULL; bool ok = parse_statement(ctx, &result); return ok ? result : NULL; } void report_error(struct bshell_parse_ctx *ctx, const char *format, ...) { ctx->p_status = BSHELL_ERR_BAD_SYNTAX; fprintf(stderr, "PARSE: "); va_list arg; va_start(arg, format); vfprintf(stderr, format, arg); va_end(arg); fprintf(stderr, "\n"); struct bshell_lex_token *tok = peek_token(ctx); fprintf(stderr, " peek_token = "); #if 0 if (tok) { print_bshell_lex_token(tok); } else { fprintf(stderr, " EOF\n"); } #endif }