private VariableDeclaration ParseVariableDeclaration() { VariableDeclaration variableDeclaration = null; if (_currentToken.TheTokenType.Equals(Token.TokenType.VARIABLE_TYPE)) { var variableType = new VariableType(Accept(Token.TokenType.VARIABLE_TYPE)); var variableName = new UserCreatableID(Accept(Token.TokenType.USER_CREATABLE_ID)); Expression1 expression = null; if (_currentToken.TheTokenType.Equals(Token.TokenType.ASSIGNMENT)) { Accept(Token.TokenType.ASSIGNMENT); expression = ParseExpression1(); } variableDeclaration = new VariableDeclarationSimple(variableType, variableName, expression); } else if (Token.TokenType.COOK == _currentToken.TheTokenType) { variableDeclaration = new VariableDeclarationStructVariableDeclaration(ParseStructVariableDeclaration()); } Accept(Token.TokenType.SEMICOLON); return(variableDeclaration); }
public object VisitVariableDeclarationStructVariableDeclaration(VariableDeclarationStructVariableDeclaration variableDeclarationStructVariableDeclaration, object o) { variableDeclarationStructVariableDeclaration.StructVariableDeclaration.Visit(this); foreach (VariableDeclaration variableDeclaration in variableDeclarationStructVariableDeclaration.VariableDeclarations) { variableDeclaration.Visit(this); } return(null); }
public object VisitVariableDeclarationStructVariableDeclaration(VariableDeclarationStructVariableDeclaration variableDeclarationStructVariableDeclaration, object o) { variableDeclarationStructVariableDeclaration.StructVariableDeclaration.Visit(this); idTable.Add(variableDeclarationStructVariableDeclaration.StructVariableDeclaration.VariableName, variableDeclarationStructVariableDeclaration, IDTable.DeclarationType.VARIABLE); Struct @struct = ((DeclarationStruct)idTable.Lookup(variableDeclarationStructVariableDeclaration.StructVariableDeclaration.StructName, IDTable.DeclarationType.STRUCT)).Struct; variableDeclarationStructVariableDeclaration.VariableDeclarations = @struct.VariableDeclarationList.VariableDeclarations.Select <VariableDeclaration, VariableDeclaration>(variableDeclaration => { if (variableDeclaration is VariableDeclarationSimple variableDeclarationSimple) { return(new VariableDeclarationSimple(variableDeclarationSimple.VariableType, variableDeclarationSimple.Name, variableDeclarationSimple.Expression) { Address = new Address(idTable.IsGlobalScope) }); } var variableDeclarationStruct = (VariableDeclarationStructVariableDeclaration)variableDeclaration; var newStructVariableDeclaration = new VariableDeclarationStructVariableDeclaration(new StructVariableDeclaration(variableDeclarationStruct.StructVariableDeclaration.StructName, variableDeclarationStruct.StructVariableDeclaration.VariableName)); newStructVariableDeclaration.Visit(this); return(newStructVariableDeclaration); }).ToList(); return(null); }