New approach, new lexer
This commit is contained in:
229
output.cc
229
output.cc
@@ -1,32 +1,97 @@
|
||||
typedef struct OpenGL OpenGL;
|
||||
struct OpenGL{
|
||||
void(*glVertexAttribPointer)(GLuint, GLint, GLenum, GLboolean, GLsizei, GLvoid*);
|
||||
void(*glBindTexture)(GLenum, GLuint);
|
||||
void(*glDrawArrays)(GLenum, GLint, GLsizei);
|
||||
(((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 Thing{
|
||||
int test;
|
||||
};
|
||||
|
||||
S32 thing = 100;
|
||||
(thing=(thing+10));
|
||||
(++thing);
|
||||
{
|
||||
S32 thing_scoped = 10;
|
||||
(thing_scoped+=10);
|
||||
}
|
||||
typedef struct OpenGL OpenGL;
|
||||
typedef struct OS_Memory OS_Memory;
|
||||
typedef struct Arena Arena;
|
||||
typedef struct String String;
|
||||
typedef struct Token Token;
|
||||
typedef struct Lex_Stream Lex_Stream;
|
||||
typedef struct Expr Expr;
|
||||
typedef struct AST_Node AST_Node;
|
||||
typedef struct Parser_Error Parser_Error;
|
||||
typedef struct Scope Scope;
|
||||
typedef struct Parser Parser;
|
||||
struct test{
|
||||
struct Array_Block{
|
||||
Array_Block (*next);
|
||||
Based_Type_Represent (data[size]);
|
||||
};
|
||||
|
||||
struct Array{
|
||||
Array_Block first;
|
||||
Array_Block (*last);
|
||||
S64 block;
|
||||
S64 len;
|
||||
};
|
||||
|
||||
function Based_Type_Represent array_make(Arena (*arena)){
|
||||
Test_Type thing;
|
||||
Based_Type_Represent result;
|
||||
((result.arena)=arena);
|
||||
((result.last)=(&(result.first)));
|
||||
return result;
|
||||
}
|
||||
function void array_push(Array (*array), Based_Type_Represent (*item)){
|
||||
if (((array->len)+1)>size){
|
||||
assert((array->len));
|
||||
Array_Block (*block) = ((Thing)arena_push_struct(((array->arena),sizeof(Array_Block))));
|
||||
((array->last)=(((array->last).next)=block));
|
||||
((array->len)=0);
|
||||
((array->block)+=1);
|
||||
}
|
||||
(((array->last).data)[(++(array->len))]=(*item));
|
||||
}
|
||||
};
|
||||
|
||||
struct OpenGL{
|
||||
void (*glVertexAttribPointer)(GLuint, GLint, GLenumGLenum, GLboolean, GLsizei, GLvoid *);
|
||||
void (*glBindTexture)(GLenum, GLuint);
|
||||
void (*glDrawArrays)(GLenumGLenum, GLint, GLsizei);
|
||||
int (*(test_array[10]));
|
||||
Things (*thing);
|
||||
S64 thing_cap;
|
||||
S64 thing_len;
|
||||
};
|
||||
|
||||
struct OS_Memory{
|
||||
void* data;
|
||||
void (*data);
|
||||
SizeU commit;
|
||||
SizeU reserve;
|
||||
};
|
||||
|
||||
typedef struct Arena Arena;
|
||||
struct Arena{
|
||||
OS_Memory memory;
|
||||
U64 len;
|
||||
U64 alignment;
|
||||
};
|
||||
|
||||
typedef struct String String;
|
||||
struct String{
|
||||
U8* str;
|
||||
U8 (*str);
|
||||
S64 len;
|
||||
};
|
||||
|
||||
typedef Intern_String String;
|
||||
enum Token_Kind{
|
||||
typedef String Intern_String;
|
||||
typedef enum Token_Kind{
|
||||
TK_End,
|
||||
TK_Mul,
|
||||
TK_Div,
|
||||
@@ -90,37 +155,29 @@ TK_Error,
|
||||
TK_Float,
|
||||
TK_Int,
|
||||
TK_Keyword,
|
||||
};
|
||||
}Token_Kind;
|
||||
|
||||
typedef struct Token Token;
|
||||
struct Token{
|
||||
Token_Kind kind;
|
||||
String string;
|
||||
union {
|
||||
union{
|
||||
S64 integer_val;
|
||||
String error_val;
|
||||
Intern_String intern_val;
|
||||
};
|
||||
String file;
|
||||
S64 line;
|
||||
U8* line_begin;
|
||||
U8 (*line_begin);
|
||||
};
|
||||
|
||||
typedef struct Tokens Tokens;
|
||||
struct Tokens{
|
||||
Token* tokens;
|
||||
S64 iter;
|
||||
};
|
||||
|
||||
typedef struct Lex_Stream Lex_Stream;
|
||||
struct Lex_Stream{
|
||||
U8* stream;
|
||||
U8* line_begin;
|
||||
U8 (*stream);
|
||||
U8 (*line_begin);
|
||||
String filename;
|
||||
S64 line;
|
||||
};
|
||||
|
||||
enum Expr_Kind{
|
||||
typedef enum Expr_Kind{
|
||||
EK_None,
|
||||
EK_Atom,
|
||||
EK_Unary,
|
||||
@@ -130,46 +187,45 @@ EK_Cast,
|
||||
EK_List,
|
||||
EK_Call,
|
||||
EK_Index,
|
||||
};
|
||||
}Expr_Kind;
|
||||
|
||||
typedef struct Expr Expr;
|
||||
struct Expr{
|
||||
Expr_Kind kind;
|
||||
Token* token;
|
||||
Expr* next;
|
||||
union {
|
||||
struct cast_val{
|
||||
AST_Node* type;
|
||||
Expr* expr;
|
||||
};
|
||||
struct list{
|
||||
Expr* first;
|
||||
Expr* last;
|
||||
};
|
||||
struct call{
|
||||
Expr* atom;
|
||||
Expr* list;
|
||||
};
|
||||
struct index{
|
||||
Expr* atom;
|
||||
Expr* index;
|
||||
};
|
||||
struct unary{
|
||||
Expr* expr;
|
||||
};
|
||||
struct binary{
|
||||
Expr* left;
|
||||
Expr* right;
|
||||
};
|
||||
struct ternary{
|
||||
Expr* cond;
|
||||
Expr* on_true;
|
||||
Expr* on_false;
|
||||
};
|
||||
Token (*token);
|
||||
Expr (*next);
|
||||
union{
|
||||
struct{
|
||||
AST_Node (*type);
|
||||
Expr (*expr);
|
||||
}cast_val;
|
||||
struct{
|
||||
Expr (*first);
|
||||
Expr (*last);
|
||||
}list;
|
||||
struct{
|
||||
Expr (*atom);
|
||||
Expr (*list);
|
||||
}call;
|
||||
struct{
|
||||
Expr (*atom);
|
||||
Expr (*index);
|
||||
}index;
|
||||
struct{
|
||||
Expr (*expr);
|
||||
}unary;
|
||||
struct{
|
||||
Expr (*left);
|
||||
Expr (*right);
|
||||
}binary;
|
||||
struct{
|
||||
Expr (*cond);
|
||||
Expr (*on_true);
|
||||
Expr (*on_false);
|
||||
}ternary;
|
||||
};
|
||||
};
|
||||
|
||||
enum AST_Kind{
|
||||
typedef enum AST_Kind{
|
||||
AK_None,
|
||||
AK_BaseType,
|
||||
AK_Typedef,
|
||||
@@ -183,61 +239,56 @@ AK_Array,
|
||||
AK_Function,
|
||||
AK_Variable,
|
||||
AK_EnumChild,
|
||||
};
|
||||
}AST_Kind;
|
||||
|
||||
typedef struct AST_Node AST_Node;
|
||||
struct AST_Node{
|
||||
AST_Kind kind;
|
||||
Token* pos;
|
||||
Token (*pos);
|
||||
Intern_String name;
|
||||
AST_Node* next;
|
||||
AST_Node* next_scope;
|
||||
AST_Node* first_note;
|
||||
AST_Node* last_note;
|
||||
AST_Node* first_child;
|
||||
AST_Node* last_child;
|
||||
union {
|
||||
AST_Node (*next);
|
||||
AST_Node (*next_scope);
|
||||
AST_Node (*first_note);
|
||||
AST_Node (*last_note);
|
||||
AST_Node (*first_child);
|
||||
AST_Node (*last_child);
|
||||
union{
|
||||
SizeU base_type_size;
|
||||
AST_Node* pointer;
|
||||
AST_Node* typedef_type;
|
||||
AST_Node* variable_type;
|
||||
AST_Node* func_return_type;
|
||||
AST_Node (*pointer);
|
||||
AST_Node (*typedef_type);
|
||||
AST_Node (*variable_type);
|
||||
AST_Node (*func_return_type);
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct Parser_Error Parser_Error;
|
||||
struct Parser_Error{
|
||||
Parser_Error* next;
|
||||
Parser_Error (*next);
|
||||
String message;
|
||||
Token* token;
|
||||
Token (*token);
|
||||
};
|
||||
|
||||
typedef struct Scope Scope;
|
||||
struct Scope{
|
||||
Scope* next;
|
||||
AST_Node* first;
|
||||
AST_Node* last;
|
||||
Scope (*next);
|
||||
AST_Node (*first);
|
||||
AST_Node (*last);
|
||||
};
|
||||
|
||||
typedef struct Parser Parser;
|
||||
struct Parser{
|
||||
Arena main_arena;
|
||||
Arena intern_table_arena;
|
||||
Arena symbol_table_arena;
|
||||
Scope* scope_free_list;
|
||||
Scope* scope_stack;
|
||||
Scope* global_scope;
|
||||
Scope (*scope_free_list);
|
||||
Scope (*scope_stack);
|
||||
Scope (*global_scope);
|
||||
S64 symbols_inserted;
|
||||
S64 symbols_count;
|
||||
AST_Node* symbols;
|
||||
Intern_String* interns;
|
||||
AST_Node (*symbols);
|
||||
Intern_String (*interns);
|
||||
S64 interns_in_bytes;
|
||||
S64 interns_inserted;
|
||||
S64 interns_count;
|
||||
U8* first_keyword;
|
||||
U8* last_keyword;
|
||||
U8 (*first_keyword);
|
||||
U8 (*last_keyword);
|
||||
Parser_Error default;
|
||||
Parser_Error error;
|
||||
Tokens token_array;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user