Exemplo n.º 1
0
        public override void Compile(ICompiler cmp, bool reverse)
        {
            int     gid  = group.Number;
            LinkRef tail = cmp.NewLink();

            if (FalseExpression == null)
            {
                //    IfDefined :1
                //      <yes_exp>
                // 1: <tail>

                cmp.EmitIfDefined(gid, tail);
                TrueExpression.Compile(cmp, reverse);
            }
            else
            {
                //    IfDefined :1
                //      <yes_expr>
                //      Jump :2
                // 1:   <no_expr>
                // 2: <tail>

                LinkRef false_expr = cmp.NewLink();
                cmp.EmitIfDefined(gid, false_expr);
                TrueExpression.Compile(cmp, reverse);
                cmp.EmitJump(tail);
                cmp.ResolveLink(false_expr);
                FalseExpression.Compile(cmp, reverse);
            }

            cmp.ResolveLink(tail);
        }
Exemplo n.º 2
0
        public override void Compile(ICompiler cmp, bool reverse)
        {
            LinkRef true_expr  = cmp.NewLink();
            LinkRef false_expr = cmp.NewLink();

            // test op: positive / negative

            if (!negate)
            {
                cmp.EmitTest(true_expr, false_expr);
            }
            else
            {
                cmp.EmitTest(false_expr, true_expr);
            }

            // test expression: lookahead / lookbehind

            TestExpression.Compile(cmp, this.reverse);
            cmp.EmitTrue();

            // target expressions

            if (TrueExpression == null)                                 // (?= ...)
            //    Test :1, :2
            //      <test_expr>
            // :2   False
            // :1   <tail>

            {
                cmp.ResolveLink(false_expr);
                cmp.EmitFalse();
                cmp.ResolveLink(true_expr);
            }
            else
            {
                cmp.ResolveLink(true_expr);
                TrueExpression.Compile(cmp, reverse);

                if (FalseExpression == null)                            // (?(...) ...)
                //    Test :1, :2
                //      <test_expr>
                // :1   <yes_expr>
                // :2   <tail>

                {
                    cmp.ResolveLink(false_expr);
                }
                else                                                    // (?(...) ... | ...)
                //    Test :1, :2
                //      <test_expr>
                // :1   <yes_expr>
                //      Jump :3
                // :2   <no_expr>
                // :3   <tail>

                {
                    LinkRef tail = cmp.NewLink();

                    cmp.EmitJump(tail);
                    cmp.ResolveLink(false_expr);
                    FalseExpression.Compile(cmp, reverse);
                    cmp.ResolveLink(tail);
                }
            }
        }