New syntax that's easier to parse, parsing doesn't need variable lookup

This commit is contained in:
Krzosa Karol
2022-05-03 11:31:21 +02:00
parent 3c376bbe30
commit 8c04044ea2
12 changed files with 1216 additions and 244 deletions

24
main.c
View File

@@ -9,6 +9,7 @@
#include "lex.h"
#include "parser.h"
#include "expr.h"
#include "ast.h"
global FILE *global_output_file;
#define lex_print(...) fprintf(global_output_file, __VA_ARGS__)
@@ -21,8 +22,10 @@ global FILE *global_output_file;
#include "lex.c"
#include "expr.c"
#include "ast.c"
#include "parse_expr.c"
#include "parse_decl.c"
#include "print.c"
function void
lex_test(){
@@ -77,25 +80,40 @@ parser_test(){
assert(token_match(&p, TK_End));
String exprs[] = {
lit("(534>43?435:42,234,cast(S64)32/*todo cast*/,Thing[10][2],Thing(1,2))"),
lit("(4+2*53)"),
lit("((4+2)*53)"),
lit("++5"),
lit("5--"), // @Todo(Krzosa):
lit("-5"),
lit("(+5)"),
lit("cast(S64)5"),
lit("sizeof(32) + sizeof(:S32*)"),
lit("cast(S64**)5"),
lit("cast(S64)5+3"),
lit("534>43?435:42"),
lit("(534>43?435:42,234,cast(S64)42,Thing[10][2],Thing(1,2))"),
};
for(S64 i = 0; i < buff_cap(exprs); i++){
parser_lex_stream(&p, exprs[i], lit("File"));
Expr *expr = parse_expr(&p);
assert(expr);
expr_print(expr);
expr_print(&p, expr);
lex_print("\n");
}
/*
String string
= lit(
"@test Thing2 :: struct { thing: union{a:U32;}; _: union{ thing: U32*; }; }"
"Thing :: enum: U32 { @str=\"as\" Thing = 32, Thing2 = 15<<2, }"
"Thing :: struct{ identi: U64*[32]; InnerStruct :: struct { t: U32; } var: InnerStruct; pp :: enum { Thing_1 } }"
"thing:(S64*,U64) U32*@[10]; }"
);
*/
String string = os_read_file(lit("test.cc"));
parser_lex_stream(&p, string, lit("Parse"));
Decl *decls = parse(&p);
assert(decls->list.first);
print_decl(&p, decls);
}
function S32