Example #1
0
        private void ProcessLetStatement(NodeBase statement)
        {
            Queue <NodeBase> children = GetChildren(statement);

            Expect(children.Dequeue(), NodeType.Keyword, "let");
            Identifier identifier = GetIdentifier(children.Dequeue());

            if (PeekValue(children) == "[")
            {
                Expect(children.Dequeue(), NodeType.Symbol, "[");
                ProcessExpression(children.Dequeue());
                vmWriter.Push(identifier);
                vmWriter.IndexArray();
                Expect(children.Dequeue(), NodeType.Symbol, "]");
                Expect(children.Dequeue(), NodeType.Symbol, "=");
                ProcessExpression(children.Dequeue());
                Expect(children.Dequeue(), NodeType.Symbol, ";");
                vmWriter.AssignArray();
            }
            else
            {
                Expect(children.Dequeue(), NodeType.Symbol, "=");
                ProcessExpression(children.Dequeue());
                Expect(children.Dequeue(), NodeType.Symbol, ";");
                vmWriter.Pop(identifier);
            }
        }