This commit is contained in:
attilavs2 2025-03-08 18:57:42 +01:00
parent c5c58f07bc
commit 77ddf1514a
2 changed files with 34 additions and 33 deletions

View file

@ -21,10 +21,11 @@
"else" return ELSE;
"fn" return FN;
"var" return VAR;
"let" return LET;
"block" return BLOCK;
[-+*/%a-zA-Z]+ {
[-+*/%<=>!a-zA-Z]+ {
yylval.str = yytext;
return G_IDENT;
}
@ -34,10 +35,7 @@
return CST;
}
[()<=>!] return *yytext;
">=" return GTEQ;
"<=" return SMEQ;
[()] return *yytext;
[ \t\n]+ ;

View file

@ -17,22 +17,21 @@
%token <str> G_IDENT TYPE_U
%token VEC
%token VAR
%token LET
%token IF
%token ELSE
%token WHILE
%token FN
%token GTEQ
%token SMEQ
%token BLOCK
%token <st> CST
%type <st> stmt stmt_list
%type <st> expr expr_list
%type <tag> type
%%
program:
stmt_list '.' {set_entry_point($1); exit(0); }
expr_list '.' {set_entry_point($1); exit(0); }
;
type:
@ -46,44 +45,48 @@ type:
;
fn_args:
G_IDENT type
G_IDENT
{}
| G_IDENT type
{}
| fn_args G_IDENT
{}
| fn_args G_IDENT type
{}
;
stmt:
expr:
'(' G_IDENT ')'
{$$ = make_operation(ST_Call, 0, $2, 0, NULL);}
| '(' VAR G_IDENT ')'
{Tag ntag = {0,T_null}; $$ = declare(BI_var,ntag,$3);}
| '(' VAR type G_IDENT ')'
{$$ = declare(BI_var, $3, $4);}
| '(' IF stmt stmt_list ')'
| '(' VAR G_IDENT expr')'
{}
| '(' VAR type G_IDENT expr ')'
{}
| '(' LET G_IDENT ')'
{}
| '(' LET type G_IDENT ')'
{}
| '(' LET G_IDENT expr ')'
{}
| '(' LET type G_IDENT expr ')'
{}
| '(' IF expr expr_list ')'
{$$ = make_operation(BI_if, 0, NULL, 2, $3, $4);}
| '(' IF stmt stmt_list ')' '(' ELSE stmt_list ')'
| '(' IF expr expr_list ')' '(' ELSE expr_list ')'
{Statement *st = make_block(make_operation(BI_if, 0, NULL, 2, $3, $4));
$$ = add_block(st, make_operation(BI_else, 0, NULL, 1, $8));
}
| '(' WHILE stmt stmt_list ')'
| '(' WHILE expr expr_list ')'
{}
| '(' FN '(' fn_args ')' stmt_list ')'
| '(' FN '(' fn_args ')' expr_list ')'
{}
| '(' GTEQ stmt stmt ')'
{}
| '(' SMEQ stmt stmt ')'
{}
| '(' '<' stmt stmt ')'
{}
| '(' '>' stmt stmt ')'
{}
| '(' '=' stmt stmt ')'
{}
| '(' '!' stmt ')'
{}
| '(' BLOCK stmt_list ')'
| '(' BLOCK expr_list ')'
{$$ = $3;}
| '(' G_IDENT stmt ')'
| '(' G_IDENT expr_list ')'
{$$ = make_operation(ST_None, 0, $2, 1, $3);}
| G_IDENT
{$$ = variable_get($1);}
@ -91,10 +94,10 @@ stmt:
{$$ = $1;}
;
stmt_list:
stmt
expr_list:
expr
{$$ = make_block($1);}
| stmt_list stmt
| expr_list expr
{$$ = add_block($1, $2);}
;