mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user