fix(parser): rule if now works
This commit is contained in:
parent
2f2509f1c9
commit
5faa179b63
2 changed files with 18 additions and 13 deletions
|
|
@ -2,8 +2,8 @@
|
|||
#define EXECUTION_H
|
||||
|
||||
#include "../utils/ast/ast.h"
|
||||
#include "../utils/lists/lists.h"
|
||||
#include "../utils/hash_map/hash_map.h"
|
||||
#include "../utils/lists/lists.h"
|
||||
|
||||
/**
|
||||
* @brief Execute the AST
|
||||
|
|
|
|||
|
|
@ -247,31 +247,34 @@ struct ast *parse_compound_list(struct lexer_context *ctx)
|
|||
while (token->type == TOKEN_NEWLINE)
|
||||
{
|
||||
token = POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
// and_or
|
||||
current_cmd = parse_and_or(ctx);
|
||||
if (current_cmd == NULL)
|
||||
return NULL;
|
||||
list_append(result_list, current_cmd);
|
||||
result_list = list_append(result_list, current_cmd);
|
||||
|
||||
// Following commands
|
||||
token = PEEK_TOKEN();
|
||||
while (token->type == TOKEN_SEMICOLON || token->type == TOKEN_NEWLINE)
|
||||
{
|
||||
POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
|
||||
// Skip newlines
|
||||
while (token->type == TOKEN_NEWLINE)
|
||||
{
|
||||
token = POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
// and_or
|
||||
current_cmd = parse_and_or(ctx);
|
||||
if (current_cmd == NULL)
|
||||
return NULL;
|
||||
list_append(result_list, current_cmd);
|
||||
result_list = list_append(result_list, current_cmd);
|
||||
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
|
@ -280,12 +283,14 @@ struct ast *parse_compound_list(struct lexer_context *ctx)
|
|||
if (token->type == TOKEN_SEMICOLON)
|
||||
{
|
||||
token = POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
// Skip newlines
|
||||
while (token->type == TOKEN_NEWLINE)
|
||||
{
|
||||
token = POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
||||
struct ast *result = ast_create_list(result_list);
|
||||
|
|
@ -333,8 +338,8 @@ struct ast *parse_else_clause(struct lexer_context *ctx)
|
|||
|
||||
if (token->type == TOKEN_ELSE)
|
||||
{
|
||||
token = POP_TOKEN(); // eat else
|
||||
result = parse_compound_list(ctx);
|
||||
token = POP_TOKEN(); // Forward
|
||||
}
|
||||
|
||||
if (result == NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue