diff --git a/src/main.c b/src/main.c index e548360..c8988ca 100644 --- a/src/main.c +++ b/src/main.c @@ -32,7 +32,10 @@ static int main_loop(struct lexer_context *ctx, struct args_options *options, { int return_code = SUCCESS; // init parser - int parser_init(); + if (!parser_init()) + { + perror("parser initialization failed."); + } // Retrieve and build first AST struct ast *command_ast = get_ast(ctx); diff --git a/src/parser/grammar.c b/src/parser/grammar.c index 33551f5..b734c7b 100644 --- a/src/parser/grammar.c +++ b/src/parser/grammar.c @@ -186,7 +186,10 @@ struct ast *parse_input(struct lexer_context *ctx) struct token *token = PEEK_TOKEN(); if (token->type == TOKEN_EOF) - return ast_create_list(NULL); + { + POP_TOKEN(); + return ast_create_end(); + } if (token->type == TOKEN_NEWLINE) { diff --git a/src/parser/grammar_advanced.c b/src/parser/grammar_advanced.c index aef3c27..faa2f5e 100644 --- a/src/parser/grammar_advanced.c +++ b/src/parser/grammar_advanced.c @@ -22,6 +22,9 @@ static enum ast_redir_type redir_tok_to_ast_type(enum token_type tok_type) struct ast *parse_redirection(struct lexer_context *ctx) { + (void)ctx; + return NULL; + /* struct token *token = PEEK_TOKEN(); int io_number = -1; if (token->type == TOKEN_IONUMBER) @@ -53,6 +56,7 @@ struct ast *parse_redirection(struct lexer_context *ctx) POP_TOKEN(); return ast_create_redir(io_number, redir_type, target); + */ } struct ast *parse_prefix(struct lexer_context *ctx) diff --git a/src/parser/parser.c b/src/parser/parser.c index b71867a..e5c5f94 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -25,6 +25,16 @@ bool parser_init(void) return true; } +void parser_close(void) +{ + if (state != PARSER_STATE_READY) + { + perror("trying to close parser which was not opened"); + } + state = PARSER_STATE_CLOSED; + // TODO close grammar +} + struct ast *get_ast(struct lexer_context *ctx) { if (ctx == NULL) diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index 65cc594..c2cf250 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -14,6 +14,9 @@ libutils_a_SOURCES = \ ast/ast_redir.c \ ast/ast_void.c \ ast/ast_end.c \ + ast/ast_word.c \ + ast/ast_neg.c \ + ast/ast_pipe.c \ args/args.c \ vars/vars.c diff --git a/src/utils/ast/ast.h b/src/utils/ast/ast.h index cbb5efc..334820b 100644 --- a/src/utils/ast/ast.h +++ b/src/utils/ast/ast.h @@ -11,6 +11,7 @@ #include "ast_void.h" #include "ast_word.h" #include "ast_pipe.h" +#include "ast_neg.h" /** * Prints the Graphviz DOT representation of the given AST to stdout. diff --git a/src/utils/ast/ast_base.h b/src/utils/ast/ast_base.h index 341b380..127dad7 100644 --- a/src/utils/ast/ast_base.h +++ b/src/utils/ast/ast_base.h @@ -29,6 +29,7 @@ struct ast * - struct ast_command* (AST_CMD) * - struct ast_and_or* (AST_AND_OR) * - struct ast_redir* (AST_REDIR) + * - and a lot more now... */ void *data; }; diff --git a/src/utils/ast/ast_command.c b/src/utils/ast/ast_command.c index 2b6bbf6..14904ae 100644 --- a/src/utils/ast/ast_command.c +++ b/src/utils/ast/ast_command.c @@ -18,7 +18,7 @@ struct ast *ast_create_command(struct list *command) struct ast_command *ast_get_command(struct ast *node) { - if (node == NULL || node->type == AST_CMD) + if (node == NULL || node->type != AST_CMD) return NULL; return (struct ast_command *)node->data; } diff --git a/src/utils/ast/ast_neg.c b/src/utils/ast/ast_neg.c index f5817fc..80dc4f3 100644 --- a/src/utils/ast/ast_neg.c +++ b/src/utils/ast/ast_neg.c @@ -4,7 +4,7 @@ bool ast_is_neg(struct ast *node) { - return node != NULL && node->type == AST_REDIR; + return node != NULL && node->type == AST_NEG; } struct ast_neg *ast_get_neg(struct ast *node) @@ -20,6 +20,8 @@ struct ast *ast_create_neg(bool negation, struct ast *child) if (!node) return NULL; + node->negation = negation; + node->child = child; return ast_create(AST_NEG, node); } diff --git a/src/utils/ast/ast_word.c b/src/utils/ast/ast_word.c index d798c77..957952c 100644 --- a/src/utils/ast/ast_word.c +++ b/src/utils/ast/ast_word.c @@ -1,5 +1,7 @@ +#define _POSIX_C_SOURCE 200809L #include "ast_word.h" +#include #include #include #include