let s:cpo_save = &cpo
set cpo&vim
-syn keyword onyxKeyword struct
-syn keyword onyxKeyword use
-syn keyword onyxKeyword if
-syn keyword onyxKeyword elseif
-syn keyword onyxKeyword else
-syn keyword onyxKeyword export
-syn keyword onyxKeyword proc
-syn keyword onyxKeyword foreign
-syn keyword onyxKeyword for
+syn keyword onyxKeyword struct proc use export foreign global
+syn keyword onyxKeyword if elseif else
+syn keyword onyxKeyword for return do
syn keyword onyxKeyword return
-syn keyword onyxKeyword do
-syn keyword onyxKeyword global
syn keyword onyxKeyword as
syn keyword onyxType i32
print_if :: foreign "host" "print" proc (i i32, f f32) ---
foo :: proc -> i32 {
- return 10 as i32;
+ return 10;
}
add :: proc (a i32, b i32) -> i32 {
// is possible that all code paths are covered with returning
// an i32. This will need to be fixed.
abs :: proc (val i32) -> i32 {
- if val <= 0 { return -val; };
+ if val <= 0 { return -val; }
// else { return val; };
return val;
}
return c * d;
}
-export do_stuff :: proc -> i32 {
- res := diff_square((4 + 5) as i32, (2 + 3) as i32);
+do_stuff :: proc -> i32 {
+ res := diff_square(4 + 5, 2 + 3);
res = res + foo();
- // res should be -66
return res * -1;
}
new_output :: abs(output) * 2;
print(new_output);
+ } elseif output == -67 {
+ print(1234);
+
} else {
print(-1);
-
- };
+ }
print(output);
print_float(float_test());
static OnyxAstNode* parse_factor(OnyxParser* parser);
static OnyxAstNode* parse_bin_op(OnyxParser* parser, OnyxAstNode* left);
static OnyxAstNode* parse_expression(OnyxParser* parser);
-static OnyxAstNode* parse_if_stmt(OnyxParser* parser);
+static OnyxAstNodeIf* parse_if_stmt(OnyxParser* parser);
static b32 parse_symbol_statement(OnyxParser* parser, OnyxAstNode** ret);
static OnyxAstNode* parse_return_statement(OnyxParser* parser);
static OnyxAstNodeBlock* parse_block(OnyxParser* parser, b32 belongs_to_function);
return root;
}
-static OnyxAstNode* parse_if_stmt(OnyxParser* parser) {
+static OnyxAstNodeIf* parse_if_stmt(OnyxParser* parser) {
expect(parser, TOKEN_TYPE_KEYWORD_IF);
OnyxAstNode* cond = parse_expression(parser);
OnyxAstNodeIf* root_if = if_node;
if_node->cond = cond;
- if_node->true_block = true_block->as_block.body;
+ if (true_block != NULL)
+ if_node->true_block = true_block->as_block.body;
while (parser->curr_token->type == TOKEN_TYPE_KEYWORD_ELSEIF) {
parser_next_token(parser);
true_block = (OnyxAstNode *) parse_block(parser, 0);
elseif_node->cond = cond;
- elseif_node->true_block = true_block->as_block.body;
+ if (true_block != NULL)
+ elseif_node->true_block = true_block->as_block.body;
if_node->false_block = (OnyxAstNode *) elseif_node;
if_node = elseif_node;
parser_next_token(parser);
OnyxAstNode* false_block = (OnyxAstNode *) parse_block(parser, 0);
- if_node->false_block = false_block->as_block.body;
+ if (false_block != NULL)
+ if_node->false_block = false_block->as_block.body;
}
- return (OnyxAstNode *) root_if;
+ return root_if;
}
// Returns 1 if the symbol was consumed. Returns 0 otherwise
}
static OnyxAstNode* parse_statement(OnyxParser* parser) {
+ b32 needs_semicolon = 1;
+ OnyxAstNode* retval = NULL;
+
switch (parser->curr_token->type) {
case TOKEN_TYPE_KEYWORD_RETURN:
- return parse_return_statement(parser);
+ retval = parse_return_statement(parser);
+ break;
case TOKEN_TYPE_OPEN_BRACE:
- return (OnyxAstNode *) parse_block(parser, 0);
+ needs_semicolon = 0;
+ retval = (OnyxAstNode *) parse_block(parser, 0);
+ break;
case TOKEN_TYPE_SYMBOL:
- {
- OnyxAstNode* ret = NULL;
- if (parse_symbol_statement(parser, &ret)) return ret;
- // fallthrough
- }
+ if (parse_symbol_statement(parser, &retval)) break;
+ // fallthrough
case TOKEN_TYPE_OPEN_PAREN:
case TOKEN_TYPE_SYM_PLUS:
case TOKEN_TYPE_SYM_BANG:
case TOKEN_TYPE_LITERAL_NUMERIC:
case TOKEN_TYPE_LITERAL_STRING:
- return parse_expression(parser);
+ retval = parse_expression(parser);
+ break;
case TOKEN_TYPE_KEYWORD_IF:
- return parse_if_stmt(parser);
+ needs_semicolon = 0;
+ retval = (OnyxAstNode *) parse_if_stmt(parser);
+ break;
default:
- return NULL;
+ break;
}
+
+ if (needs_semicolon) {
+ if (parser->curr_token->type != TOKEN_TYPE_SYM_SEMICOLON) {
+ onyx_message_add(parser->msgs,
+ ONYX_MESSAGE_TYPE_EXPECTED_TOKEN,
+ parser->curr_token->pos,
+ onyx_get_token_type_name(TOKEN_TYPE_SYM_SEMICOLON),
+ onyx_get_token_type_name(parser->curr_token->type));
+
+ find_token(parser, TOKEN_TYPE_SYM_SEMICOLON);
+ }
+ parser_next_token(parser);
+ }
+
+ return retval;
}
static OnyxAstNodeBlock* parse_block(OnyxParser* parser, b32 belongs_to_function) {
*next = stmt;
next = &stmt->next;
}
-
- if (parser->curr_token->type != TOKEN_TYPE_SYM_SEMICOLON) {
- onyx_message_add(parser->msgs,
- ONYX_MESSAGE_TYPE_EXPECTED_TOKEN,
- parser->curr_token->pos,
- onyx_get_token_type_name(TOKEN_TYPE_SYM_SEMICOLON),
- onyx_get_token_type_name(parser->curr_token->type));
-
- find_token(parser, TOKEN_TYPE_SYM_SEMICOLON);
- }
- parser_next_token(parser);
}
expect(parser, TOKEN_TYPE_CLOSE_BRACE);