Global variables (#378)

* global variables

* implemented type checking of global variable, added test case

* added a comment

* improvements based on Dave's suggestions

* improvements based on Jon's suggestions

* added test cases about global variable ordering
This commit is contained in:
Jeremy G. Siek
2021-03-15 16:06:27 -04:00
committed by GitHub
parent 41786eae25
commit ced98ef021
22 changed files with 822 additions and 3 deletions
+11 -3
View File
@@ -86,6 +86,7 @@ void yy::parser::error(
%type <Carbon::Expression*> return_type
%type <Carbon::Expression*> paren_expression
%type <Carbon::Expression*> tuple
%type <Carbon::Member*> variable_declaration
%type <Carbon::Member*> member
%type <std::list<Carbon::Member*>*> member_list
%type <Carbon::FieldList*> field
@@ -321,9 +322,11 @@ function_declaration:
FN identifier tuple return_type ";"
{ $$ = MakeFunDef(yylineno, $2, $4, $3, 0); }
;
member:
VAR expression ":" identifier ";"
{ $$ = MakeField(yylineno, $4, $2); }
variable_declaration: expression ":" identifier
{ $$ = MakeField(yylineno, $3, $1); }
;
member: VAR variable_declaration ";"
{ $$ = $2; }
;
member_list:
// Empty
@@ -368,6 +371,11 @@ declaration:
$$ = new Carbon::Declaration(
Carbon::ChoiceDeclaration{yylineno, $2, std::list(*$4)});
}
| VAR variable_declaration "=" expression ";"
{
$$ = new Carbon::Declaration(
Carbon::VariableDeclaration(yylineno, *$2->u.field.name, $2->u.field.type, $4));
}
;
declaration_list:
// Empty