Exemplo n.º 1
0
        private void TunnelingProcessNode(SyntaxTreeNode node)
        {
            if (node.Value is Nonterminal && !node.IsEpsilon)
            {
                var nonterminal = node.Value as Nonterminal;

                if (nonterminal.Equals(FormalNonterminals.IF_STATEMENT))
                {
                    node.Value[END_BLOCK_LABEL_KEY] = _code.Helper.GetTempLabel();

                    if (!node[FormalNonterminals.ELSE_BLOCK].IsEpsilon)
                    {
                        node[FormalNonterminals.ELSE_BLOCK].Value[BEGIN_BLOCK_LABEL_KEY] = _code.Helper.GetTempLabel();
                    }
                }

                if (nonterminal.Equals(FormalNonterminals.ELSE_BLOCK))
                {
                    _code.Emit(new Instruction(OpCode.LTRGT, (Operand)node.Value[BEGIN_BLOCK_LABEL_KEY], null, null));
                }

                if (nonterminal.Equals(FormalNonterminals.FOR_STATEMENT))
                {
                    node.Value[END_BLOCK_LABEL_KEY] = _code.Helper.GetTempLabel();

                    node[FormalNonterminals.FOR_TEST_BLOCK].Value[BEGIN_BLOCK_LABEL_KEY] = _code.Helper.GetTempLabel();
                    node[FormalNonterminals.FOR_STEP_BLOCK].Value[BEGIN_BLOCK_LABEL_KEY] = _code.Helper.GetTempLabel();
                    node[FormalNonterminals.FOR_BODY_BLOCK].Value[BEGIN_BLOCK_LABEL_KEY] = _code.Helper.GetTempLabel();
                }

                if (nonterminal.Equals(FormalNonterminals.FOR_TEST_BLOCK) || nonterminal.Equals(FormalNonterminals.FOR_STEP_BLOCK) || nonterminal.Equals(FormalNonterminals.FOR_BODY_BLOCK))
                {
                    _code.Emit(new Instruction(OpCode.LTRGT, (Operand)node.Value[BEGIN_BLOCK_LABEL_KEY], null, null));
                }
            }
        }
Exemplo n.º 2
0
        private void TunnelingProcessNode(SyntaxTreeNode node)
        {
            if (!node.HasNoChildren && node.Value is Nonterminal)
            {
                var nonterminal = node.Value as Nonterminal;

                if (nonterminal.Equals(MyNonterminals.IF_STATEMENT))
                {
                    var ifBeginLabel = _code.Helper.GetTempLabel();
                    var ifEndLabel   = _code.Helper.GetTempLabel();

                    node.Value.Attributes[IF_BEGIN_LABEL_KEY] = ifBeginLabel;
                    node.Value.Attributes[IF_END_LABEL_KEY]   = ifEndLabel;
                }
                else if (nonterminal.Equals(MyNonterminals.THEN_BLOCK) || nonterminal.Equals(MyNonterminals.ELSE_BLOCK))
                {
                    if (nonterminal.Equals(MyNonterminals.THEN_BLOCK))
                    {
                        _code.Emit(new Instruction(OpCode.JMP, node.Parent.Value[IF_BEGIN_LABEL_KEY] as Operand, null, null));
                    }

                    var blockBeginLabel = _code.Helper.GetTempLabel();

                    node.Value.Attributes[LABEL_KEY] = blockBeginLabel;

                    _code.Emit(new Instruction(OpCode.LTRGT, blockBeginLabel, null, null));
                }
            }
        }