New approach, new lexer
This commit is contained in:
309
ast.h
309
ast.h
@@ -1,164 +1,201 @@
|
||||
typedef struct Decl_Enum_Child Decl_Enum_Child;
|
||||
typedef struct Decl_Function_Arg Decl_Function_Arg;
|
||||
typedef struct Typespec Typespec;
|
||||
typedef struct Decl Decl;
|
||||
typedef struct Note Note;
|
||||
typedef struct Stmt Stmt;
|
||||
|
||||
#if 0
|
||||
//-----------------------------------------------------------------------------
|
||||
// Type specifier
|
||||
// Type specifiers
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef enum Typespec_Kind{
|
||||
TS_None,
|
||||
TS_Name,
|
||||
TS_Pointer,
|
||||
TS_Array,
|
||||
TS_Function,
|
||||
}Typespec_Kind;
|
||||
|
||||
struct Typespec{
|
||||
Typespec_Kind kind;
|
||||
Typespec *next;
|
||||
Token *pos;
|
||||
@prefix="TS_" Typespec_Kind :: enum{ None, Name, Pointer, Array, Function }
|
||||
Typespec :: struct{
|
||||
kind: Typespec_Kind;
|
||||
next: Typespec*;
|
||||
pos : Token*;
|
||||
|
||||
union{
|
||||
Intern_String name;
|
||||
struct{
|
||||
Typespec *first;
|
||||
Typespec *last;
|
||||
Typespec *ret;
|
||||
}function_spec;
|
||||
struct{
|
||||
Typespec *base;
|
||||
Expr *size;
|
||||
}array_spec;
|
||||
Typespec *base;
|
||||
};
|
||||
};
|
||||
name: Intern_String;
|
||||
base: Typespec*;
|
||||
function_spec: struct{
|
||||
first: Typespec*;
|
||||
last : Typespec*;
|
||||
ret : Typespec*;
|
||||
}
|
||||
array_spec: struct{
|
||||
base: Typespec*;
|
||||
size: Expr*;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Notes
|
||||
//-----------------------------------------------------------------------------
|
||||
struct Note{
|
||||
Token *pos;
|
||||
Intern_String name;
|
||||
Expr *expr;
|
||||
Note :: struct{
|
||||
pos : Token*;
|
||||
name: Intern_String;
|
||||
expr: Expr*;
|
||||
|
||||
Note *next;
|
||||
Note *first;
|
||||
Note *last;
|
||||
next : Note*;
|
||||
first: Note*;
|
||||
last : Note*;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef enum Decl_Kind{
|
||||
DECL_None,
|
||||
DECL_Struct,
|
||||
DECL_Union,
|
||||
DECL_Enum,
|
||||
DECL_Variable,
|
||||
DECL_Typedef,
|
||||
DECL_Function,
|
||||
DECL_List,
|
||||
}Decl_Kind;
|
||||
@prefix = "DECL_" Decl_Kind :: enum { None, Struct, Union, Enum, Variable, Typedef, Function, List }
|
||||
@prefix="STRUCT_" Decl_Struct_Kind :: enum { Nested, Base }
|
||||
|
||||
typedef enum Decl_Struct_Kind{
|
||||
STRUCT_Base ,
|
||||
STRUCT_Nested,
|
||||
}Decl_Struct_Kind;
|
||||
Decl_Function_Arg :: struct{
|
||||
next: Decl_Function_Arg *;
|
||||
name: Intern_String;
|
||||
pos : Token *;
|
||||
typespec: Typespec *;
|
||||
}
|
||||
|
||||
struct Decl_Function_Arg{
|
||||
Decl_Function_Arg *next;
|
||||
Intern_String name;
|
||||
Typespec *typespec;
|
||||
Token *pos;
|
||||
Decl_Enum_Child :: struct{
|
||||
next: Decl_Enum_Child *;
|
||||
name: Intern_String;
|
||||
pos : Token *;
|
||||
expr: Expr *;
|
||||
|
||||
first_note: Note *;
|
||||
last_note : Note *;
|
||||
};
|
||||
|
||||
struct Decl_Enum_Child{
|
||||
Decl_Enum_Child *next;
|
||||
Intern_String name;
|
||||
Token *pos;
|
||||
Expr *expr;
|
||||
Decl :: struct{
|
||||
kind: Decl_Kind;
|
||||
next: Decl *;
|
||||
|
||||
Note *first_note;
|
||||
Note *last_note;
|
||||
};
|
||||
|
||||
struct Decl{
|
||||
Decl_Kind kind;
|
||||
Decl *next;
|
||||
name: Intern_String;
|
||||
pos : Token *;
|
||||
|
||||
Intern_String name;
|
||||
Token *pos;
|
||||
|
||||
Note *first_note;
|
||||
Note *last_note;
|
||||
first_note: Note *;
|
||||
last_note : Note *;
|
||||
|
||||
union{
|
||||
struct{
|
||||
Decl_Enum_Child *first;
|
||||
Decl_Enum_Child *last;
|
||||
Typespec *typespec;
|
||||
}enum_decl;
|
||||
struct{
|
||||
Decl_Struct_Kind kind;
|
||||
Decl *first;
|
||||
Decl *last;
|
||||
} struct_decl;
|
||||
struct{
|
||||
Typespec *type;
|
||||
Expr *expr;
|
||||
}variable_decl;
|
||||
struct{
|
||||
Typespec *type;
|
||||
}typedef_decl;
|
||||
struct{
|
||||
Decl_Function_Arg *first;
|
||||
Decl_Function_Arg *last ;
|
||||
Typespec *ret;
|
||||
}function_decl;
|
||||
struct{
|
||||
Decl *first;
|
||||
Decl *last;
|
||||
}list;
|
||||
};
|
||||
};
|
||||
enum_decl: struct{
|
||||
first: Decl_Enum_Child *;
|
||||
last: Decl_Enum_Child *;
|
||||
typespec: Typespec *;
|
||||
}
|
||||
struct_decl: struct{
|
||||
first: Decl *;
|
||||
last: Decl *;
|
||||
kind: Decl_Struct_Kind ;
|
||||
}
|
||||
variable_decl: struct{
|
||||
type: Typespec *;
|
||||
expr: Expr *;
|
||||
}
|
||||
typedef_decl: struct{
|
||||
type: Typespec *;
|
||||
}
|
||||
function_decl: struct{
|
||||
first: Decl_Function_Arg *;
|
||||
last : Decl_Function_Arg *;
|
||||
ret: Typespec *;
|
||||
body : Stmt*;
|
||||
}
|
||||
list: struct{
|
||||
first: Decl *;
|
||||
last: Decl *;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Statements
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef enum Stmt_Kind{
|
||||
STMT_None,
|
||||
STMT_Decl,
|
||||
STMT_Expr,
|
||||
STMT_Return,
|
||||
STMT_If,
|
||||
STMT_For,
|
||||
}Stmt_Kind;
|
||||
@prefix="STMT_" Stmt_Kind :: enum{ None, Decl, Expr, List, Return, If, For}
|
||||
|
||||
typedef struct Stmt_List Stmt_List;
|
||||
struct Stmt_List{
|
||||
Stmt *first;
|
||||
Stmt *last;
|
||||
};
|
||||
Stmt_If :: struct {
|
||||
next: Stmt_If*;
|
||||
cond: Expr*;
|
||||
body: Stmt*;
|
||||
}
|
||||
|
||||
typedef struct Stmt_If Stmt_If;
|
||||
struct Stmt_If{
|
||||
Stmt_If *next;
|
||||
Expr *expr;
|
||||
union{
|
||||
struct{Stmt *first; Stmt *last;};
|
||||
Stmt_List *list;
|
||||
};
|
||||
};
|
||||
|
||||
struct Stmt{
|
||||
Stmt_Kind kind;
|
||||
Stmt *next;
|
||||
Stmt :: struct {
|
||||
kind: Stmt_Kind;
|
||||
next: Stmt*;
|
||||
pos : Token*;
|
||||
|
||||
union{
|
||||
Decl *decl;
|
||||
Expr *expr;
|
||||
Stmt_If *if_stmt;
|
||||
Stmt_List *list;
|
||||
};
|
||||
};
|
||||
stmt_if: Stmt_If;
|
||||
decl: Decl*;
|
||||
expr: Expr*;
|
||||
list: struct{
|
||||
first: Stmt*;
|
||||
last : Stmt*;
|
||||
}
|
||||
ret: struct{
|
||||
expr: Expr*;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gather
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@prefix="PK_"
|
||||
Pointer_Kind::enum{
|
||||
None,
|
||||
Typespec,
|
||||
Expr,
|
||||
Decl,
|
||||
Stmt,
|
||||
Enum_Child,
|
||||
Func_Arg,
|
||||
Intern_String
|
||||
}
|
||||
|
||||
Pointer::struct{
|
||||
kind: Pointer_Kind;
|
||||
union {
|
||||
typespec: Typespec *;
|
||||
decl: Decl *;
|
||||
expr: Expr *;
|
||||
stmt: Stmt *;
|
||||
func_arg: Decl_Function_Arg*;
|
||||
enum_child: Decl_Enum_Child*;
|
||||
string: Intern_String *;
|
||||
}
|
||||
}
|
||||
|
||||
Pointer_Bucket::struct{
|
||||
next: Pointer_Bucket*;
|
||||
data: Pointer[4096];
|
||||
}
|
||||
|
||||
Pointer_Array::struct{
|
||||
first: Pointer_Bucket;
|
||||
last : Pointer_Bucket*;
|
||||
len : S64;
|
||||
block: S64;
|
||||
arena: Arena*;
|
||||
|
||||
iter_bucket: Pointer_Bucket*;
|
||||
iter_len: S64;
|
||||
iter_block: S64;
|
||||
}
|
||||
|
||||
@prefix="GATHER_"
|
||||
Gather_Flag::enum{
|
||||
None = 0,
|
||||
Typespec = 1,
|
||||
Expr = 2,
|
||||
Decl = 4,
|
||||
Stmt = 8,
|
||||
Enum_Child = 16,
|
||||
Func_Arg = 32,
|
||||
}
|
||||
|
||||
@prefix="TRAVERS_"
|
||||
Traversal_Flag :: enum{
|
||||
None,
|
||||
Typespec = 1,
|
||||
Expr = 2,
|
||||
//Decl = 4,
|
||||
Stmt = 8,
|
||||
All = TRAVERS_Typespec | TRAVERS_Expr | TRAVERS_Stmt,
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "generated_ast.h"
|
||||
|
||||
Reference in New Issue
Block a user