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

246
output.cc
View File

@@ -0,0 +1,246 @@
(((534>43)?435:42),234,((S64)32),Thing[10][2],Thing((1,2)))
(4+(2*53))
((4+2)*53)
(++5)
(--5)
(-5)
(+5)
(sizeof(32)+sizeof(S32*))
((S64**)5)
(((S64)5)+3)
((534>43)?435:42)
struct OS_Memory{
data: void*;
commit: SizeU;
reserve: SizeU;
};
struct Arena{
@using memory: OS_Memory;
len: U64;
alignment: U64;
};
struct String{
str: U8*;
len: S64;
};
typedef Intern_String String;
@stringify @prefix = TK_ enum Token_Kind : S64{
@str = End of stream End,
@str = * Mul,
@str = / Div,
@str = + Add,
@str = - Sub,
@str = % Mod,
@str = & BitAnd,
@str = | BitOr,
@str = ^ BitXor,
@str = ~ Neg,
@str = ! Not,
@str = ( OpenParen,
@str = CloseParen,
@str = { OpenBrace,
@str = } CloseBrace,
@str = [ OpenBracket,
@str = ] CloseBracket,
@str = , Comma,
@str = # Pound,
@str = ? Question,
@str = ... ThreeDots,
@str = ; Semicolon,
@str = . Dot,
@str = < LesserThen,
@str = > GreaterThen,
@str = : Colon,
@str = = Assign,
@str = /= DivAssign,
@str = *= MulAssign,
@str = %= ModAssign,
@str = -= SubAssign,
@str = += AddAssign,
@str = &= AndAssign,
@str = |= OrAssign,
@str = ^= XorAssign,
@str = <<= LeftShiftAssign,
@str = >>= RightShiftAssign,
@str = :: DoubleColon,
@str = @ At,
@str = -- Decrement,
@str = ++ Increment,
@str = -- PostDecrement,
@str = ++ PostIncrement,
@str = <= LesserThenOrEqual,
@str = >= GreaterThenOrEqual,
@str = == Equals,
@str = && And,
@str = || Or,
@str = != NotEquals,
@str = << LeftShift,
@str = >> RightShift,
@str = -> Arrow,
@str = sizeof ExprSizeof,
DocComment,
Comment,
Identifier,
StringLit,
U8Lit,
Character,
Error,
Float,
Int,
Keyword,
};
struct Token{
kind: Token_Kind;
@using string: String;
val: union {
integer: S64;
error: String;
intern: Intern_String;
};
file: String;
line: S64;
line_begin: U8*;
};
struct Tokens{
@array tokens: Token*;
iter: S64;
};
struct Lex_Stream{
stream: U8*;
line_begin: U8*;
filename: String;
line: S64;
};
@prefix = EK_ enum Expr_Kind : S64{
None,
Atom,
Unary,
Binary,
Ternary,
Cast,
List,
Call,
Index,
};
struct Expr{
kind: Expr_Kind;
token: Token*;
next: Expr*;
_: union {
cast_val: struct {
type: AST_Node*;
expr: Expr*;
};
list: struct {
first: Expr*;
last: Expr*;
};
call: struct {
atom: Expr*;
list: Expr*;
};
index: struct {
atom: Expr*;
index: Expr*;
};
unary: struct {
expr: Expr*;
};
binary: struct {
left: Expr*;
right: Expr*;
};
ternary: struct {
cond: Expr*;
on_true: Expr*;
on_false: Expr*;
};
};
};
@prefix = AK_ enum AST_Kind : S64{
None,
BaseType,
Typedef,
Enum,
Struct,
Union,
Note,
List,
Pointer,
Array,
Function,
Variable,
EnumChild,
};
struct AST_Node{
kind: AST_Kind;
pos: Token*;
name: Intern_String;
next: AST_Node*;
next_scope: AST_Node*;
first_note: AST_Node*;
last_note: AST_Node*;
first_child: AST_Node*;
last_child: AST_Node*;
_: union {
base_type_size: SizeU;
pointer: AST_Node*;
typedef_type: AST_Node*;
variable_type: AST_Node*;
func_return_type: AST_Node*;
};
};
struct Parser_Error{
next: Parser_Error*;
message: String;
token: Token*;
};
struct Scope{
next: Scope*;
first: AST_Node*;
last: AST_Node*;
};
struct Parser{
main_arena: Arena;
intern_table_arena: Arena;
symbol_table_arena: Arena;
scope_free_list: Scope*;
scope_stack: Scope*;
global_scope: Scope*;
symbols_inserted: S64;
symbols_count: S64;
symbols: AST_Node*;
interns: Intern_String*;
interns_in_bytes: S64;
interns_inserted: S64;
interns_count: S64;
first_keyword: U8*;
last_keyword: U8*;
@sllqueue default: Parser_Error;
@sllqueue error: Parser_Error;
@using token_array: Tokens;
};