comp

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 17383102ddec303f3707e1c2168f017ae18acc7b
Author: thing1 <thing1@seacrossedlovers.xyz>
Date:   Mon, 16 Mar 2026 20:00:28 +0000

init commit

Diffstat:
Acomp.h | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acomp.y | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alex.c | 5+++++
3 files changed, 163 insertions(+), 0 deletions(-)

diff --git a/comp.h b/comp.h @@ -0,0 +1,94 @@ +typedef struct Type Type; +typedef struct Func Func; +typedef struct Rhs Rhs; +typedef struct Expr Expr; +typedef struct Value Value; + +typedef struct Func { + Type *type; + char *name; + Type **argtypes; + char **argnames; + int argc; + Expr **body; + int exprc; +} Func; + +enum Types { + I8, + I16, + I32, + I64, + + U8, + U16, + U32, + U64, + + F32, + F64, + + COMPLEX, +}; + +typedef struct Type { + enum Types type; +} Type; + +enum Exprs { + ASSIGN, + FCALL_EXPR, +}; + +typedef struct Expr { + enum Exprs expr; + union { + struct { + Type *type; + char *name; + Rhs *rhs; + } assign; + struct { + char *name; + Rhs **args; + int argc; + } fcall; + }; +} Expr; + +enum Rhss { + MATH, + FCALL_RHS, + VALUE, + BRACE, +}; + +enum Op { + ADD, + SUB, + MUL, + DIV, +}; + +typedef struct Rhs { + enum Rhss rhs; + union { + struct { + enum Op op; + Rhs *lhs; + Rhs *rhs; + } math; + struct { + char *name; + Rhs **args; + int argc; + } fcall; + Rhs *brace; + Value *value; + }; +} Rhs; + +typedef struct Value { + long long int lval; + double dval; +} Value; diff --git a/comp.y b/comp.y @@ -0,0 +1,64 @@ +%{ +#include "comp.h" +%} + +%union { + Func *func; + Type *type; + Rhs *rhs; + Expr *expr; + Value *value; +} + +%token FUNC +%token NAME +%token INT +%token FLOAT + +%left '(' ')' +%left '*' '/' +%left '+' '-' + +%% +prog : func + | prog func + ; + +func : FUNC name '(' args ')' type '{' exprs '}' + ; + +name : NAME + ; + +args : name + | args ',' name + ; + +type : NAME + ; + +exprs : expr ';' + | exprs expr ';' + ; + +expr : name '(' params ')' + | type name '=' rhs + ; + +params : rhs + | params ',' rhs + ; + +rhs : value + | name '(' params ')' + | rhs '+' rhs + | rhs '-' rhs + | rhs '*' rhs + | rhs '/' rhs + | '(' rhs ')' + ; + +value : INT + | FLOAT + ; +%% diff --git a/lex.c b/lex.c @@ -0,0 +1,5 @@ +int yylex() { + +} + +