示例#1
0
        public Type Visit(ListIndexNode node)
        {
            Type type      = Visit((dynamic)node[0]);
            Type indexType = Visit((dynamic)node[1]);

            node.extra = type;
            if (indexType != Type.INT)
            {
                throw new SemanticError($"List indexes should be {Type.INT}, got {indexType}", node[1].AnchorToken);
            }
            return(type.FromListType());
        }
示例#2
0
        public Node SimpleExpression()
        {
            Node node = null;

            if (Has(TokenCategory.PARENTHESIS_OPEN))
            {
                Expect(TokenCategory.PARENTHESIS_OPEN);
                node = Expression();
                Expect(TokenCategory.PARENTHESIS_CLOSE);
            }
            else if (Has(TokenCategory.IDENTIFIER))
            {
                node = Node.fromToken(Expect(TokenCategory.IDENTIFIER));
                // May be a call
                if (Has(TokenCategory.PARENTHESIS_OPEN))
                {
                    var call_node = new CallNode()
                    {
                        AnchorToken = node.AnchorToken
                    };
                    Expect(TokenCategory.PARENTHESIS_OPEN);
                    if (Has(firstOfExpression))
                    {
                        call_node.Add(Expression());
                        call_node.Add(ZeroOrMore(TokenCategory.COMMA, Expression, true));
                    }
                    Expect(TokenCategory.PARENTHESIS_CLOSE);
                    node = call_node;
                }
            }
            else if (Has(firstOfLiteral))
            {
                node = Literal();
            }
            else
            {
                throw new SyntaxError(firstOfSimpleExpression, tokenStream.Current);
            }

            if (Has(TokenCategory.BRACKET_OPEN))
            {
                Expect(TokenCategory.BRACKET_OPEN);
                var indexNode = new ListIndexNode()
                {
                    node, Expression()
                };
                Expect(TokenCategory.BRACKET_CLOSE);
                return(indexNode);
            }
            return(node);
        }
示例#3
0
        public void Visit(ListIndexNode node)
        {
            Visit((dynamic)node[0]);
            Visit((dynamic)node[1]);
            Type type = node.extra;

            if (!node.isAssignment)
            {
                switch (type)
                {
                case Type.BOOL_LIST:
                case Type.INT_LIST:
                    builder.AppendLine("\t\tldelem.i4");
                    break;

                case Type.STRING_LIST:
                    builder.AppendLine("\t\tldelem.ref");
                    break;
                }
            }
        }