fix: mismatched AST locations (#140)

This commit is contained in:
Sven Vogel 2024-10-10 22:57:13 +02:00
parent a71385d508
commit fb055a5225
2 changed files with 125 additions and 125 deletions

View File

@ -470,7 +470,7 @@ int createDef(AST_NODE_PTR currentNode, GArray** variables) {
def.declaration = decl; def.declaration = decl;
Expression* name = createExpression(expression); Expression* name = createExpression(expression);
if (name == NULL) { if (name == NULL) {
status = SEMANTIC_OK; return SEMANTIC_ERROR;
} }
if (!compareTypes(def.declaration.type, name->result)) { if (!compareTypes(def.declaration.type, name->result)) {

View File

@ -21,7 +21,7 @@
extern ModuleRef* parser_ref; extern ModuleRef* parser_ref;
#define new_loc() new_location(yylloc.first_line, yylloc.first_column, yylloc.last_line, yylloc.last_column, current_file, parser_ref) #define new_loc(loc) new_location(loc.first_line, loc.first_column, loc.last_line, loc.last_column, current_file, parser_ref)
} }
%union { %union {
@ -212,18 +212,18 @@ annotation: Ident { AST_Annotation annotation;
annotationbind: '#' annotation { $$ = $2; }; annotationbind: '#' annotation { $$ = $2; };
moduleref: Ident {$$ = AST_new_node(new_loc(), AST_Ident, $1);} moduleref: Ident {$$ = AST_new_node(new_loc(@1), AST_Ident, $1);}
| Ident ModSep moduleref {AST_NODE_PTR modref = AST_new_node(new_loc(), AST_ModuleRef, NULL); | Ident ModSep moduleref {AST_NODE_PTR modref = AST_new_node(new_loc(@3), AST_ModuleRef, NULL);
AST_push_node(modref, AST_new_node(new_loc(), AST_Ident, $1)); AST_push_node(modref, AST_new_node(new_loc(@1), AST_Ident, $1));
AST_push_node(modref, $3); AST_push_node(modref, $3);
$$ = modref;}; $$ = modref;};
expr: ValFloat {$$ = AST_new_node(new_loc(), AST_Float, $1);} expr: ValFloat {$$ = AST_new_node(new_loc(@1), AST_Float, $1);}
| ValInt {$$ = AST_new_node(new_loc(), AST_Int, $1);} | ValInt {$$ = AST_new_node(new_loc(@1), AST_Int, $1);}
| ValChar {$$ = AST_new_node(new_loc(), AST_Char, $1);} | ValChar {$$ = AST_new_node(new_loc(@1), AST_Char, $1);}
| ValMultistr {$$ = AST_new_node(new_loc(), AST_String, $1);} | ValMultistr {$$ = AST_new_node(new_loc(@1), AST_String, $1);}
| ValStr {$$ = AST_new_node(new_loc(), AST_String, $1);} | ValStr {$$ = AST_new_node(new_loc(@1), AST_String, $1);}
| Ident {$$ = AST_new_node(new_loc(), AST_Ident, $1);} | Ident {$$ = AST_new_node(new_loc(@1), AST_Ident, $1);}
| operation {$$ = $1;} | operation {$$ = $1;}
| boxaccess {$$ = $1;} | boxaccess {$$ = $1;}
| boxselfaccess{$$ = $1;} | boxselfaccess{$$ = $1;}
@ -231,47 +231,47 @@ expr: ValFloat {$$ = AST_new_node(new_loc(), AST_Float, $1);}
| reinterpretcast{$$ = $1;} | reinterpretcast{$$ = $1;}
| '(' expr ')' {$$=$2;} | '(' expr ')' {$$=$2;}
| funcall {$$=$1;} | funcall {$$=$1;}
| KeyRef Ident {AST_NODE_PTR addrof = AST_new_node(new_loc(), AST_AddressOf, NULL); | KeyRef Ident {AST_NODE_PTR addrof = AST_new_node(new_loc(@1), AST_AddressOf, NULL);
AST_push_node(addrof, AST_new_node(new_loc(), AST_Ident, $2)); AST_push_node(addrof, AST_new_node(new_loc(@2), AST_Ident, $2));
$$ = addrof;} $$ = addrof;}
| expr '[' expr ']' {AST_NODE_PTR deref = AST_new_node(new_loc(), AST_Dereference, NULL); | expr '[' expr ']' {AST_NODE_PTR deref = AST_new_node(new_loc(@1), AST_Dereference, NULL);
AST_push_node(deref, $1); AST_push_node(deref, $1);
AST_push_node(deref, $3); AST_push_node(deref, $3);
$$ = deref;}; $$ = deref;};
exprlist: expr ',' exprlist {AST_push_node($3, $1); exprlist: expr ',' exprlist {AST_push_node($3, $1);
$$ = $3;} $$ = $3;}
| expr {AST_NODE_PTR list = AST_new_node(new_loc(), AST_ExprList, NULL); | expr {AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_ExprList, NULL);
AST_push_node(list, $1); AST_push_node(list, $1);
$$ = list;}; $$ = list;};
argumentlist: argumentlist '(' exprlist ')' {AST_push_node($1, $3); argumentlist: argumentlist '(' exprlist ')' {AST_push_node($1, $3);
$$ = $1;} $$ = $1;}
| '(' exprlist ')'{AST_NODE_PTR list = AST_new_node(new_loc(), AST_ArgList, NULL); | '(' exprlist ')'{AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_ArgList, NULL);
AST_push_node(list, $2); AST_push_node(list, $2);
$$ = list;} $$ = list;}
| argumentlist '(' ')' | argumentlist '(' ')'
| '(' ')'{AST_NODE_PTR list = AST_new_node(new_loc(), AST_ArgList, NULL); | '(' ')'{AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_ArgList, NULL);
$$ = list;}; $$ = list;};
procdef: KeyFun Ident paramlist '{' statementlist'}' {AST_NODE_PTR fun = AST_new_node(new_loc(), AST_ProcDef, NULL); procdef: KeyFun Ident paramlist '{' statementlist'}' {AST_NODE_PTR fun = AST_new_node(new_loc(@1), AST_ProcDef, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $2); AST_NODE_PTR ident = AST_new_node(new_loc(@2), AST_Ident, $2);
AST_push_node(fun, ident); AST_push_node(fun, ident);
AST_push_node(fun, $3); AST_push_node(fun, $3);
AST_push_node(fun, $5); AST_push_node(fun, $5);
$$ = fun; $$ = fun;
DEBUG("Function");} DEBUG("Function");}
procdecl: KeyFun Ident paramlist {AST_NODE_PTR fun = AST_new_node(new_loc(), AST_ProcDecl, NULL); procdecl: KeyFun Ident paramlist {AST_NODE_PTR fun = AST_new_node(new_loc(@1), AST_ProcDecl, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $2); AST_NODE_PTR ident = AST_new_node(new_loc(@2), AST_Ident, $2);
AST_push_node(fun, ident); AST_push_node(fun, ident);
AST_push_node(fun, $3); AST_push_node(fun, $3);
$$ = fun; $$ = fun;
DEBUG("Function");}; DEBUG("Function");};
fundef: KeyFun type ':' Ident paramlist '{' statementlist'}' {AST_NODE_PTR fun = AST_new_node(new_loc(), AST_FunDef, NULL); fundef: KeyFun type ':' Ident paramlist '{' statementlist'}' {AST_NODE_PTR fun = AST_new_node(new_loc(@1), AST_FunDef, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $4); AST_NODE_PTR ident = AST_new_node(new_loc(@4), AST_Ident, $4);
AST_push_node(fun, ident); AST_push_node(fun, ident);
AST_push_node(fun, $2); AST_push_node(fun, $2);
AST_push_node(fun, $5); AST_push_node(fun, $5);
@ -279,8 +279,8 @@ fundef: KeyFun type ':' Ident paramlist '{' statementlist'}' {AST_NODE_PTR fun =
$$ = fun; $$ = fun;
DEBUG("Function");} DEBUG("Function");}
fundecl: KeyFun type ':' Ident paramlist {AST_NODE_PTR fun = AST_new_node(new_loc(), AST_FunDecl, NULL); fundecl: KeyFun type ':' Ident paramlist {AST_NODE_PTR fun = AST_new_node(new_loc(@1), AST_FunDecl, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $4); AST_NODE_PTR ident = AST_new_node(new_loc(@4), AST_Ident, $4);
AST_push_node(fun, ident); AST_push_node(fun, ident);
AST_push_node(fun, $2); AST_push_node(fun, $2);
AST_push_node(fun, $5); AST_push_node(fun, $5);
@ -292,66 +292,66 @@ fundecl: KeyFun type ':' Ident paramlist {AST_NODE_PTR fun = AST_new_node(new_lo
paramlist: paramlist '(' params ')' {AST_push_node($1, $3); paramlist: paramlist '(' params ')' {AST_push_node($1, $3);
$$ = $1;} $$ = $1;}
| paramlist '(' ')'{$$ = $1;} | paramlist '(' ')'{$$ = $1;}
| '(' params ')' {AST_NODE_PTR list = AST_new_node(new_loc(), AST_List, NULL); | '(' params ')' {AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_List, NULL);
AST_push_node(list, $2); AST_push_node(list, $2);
$$ = list;} $$ = list;}
| '(' ')' {$$ = AST_new_node(new_loc(), AST_List, NULL);}; | '(' ')' {$$ = AST_new_node(new_loc(@1), AST_List, NULL);};
params: IOqualifyier paramdecl ',' params {AST_NODE_PTR parameter = AST_new_node(new_loc(), AST_Parameter, NULL); params: IOqualifyier paramdecl ',' params {AST_NODE_PTR parameter = AST_new_node(new_loc(@1), AST_Parameter, NULL);
AST_push_node(parameter, $1); AST_push_node(parameter, $1);
AST_push_node(parameter, $2); AST_push_node(parameter, $2);
AST_push_node($4, parameter); AST_push_node($4, parameter);
$$ = $4;} $$ = $4;}
| IOqualifyier paramdecl {AST_NODE_PTR list = AST_new_node(new_loc(), AST_ParamList, NULL); | IOqualifyier paramdecl {AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_ParamList, NULL);
AST_NODE_PTR parameter = AST_new_node(new_loc(), AST_Parameter, NULL); AST_NODE_PTR parameter = AST_new_node(new_loc(@1), AST_Parameter, NULL);
AST_push_node(parameter, $1); AST_push_node(parameter, $1);
AST_push_node(parameter, $2); AST_push_node(parameter, $2);
AST_push_node(list, parameter); AST_push_node(list, parameter);
$$ = list;}; $$ = list;};
IOqualifyier: KeyIn { AST_NODE_PTR in = AST_new_node(new_loc(), AST_Qualifyier, "in"); IOqualifyier: KeyIn { AST_NODE_PTR in = AST_new_node(new_loc(@1), AST_Qualifyier, "in");
AST_NODE_PTR list = AST_new_node(new_loc(), AST_List, NULL); AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_List, NULL);
AST_push_node(list, in); AST_push_node(list, in);
$$ = list;} $$ = list;}
| KeyOut{ AST_NODE_PTR out = AST_new_node(new_loc(), AST_Qualifyier, "out"); | KeyOut{ AST_NODE_PTR out = AST_new_node(new_loc(@1), AST_Qualifyier, "out");
AST_NODE_PTR list = AST_new_node(new_loc(), AST_List, NULL); AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_List, NULL);
AST_push_node(list, out); AST_push_node(list, out);
$$ = list;} $$ = list;}
| KeyIn KeyOut{ AST_NODE_PTR in = AST_new_node(new_loc(), AST_Qualifyier, "in"); | KeyIn KeyOut{ AST_NODE_PTR in = AST_new_node(new_loc(@1), AST_Qualifyier, "in");
AST_NODE_PTR out = AST_new_node(new_loc(), AST_Qualifyier, "out"); AST_NODE_PTR out = AST_new_node(new_loc(@1), AST_Qualifyier, "out");
AST_NODE_PTR list = AST_new_node(new_loc(), AST_List, NULL); AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_List, NULL);
AST_push_node(list, in); AST_push_node(list, in);
AST_push_node(list, out); AST_push_node(list, out);
$$ = list;} $$ = list;}
| KeyOut KeyIn{ AST_NODE_PTR in = AST_new_node(new_loc(), AST_Qualifyier, "in"); | KeyOut KeyIn{ AST_NODE_PTR in = AST_new_node(new_loc(@2), AST_Qualifyier, "in");
AST_NODE_PTR out = AST_new_node(new_loc(), AST_Qualifyier, "out"); AST_NODE_PTR out = AST_new_node(new_loc(@1), AST_Qualifyier, "out");
AST_NODE_PTR list = AST_new_node(new_loc(), AST_List, NULL); AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_List, NULL);
AST_push_node(list, in); AST_push_node(list, in);
AST_push_node(list, out); AST_push_node(list, out);
$$ = list;} $$ = list;}
| {$$ = AST_new_node(new_loc(), AST_List, NULL);}; | {$$ = AST_new_node(new_loc(yylloc), AST_List, NULL);};
paramdecl: type ':' Ident { AST_NODE_PTR paramdecl = AST_new_node(new_loc(), AST_ParamDecl, NULL); paramdecl: type ':' Ident { AST_NODE_PTR paramdecl = AST_new_node(new_loc(@1), AST_ParamDecl, NULL);
AST_push_node(paramdecl, $1); AST_push_node(paramdecl, $1);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $3); AST_NODE_PTR ident = AST_new_node(new_loc(@3), AST_Ident, $3);
AST_push_node(paramdecl, ident); AST_push_node(paramdecl, ident);
$$ = paramdecl; $$ = paramdecl;
DEBUG("Param-Declaration"); }; DEBUG("Param-Declaration"); };
box: KeyType KeyBox ':' Ident '{' boxbody '}' {AST_NODE_PTR box = AST_new_node(new_loc(), AST_Box, NULL); box: KeyType KeyBox ':' Ident '{' boxbody '}' {AST_NODE_PTR box = AST_new_node(new_loc(@1), AST_Box, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $4); AST_NODE_PTR ident = AST_new_node(new_loc(@4), AST_Ident, $4);
AST_push_node(box, ident); AST_push_node(box, ident);
AST_push_node(box, $6); AST_push_node(box, $6);
$$ = box; $$ = box;
DEBUG("Box"); } DEBUG("Box"); }
| KeyType KeyBox ':' Ident '{' '}' {AST_NODE_PTR box = AST_new_node(new_loc(), AST_Box, NULL); | KeyType KeyBox ':' Ident '{' '}' {AST_NODE_PTR box = AST_new_node(new_loc(@1), AST_Box, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $4); AST_NODE_PTR ident = AST_new_node(new_loc(@4), AST_Ident, $4);
AST_push_node(box, ident); AST_push_node(box, ident);
$$ = box;}; $$ = box;};
boxbody: boxbody boxcontent {AST_push_node($1, $2); boxbody: boxbody boxcontent {AST_push_node($1, $2);
$$ = $1;} $$ = $1;}
| boxcontent {AST_NODE_PTR list = AST_new_node(new_loc(), AST_List, NULL); | boxcontent {AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_List, NULL);
AST_push_node(list, $1); AST_push_node(list, $1);
$$ = list;}; $$ = list;};
@ -359,68 +359,68 @@ boxcontent: decl { $$ = $1;DEBUG("Box decl Content"); }
| definition { $$ = $1;DEBUG("Box def Content"); } | definition { $$ = $1;DEBUG("Box def Content"); }
| fundef { $$ = $1;DEBUG("Box fun Content"); }; | fundef { $$ = $1;DEBUG("Box fun Content"); };
boxselfaccess: KeySelf '.' Ident {AST_NODE_PTR boxselfaccess = AST_new_node(new_loc(), AST_List, NULL); boxselfaccess: KeySelf '.' Ident {AST_NODE_PTR boxselfaccess = AST_new_node(new_loc(@1), AST_List, NULL);
AST_NODE_PTR self = AST_new_node(new_loc(), AST_Ident, "self"); AST_NODE_PTR self = AST_new_node(new_loc(@1), AST_Ident, "self");
AST_push_node(boxselfaccess, self); AST_push_node(boxselfaccess, self);
AST_NODE_PTR identlist = AST_new_node(new_loc(), AST_IdentList, NULL); AST_NODE_PTR identlist = AST_new_node(new_loc(@1), AST_IdentList, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $3); AST_NODE_PTR ident = AST_new_node(new_loc(@3), AST_Ident, $3);
AST_push_node(identlist,ident); AST_push_node(identlist,ident);
AST_push_node(boxselfaccess, identlist); AST_push_node(boxselfaccess, identlist);
$$ = boxselfaccess;} $$ = boxselfaccess;}
| KeySelf '.' boxaccess {AST_NODE_PTR boxselfaccess = AST_new_node(new_loc(), AST_List, NULL); | KeySelf '.' boxaccess {AST_NODE_PTR boxselfaccess = AST_new_node(new_loc(@1), AST_List, NULL);
AST_NODE_PTR self = AST_new_node(new_loc(), AST_Ident, "self"); AST_NODE_PTR self = AST_new_node(new_loc(@1), AST_Ident, "self");
AST_push_node(boxselfaccess, self); AST_push_node(boxselfaccess, self);
AST_push_node(boxselfaccess, $3); AST_push_node(boxselfaccess, $3);
$$ = boxselfaccess;}; $$ = boxselfaccess;};
boxaccess: Ident '.' Ident {AST_NODE_PTR identlist = AST_new_node(new_loc(), AST_IdentList, NULL); boxaccess: Ident '.' Ident {AST_NODE_PTR identlist = AST_new_node(new_loc(@1), AST_IdentList, NULL);
AST_NODE_PTR ident1 = AST_new_node(new_loc(), AST_Ident, $1); AST_NODE_PTR ident1 = AST_new_node(new_loc(@1), AST_Ident, $1);
AST_NODE_PTR ident2 = AST_new_node(new_loc(), AST_Ident, $3); AST_NODE_PTR ident2 = AST_new_node(new_loc(@3), AST_Ident, $3);
AST_push_node(identlist,ident1); AST_push_node(identlist,ident1);
AST_push_node(identlist,ident2); AST_push_node(identlist,ident2);
$$ = identlist;} $$ = identlist;}
| Ident '.' boxaccess {AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $1); | Ident '.' boxaccess {AST_NODE_PTR ident = AST_new_node(new_loc(@1), AST_Ident, $1);
AST_push_node($3,ident); AST_push_node($3,ident);
$$ = $3;}; $$ = $3;};
boxcall: boxaccess argumentlist {AST_NODE_PTR boxcall = AST_new_node(new_loc(), AST_Call, NULL); boxcall: boxaccess argumentlist {AST_NODE_PTR boxcall = AST_new_node(new_loc(@1), AST_Call, NULL);
AST_push_node(boxcall, $1); AST_push_node(boxcall, $1);
AST_push_node(boxcall, $2); AST_push_node(boxcall, $2);
$$ = boxcall;} $$ = boxcall;}
| boxselfaccess argumentlist {AST_NODE_PTR boxcall = AST_new_node(new_loc(), AST_Call, NULL); | boxselfaccess argumentlist {AST_NODE_PTR boxcall = AST_new_node(new_loc(@1), AST_Call, NULL);
AST_push_node(boxcall, $1); AST_push_node(boxcall, $1);
AST_push_node(boxcall, $2); AST_push_node(boxcall, $2);
$$ = boxcall;}; $$ = boxcall;};
typecast: expr KeyAs type %prec KeyAs {AST_NODE_PTR cast = AST_new_node(new_loc(), AST_Typecast, NULL); typecast: expr KeyAs type %prec KeyAs {AST_NODE_PTR cast = AST_new_node(new_loc(@1), AST_Typecast, NULL);
AST_push_node(cast, $1); AST_push_node(cast, $1);
AST_push_node(cast, $3); AST_push_node(cast, $3);
$$ = cast; $$ = cast;
DEBUG("Type-Cast"); }; DEBUG("Type-Cast"); };
reinterpretcast: expr KeyTo type %prec KeyTo { AST_NODE_PTR cast = AST_new_node(new_loc(), AST_Transmute, NULL); reinterpretcast: expr KeyTo type %prec KeyTo { AST_NODE_PTR cast = AST_new_node(new_loc(@1), AST_Transmute, NULL);
AST_push_node(cast, $1); AST_push_node(cast, $1);
AST_push_node(cast, $3); AST_push_node(cast, $3);
$$ = cast; $$ = cast;
DEBUG("Reinterpret-Cast"); }; DEBUG("Reinterpret-Cast"); };
funcall: moduleref argumentlist {AST_NODE_PTR funcall = AST_new_node(new_loc(), AST_Call, NULL); funcall: moduleref argumentlist {AST_NODE_PTR funcall = AST_new_node(new_loc(@1), AST_Call, NULL);
AST_push_node(funcall, $1); AST_push_node(funcall, $1);
AST_push_node(funcall, $2); AST_push_node(funcall, $2);
$$ = funcall; $$ = funcall;
DEBUG("Function call"); }; DEBUG("Function call"); };
moduleimport: KeyImport ValStr {$$ = AST_new_node(new_loc(), AST_Import, $2); moduleimport: KeyImport ValStr {$$ = AST_new_node(new_loc(@1), AST_Import, $2);
DEBUG("Module-Import"); }; DEBUG("Module-Import"); };
moduleinclude: KeyInclude ValStr {$$ = AST_new_node(new_loc(), AST_Include, $2); moduleinclude: KeyInclude ValStr {$$ = AST_new_node(new_loc(@1), AST_Include, $2);
DEBUG("Module-Include"); }; DEBUG("Module-Include"); };
statementlist: statementlist statement {AST_push_node($1, $2); statementlist: statementlist statement {AST_push_node($1, $2);
$$ = $1;} $$ = $1;}
| statement {AST_NODE_PTR list = AST_new_node(new_loc(), AST_StmtList, NULL); | statement {AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_StmtList, NULL);
AST_push_node(list, $1); AST_push_node(list, $1);
$$ = list;}; $$ = list;};
@ -433,20 +433,20 @@ statement: assign {$$ = $1;}
| funcall {$$ = $1;} | funcall {$$ = $1;}
| boxcall{$$ = $1;}; | boxcall{$$ = $1;};
returnstmt: KeyReturn expr { AST_NODE_PTR return_stmt = AST_new_node(new_loc(), AST_Return, NULL); returnstmt: KeyReturn expr { AST_NODE_PTR return_stmt = AST_new_node(new_loc(@1), AST_Return, NULL);
AST_push_node(return_stmt, $2); AST_push_node(return_stmt, $2);
$$ = return_stmt; }; $$ = return_stmt; };
branchif: KeyIf expr '{' statementlist '}' { AST_NODE_PTR branch = AST_new_node(new_loc(), AST_If, NULL); branchif: KeyIf expr '{' statementlist '}' { AST_NODE_PTR branch = AST_new_node(new_loc(@1), AST_If, NULL);
AST_push_node(branch, $2); AST_push_node(branch, $2);
AST_push_node(branch, $4); AST_push_node(branch, $4);
$$ = branch; }; $$ = branch; };
branchelse: KeyElse '{' statementlist '}' { AST_NODE_PTR branch = AST_new_node(new_loc(), AST_Else, NULL); branchelse: KeyElse '{' statementlist '}' { AST_NODE_PTR branch = AST_new_node(new_loc(@1), AST_Else, NULL);
AST_push_node(branch, $3); AST_push_node(branch, $3);
$$ = branch; }; $$ = branch; };
branchelseif: KeyElse KeyIf expr '{' statementlist '}' { AST_NODE_PTR branch = AST_new_node(new_loc(), AST_IfElse, NULL); branchelseif: KeyElse KeyIf expr '{' statementlist '}' { AST_NODE_PTR branch = AST_new_node(new_loc(@1), AST_IfElse, NULL);
AST_push_node(branch, $3); AST_push_node(branch, $3);
AST_push_node(branch, $5); AST_push_node(branch, $5);
$$ = branch; }; $$ = branch; };
@ -454,119 +454,119 @@ branchelseif: KeyElse KeyIf expr '{' statementlist '}' { AST_NODE_PTR branch = A
branchfull: branchhalf { $$ = $1;}; branchfull: branchhalf { $$ = $1;};
|branchhalf branchelse { AST_push_node($1 , $2); |branchhalf branchelse { AST_push_node($1 , $2);
$$ = $1; } $$ = $1; }
branchhalf: branchif { AST_NODE_PTR branch = AST_new_node(new_loc(), AST_Stmt, NULL); branchhalf: branchif { AST_NODE_PTR branch = AST_new_node(new_loc(@1), AST_Stmt, NULL);
AST_push_node(branch, $1); AST_push_node(branch, $1);
$$ = branch; } $$ = branch; }
| branchhalf branchelseif { AST_push_node($1 , $2); | branchhalf branchelseif { AST_push_node($1 , $2);
$$ = $1; }; $$ = $1; };
while: KeyWhile expr '{' statementlist '}' {AST_NODE_PTR whilenode = AST_new_node(new_loc(), AST_While, NULL); while: KeyWhile expr '{' statementlist '}' {AST_NODE_PTR whilenode = AST_new_node(new_loc(@1), AST_While, NULL);
AST_push_node(whilenode, $2); AST_push_node(whilenode, $2);
AST_push_node(whilenode, $4); AST_push_node(whilenode, $4);
$$ = whilenode;}; $$ = whilenode;};
identlist: Ident ',' identlist {AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $1); identlist: Ident ',' identlist {AST_NODE_PTR ident = AST_new_node(new_loc(@1), AST_Ident, $1);
AST_push_node($3, ident); AST_push_node($3, ident);
$$ = $3;} $$ = $3;}
| Ident {AST_NODE_PTR list = AST_new_node(new_loc(), AST_IdentList, NULL); | Ident {AST_NODE_PTR list = AST_new_node(new_loc(@1), AST_IdentList, NULL);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $1); AST_NODE_PTR ident = AST_new_node(new_loc(@1), AST_Ident, $1);
AST_push_node(list, ident); AST_push_node(list, ident);
$$ = list;}; $$ = list;};
decl: type ':' identlist {AST_NODE_PTR decl = AST_new_node(new_loc(), AST_Decl, NULL); decl: type ':' identlist {AST_NODE_PTR decl = AST_new_node(new_loc(@1), AST_Decl, NULL);
AST_push_node(decl, $1); AST_push_node(decl, $1);
AST_push_node(decl, $3); AST_push_node(decl, $3);
$$ = decl;} $$ = decl;}
| storagequalifier type ':' identlist {AST_NODE_PTR decl = AST_new_node(new_loc(), AST_Decl, NULL); | storagequalifier type ':' identlist {AST_NODE_PTR decl = AST_new_node(new_loc(@1), AST_Decl, NULL);
AST_push_node(decl, $1); AST_push_node(decl, $1);
AST_push_node(decl, $2); AST_push_node(decl, $2);
AST_push_node(decl, $4); AST_push_node(decl, $4);
$$ = decl;}; $$ = decl;};
definition: decl '=' expr { AST_NODE_PTR def = AST_new_node(new_loc(), AST_Def, NULL); definition: decl '=' expr { AST_NODE_PTR def = AST_new_node(new_loc(@1), AST_Def, NULL);
AST_push_node(def, $1); AST_push_node(def, $1);
AST_push_node(def, $3); AST_push_node(def, $3);
$$ = def; $$ = def;
DEBUG("Definition"); }; DEBUG("Definition"); };
storagequalifier: KeyGlobal {$$ = AST_new_node(new_loc(), AST_Storage, "global");} storagequalifier: KeyGlobal {$$ = AST_new_node(new_loc(@1), AST_Storage, "global");}
| KeyStatic {$$ = AST_new_node(new_loc(), AST_Storage, "static");} | KeyStatic {$$ = AST_new_node(new_loc(@1), AST_Storage, "static");}
| KeyLocal {$$ = AST_new_node(new_loc(), AST_Storage, "local");}; | KeyLocal {$$ = AST_new_node(new_loc(@1), AST_Storage, "local");};
assign: storage_expr '=' expr { AST_NODE_PTR assign = AST_new_node(new_loc(), AST_Assign, NULL); assign: storage_expr '=' expr { AST_NODE_PTR assign = AST_new_node(new_loc(@1), AST_Assign, NULL);
AST_push_node(assign, $1); AST_push_node(assign, $1);
AST_push_node(assign, $3); AST_push_node(assign, $3);
$$ = assign; }; $$ = assign; };
storage_expr: Ident { $$ = AST_new_node(new_loc(), AST_Ident, $1); } storage_expr: Ident { $$ = AST_new_node(new_loc(@1), AST_Ident, $1); }
| boxaccess { $$ = $1; } | boxaccess { $$ = $1; }
| boxselfaccess { $$ = $1; } | boxselfaccess { $$ = $1; }
| storage_expr '[' expr ']' { AST_NODE_PTR deref = AST_new_node(new_loc(), AST_Dereference, NULL); | storage_expr '[' expr ']' { AST_NODE_PTR deref = AST_new_node(new_loc(@1), AST_Dereference, NULL);
AST_push_node(deref, $1); AST_push_node(deref, $1);
AST_push_node(deref, $3); AST_push_node(deref, $3);
$$ = deref; }; $$ = deref; };
sign: KeySigned {$$ = AST_new_node(new_loc(), AST_Sign, "signed");} sign: KeySigned {$$ = AST_new_node(new_loc(@1), AST_Sign, "signed");}
| KeyUnsigned{$$ = AST_new_node(new_loc(), AST_Sign, "unsigned");}; | KeyUnsigned{$$ = AST_new_node(new_loc(@1), AST_Sign, "unsigned");};
typedef: KeyType type':' Ident {AST_NODE_PTR typeDef = AST_new_node(new_loc(), AST_Typedef, NULL); typedef: KeyType type':' Ident {AST_NODE_PTR typeDef = AST_new_node(new_loc(@1), AST_Typedef, NULL);
AST_push_node(typeDef, $2); AST_push_node(typeDef, $2);
AST_NODE_PTR ident = AST_new_node(new_loc(), AST_Ident, $4); AST_NODE_PTR ident = AST_new_node(new_loc(@4), AST_Ident, $4);
AST_push_node(typeDef, ident); AST_push_node(typeDef, ident);
$$ = typeDef;}; $$ = typeDef;};
scale: scale KeyShort {AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "short"); scale: scale KeyShort {AST_NODE_PTR shortnode = AST_new_node(new_loc(@2), AST_Scale, "short");
AST_push_node($1, shortnode); AST_push_node($1, shortnode);
$$ = $1;} $$ = $1;}
| scale KeyHalf {AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "half"); | scale KeyHalf {AST_NODE_PTR shortnode = AST_new_node(new_loc(@2), AST_Scale, "half");
AST_push_node($1, shortnode); AST_push_node($1, shortnode);
$$ = $1;} $$ = $1;}
| scale KeyLong {AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "long"); | scale KeyLong {AST_NODE_PTR shortnode = AST_new_node(new_loc(@2), AST_Scale, "long");
AST_push_node($1, shortnode); AST_push_node($1, shortnode);
$$ = $1;} $$ = $1;}
| scale KeyDouble {AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "double"); | scale KeyDouble {AST_NODE_PTR shortnode = AST_new_node(new_loc(@2), AST_Scale, "double");
AST_push_node($1, shortnode); AST_push_node($1, shortnode);
$$ = $1;} $$ = $1;}
| KeyShort {AST_NODE_PTR scale = AST_new_node(new_loc(), AST_List, NULL); | KeyShort {AST_NODE_PTR scale = AST_new_node(new_loc(@1), AST_List, NULL);
AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "short"); AST_NODE_PTR shortnode = AST_new_node(new_loc(@1), AST_Scale, "short");
AST_push_node(scale, shortnode); AST_push_node(scale, shortnode);
$$ = scale;} $$ = scale;}
| KeyHalf {AST_NODE_PTR scale = AST_new_node(new_loc(), AST_List, NULL); | KeyHalf {AST_NODE_PTR scale = AST_new_node(new_loc(@1), AST_List, NULL);
AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "half"); AST_NODE_PTR shortnode = AST_new_node(new_loc(@1), AST_Scale, "half");
AST_push_node(scale, shortnode); AST_push_node(scale, shortnode);
$$ = scale;} $$ = scale;}
| KeyLong {AST_NODE_PTR scale = AST_new_node(new_loc(), AST_List, NULL); | KeyLong {AST_NODE_PTR scale = AST_new_node(new_loc(@1), AST_List, NULL);
AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "long"); AST_NODE_PTR shortnode = AST_new_node(new_loc(@1), AST_Scale, "long");
AST_push_node(scale, shortnode); AST_push_node(scale, shortnode);
$$ = scale;} $$ = scale;}
| KeyDouble {AST_NODE_PTR scale = AST_new_node(new_loc(), AST_List, NULL); | KeyDouble {AST_NODE_PTR scale = AST_new_node(new_loc(@1), AST_List, NULL);
AST_NODE_PTR shortnode = AST_new_node(new_loc(), AST_Scale, "double"); AST_NODE_PTR shortnode = AST_new_node(new_loc(@1), AST_Scale, "double");
AST_push_node(scale, shortnode); AST_push_node(scale, shortnode);
$$ = scale;}; $$ = scale;};
typekind: Ident {$$ = AST_new_node(new_loc(), AST_Typekind, $1);} typekind: Ident {$$ = AST_new_node(new_loc(@1), AST_Typekind, $1);}
| KeyInt {$$ = AST_new_node(new_loc(), AST_Typekind, "int");} | KeyInt {$$ = AST_new_node(new_loc(@1), AST_Typekind, "int");}
| KeyFloat {$$ = AST_new_node(new_loc(), AST_Typekind, "float");}; | KeyFloat {$$ = AST_new_node(new_loc(@1), AST_Typekind, "float");};
type: typekind {AST_NODE_PTR type = AST_new_node(new_loc(), AST_Type, NULL); type: typekind {AST_NODE_PTR type = AST_new_node(new_loc(@1), AST_Type, NULL);
AST_push_node(type, $1); AST_push_node(type, $1);
$$ = type;} $$ = type;}
| scale typekind {AST_NODE_PTR type = AST_new_node(new_loc(), AST_Type, NULL); | scale typekind {AST_NODE_PTR type = AST_new_node(new_loc(@1), AST_Type, NULL);
AST_push_node(type, $1); AST_push_node(type, $1);
AST_push_node(type, $2); AST_push_node(type, $2);
$$ = type;} $$ = type;}
| sign typekind {AST_NODE_PTR type = AST_new_node(new_loc(), AST_Type, NULL); | sign typekind {AST_NODE_PTR type = AST_new_node(new_loc(@1), AST_Type, NULL);
AST_push_node(type, $1); AST_push_node(type, $1);
AST_push_node(type, $2); AST_push_node(type, $2);
$$ = type;} $$ = type;}
| sign scale typekind {AST_NODE_PTR type = AST_new_node(new_loc(), AST_Type, NULL); | sign scale typekind {AST_NODE_PTR type = AST_new_node(new_loc(@1), AST_Type, NULL);
AST_push_node(type, $1); AST_push_node(type, $1);
AST_push_node(type, $2); AST_push_node(type, $2);
AST_push_node(type, $3); AST_push_node(type, $3);
$$ = type;} $$ = type;}
| KeyRef type {AST_NODE_PTR reftype = AST_new_node(new_loc(), AST_Reference, NULL); | KeyRef type {AST_NODE_PTR reftype = AST_new_node(new_loc(@1), AST_Reference, NULL);
AST_push_node(reftype, $2); AST_push_node(reftype, $2);
$$ = reftype; }; $$ = reftype; };
@ -575,74 +575,74 @@ operation: oparith {$$ = $1;}
| opbool {$$ = $1;} | opbool {$$ = $1;}
| opbit {$$ = $1;}; | opbit {$$ = $1;};
oparith: expr '+' expr {AST_NODE_PTR add = AST_new_node(new_loc(), AST_Add, NULL); oparith: expr '+' expr {AST_NODE_PTR add = AST_new_node(new_loc(@1), AST_Add, NULL);
AST_push_node(add, $1); AST_push_node(add, $1);
AST_push_node(add, $3); AST_push_node(add, $3);
$$ = add;} $$ = add;}
| expr '-' expr {AST_NODE_PTR subtract = AST_new_node(new_loc(), AST_Sub, NULL); | expr '-' expr {AST_NODE_PTR subtract = AST_new_node(new_loc(@1), AST_Sub, NULL);
AST_push_node(subtract, $1); AST_push_node(subtract, $1);
AST_push_node(subtract, $3); AST_push_node(subtract, $3);
$$ = subtract;} $$ = subtract;}
| expr '*' expr {AST_NODE_PTR mul = AST_new_node(new_loc(), AST_Mul, NULL); | expr '*' expr {AST_NODE_PTR mul = AST_new_node(new_loc(@1), AST_Mul, NULL);
AST_push_node(mul, $1); AST_push_node(mul, $1);
AST_push_node(mul, $3); AST_push_node(mul, $3);
$$ = mul;} $$ = mul;}
| expr '/' expr {AST_NODE_PTR div = AST_new_node(new_loc(), AST_Div, NULL); | expr '/' expr {AST_NODE_PTR div = AST_new_node(new_loc(@1), AST_Div, NULL);
AST_push_node(div, $1); AST_push_node(div, $1);
AST_push_node(div, $3); AST_push_node(div, $3);
$$ = div;} $$ = div;}
| '-' expr %prec '*'{AST_NODE_PTR negator = AST_new_node(new_loc(), AST_Negate, NULL); | '-' expr %prec '*'{AST_NODE_PTR negator = AST_new_node(new_loc(@1), AST_Negate, NULL);
AST_push_node(negator, $2); AST_push_node(negator, $2);
$$ = negator;}; $$ = negator;};
oplogic: expr OpEquals expr {AST_NODE_PTR equals = AST_new_node(new_loc(), AST_Eq, NULL); oplogic: expr OpEquals expr {AST_NODE_PTR equals = AST_new_node(new_loc(@1), AST_Eq, NULL);
AST_push_node(equals, $1); AST_push_node(equals, $1);
AST_push_node(equals, $3); AST_push_node(equals, $3);
$$ = equals;} $$ = equals;}
| expr '<' expr {AST_NODE_PTR less = AST_new_node(new_loc(), AST_Less, NULL); | expr '<' expr {AST_NODE_PTR less = AST_new_node(new_loc(@1), AST_Less, NULL);
AST_push_node(less, $1); AST_push_node(less, $1);
AST_push_node(less, $3); AST_push_node(less, $3);
$$ = less;} $$ = less;}
| expr '>' expr{AST_NODE_PTR greater = AST_new_node(new_loc(), AST_Greater, NULL); | expr '>' expr{AST_NODE_PTR greater = AST_new_node(new_loc(@1), AST_Greater, NULL);
AST_push_node(greater, $1); AST_push_node(greater, $1);
AST_push_node(greater, $3); AST_push_node(greater, $3);
$$ = greater;}; $$ = greater;};
opbool: expr OpAnd expr {AST_NODE_PTR and = AST_new_node(new_loc(), AST_BoolAnd, NULL); opbool: expr OpAnd expr {AST_NODE_PTR and = AST_new_node(new_loc(@1), AST_BoolAnd, NULL);
AST_push_node(and, $1); AST_push_node(and, $1);
AST_push_node(and, $3); AST_push_node(and, $3);
$$ = and;} $$ = and;}
| expr OpOr expr{AST_NODE_PTR or = AST_new_node(new_loc(), AST_BoolOr, NULL); | expr OpOr expr{AST_NODE_PTR or = AST_new_node(new_loc(@1), AST_BoolOr, NULL);
AST_push_node(or, $1); AST_push_node(or, $1);
AST_push_node(or, $3); AST_push_node(or, $3);
$$ = or;} $$ = or;}
| expr OpXor expr{AST_NODE_PTR xor = AST_new_node(new_loc(), AST_BoolXor, NULL); | expr OpXor expr{AST_NODE_PTR xor = AST_new_node(new_loc(@1), AST_BoolXor, NULL);
AST_push_node(xor, $1); AST_push_node(xor, $1);
AST_push_node(xor, $3); AST_push_node(xor, $3);
$$ = xor;} $$ = xor;}
| OpNot expr %prec OpAnd{AST_NODE_PTR not = AST_new_node(new_loc(), AST_BoolNot, NULL); | OpNot expr %prec OpAnd{AST_NODE_PTR not = AST_new_node(new_loc(@1), AST_BoolNot, NULL);
AST_push_node(not, $2); AST_push_node(not, $2);
$$ = not;}; $$ = not;};
opbit: expr OpBitand expr {AST_NODE_PTR and = AST_new_node(new_loc(), AST_BitAnd, NULL); opbit: expr OpBitand expr {AST_NODE_PTR and = AST_new_node(new_loc(@1), AST_BitAnd, NULL);
AST_push_node(and, $1); AST_push_node(and, $1);
AST_push_node(and, $3); AST_push_node(and, $3);
$$ = and;} $$ = and;}
| expr OpBitor expr{AST_NODE_PTR or = AST_new_node(new_loc(), AST_BitOr, NULL); | expr OpBitor expr{AST_NODE_PTR or = AST_new_node(new_loc(@1), AST_BitOr, NULL);
AST_push_node(or, $1); AST_push_node(or, $1);
AST_push_node(or, $3); AST_push_node(or, $3);
$$ = or;} $$ = or;}
| expr OpBitxor expr{AST_NODE_PTR xor = AST_new_node(new_loc(), AST_BitXor, NULL); | expr OpBitxor expr{AST_NODE_PTR xor = AST_new_node(new_loc(@1), AST_BitXor, NULL);
AST_push_node(xor, $1); AST_push_node(xor, $1);
AST_push_node(xor, $3); AST_push_node(xor, $3);
$$ = xor;} $$ = xor;}
| OpBitnot expr %prec OpBitand{AST_NODE_PTR not = AST_new_node(new_loc(), AST_BitNot, NULL); | OpBitnot expr %prec OpBitand{AST_NODE_PTR not = AST_new_node(new_loc(@1), AST_BitNot, NULL);
AST_push_node(not, $2); AST_push_node(not, $2);
$$ = not;}; $$ = not;};
%% %%
int yyerror(const char *s) { int yyerror(const char *s) {
TokenLocation location = new_loc(); TokenLocation location = new_loc(yylloc);
print_diagnostic(&location, Error, s); print_diagnostic(&location, Error, s);
return 0; return 0;
} }