public bool Visit(ArrayAccess node)
        {
            if (node.SymType != null)
            {
                return(true);
            }

            node.ArrayIdent.Accept(this);
            foreach (var expression in node.AccessExpr)
            {
                expression.Accept(this);
                if (expression.SymType.GetType() != SymbolStack.SymInt.GetType())
                {
                    throw new Exception(string.Format(
                                            "({0}, {1}) semantic error: index '{2}' is not integer",
                                            expression.Token.Line, expression.Token.Line, expression.ToString()));
                }
            }

            if (node.ArrayIdent.SymType == null)
            {
                throw new Exception(string.Format(
                                        "({0}, {1}) semantic error: array type of expression '{2}' is undeclared",
                                        node.Token.Line, node.Token.Line, node.ToString()));
            }

            node.SymType  = ((SymArrayType)node.ArrayIdent.SymType).ElementSymType;
            node.IsLValue = true;
            return(true);
        }
Exemplo n.º 2
0
        public AstPrinterNode Visit(ArrayAccess node)
        {
            var printer = new AstPrinterNode(node.ToString());

            printer.AddChild(node.ArrayIdent.Accept(this));
            foreach (var expr in node.AccessExpr)
            {
                printer.AddChild(expr.Accept(this));
            }

            return(printer);
        }