private DeclarationStatement Consume_BlockDeclaration() { Token token = currentToken; switch (token.Type) { case TokenType.L_BLOCK: Consume(TokenType.L_BLOCK); BlockDeclarationExpression declStmt = new BlockDeclarationExpression(); string variableType = "Block"; string variableName = currentToken.Value.ToString(); StringLiteral lit = ExpressionFactory.CreateStringLiteral(variableName, currentToken); declStmt.SetType(variableType); declStmt.SetName(variableName); Consume(TokenType.ID); Consume(TokenType.R_BLOCK); BlockStatement blockStmt = Consume_BlockStatement(); blockStmt.Append(Consume_EndBlock()); declStmt.SetExpression(blockStmt); return(declStmt); } throw RaiseError(ScriptErrorCode.UNEXPECTED_TOKEN, token); }
public object Visit_BlockDeclarationStatement(BlockDeclarationExpression declExpr) { string varName = declExpr.Name; Current[varName] = new BlockValue(declExpr.Expression); return(0); }
public object Visit_BlockDeclarationStatement(BlockDeclarationExpression declExpr) { if (currentTable.LookUp("Block", out ISymbol symbol)) { string symbolName = (string)declExpr.Name; ISymbol varSymbol = new VariableSymbol(symbolName, symbol); if (!currentTable.Define(varSymbol)) { throw RaiseError(ScriptErrorCode.ID_ALREADY_DECLARED, declExpr.Token); } } return(0); }