preliminary work on sea of nodes based intermediate representation.
This commit is contained in:
parent
989a32fa7b
commit
849e0b6863
13 changed files with 918 additions and 58 deletions
34
parser.c
34
parser.c
|
|
@ -367,9 +367,21 @@ ast_node *parse_term(parser *p)
|
|||
{
|
||||
ast_node *left = parse_unary(p);
|
||||
|
||||
while (match_peek(p, TOKEN_STAR) || match_peek(p, TOKEN_SLASH))
|
||||
{
|
||||
binary_op op = peek(p)->type == TOKEN_STAR ? OP_MUL : OP_DIV;
|
||||
while (match_peek(p, TOKEN_STAR) || match_peek(p, TOKEN_SLASH) || match_peek(p, TOKEN_PERC)) {
|
||||
binary_op op;
|
||||
switch (peek(p)->type) {
|
||||
case TOKEN_STAR:
|
||||
op = OP_MUL;
|
||||
break;
|
||||
case TOKEN_SLASH:
|
||||
op = OP_DIV;
|
||||
break;
|
||||
case TOKEN_PERC:
|
||||
op = OP_MOD;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
advance(p);
|
||||
ast_node *right = parse_factor(p);
|
||||
ast_node *node = arena_alloc(p->allocator, sizeof(ast_node));
|
||||
|
|
@ -561,6 +573,9 @@ ast_node *parse_expression(parser *p)
|
|||
binary_op op;
|
||||
switch (p->tokens->type)
|
||||
{
|
||||
case TOKEN_ARROW:
|
||||
op = OP_ASSIGN_PTR;
|
||||
break;
|
||||
case TOKEN_EQ:
|
||||
op = OP_ASSIGN;
|
||||
break;
|
||||
|
|
@ -854,8 +869,12 @@ static ast_node *parse_if(parser *p)
|
|||
ast_node *node = arena_alloc(p->allocator, sizeof(ast_node));
|
||||
node->type = NODE_IF;
|
||||
node->position = p->previous->position;
|
||||
node->expr.whle.body = body;
|
||||
node->expr.whle.condition = condition;
|
||||
node->expr.if_stmt.body = body;
|
||||
node->expr.if_stmt.condition = condition;
|
||||
if (match(p, TOKEN_ELSE)) {
|
||||
body = parse_compound(p);
|
||||
node->expr.if_stmt.otherwise = body;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
@ -1302,11 +1321,6 @@ static void parse(parser *p)
|
|||
ast_node *tail = p->ast;
|
||||
ast_node *expr = parse_statement(p);
|
||||
while (expr) {
|
||||
if (expr->type != NODE_FUNCTION && expr->type != NODE_VAR_DECL && expr->type != NODE_IMPORT &&
|
||||
expr->type != NODE_STRUCT && expr->type != NODE_UNION && expr->type != NODE_ENUM) {
|
||||
error(p, "expected function, struct, enum, union, global variable or import statement.");
|
||||
return;
|
||||
}
|
||||
tail->expr.unit_node.next = arena_alloc(p->allocator, sizeof(ast_node));
|
||||
tail->expr.unit_node.next->expr.unit_node.expr = expr;
|
||||
tail = tail->expr.unit_node.next;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue