private XppParserSymbol Pop()
        {
            XppParserSymbol o = Peek(0);

            nodeStack.RemoveAt(nodeStack.Count - 1);
            return(o);
        }
 public XppCompareExpr(XppTokenType opToken, XppParserSymbol left, XppParserSymbol right)
 {
     this.opToken = opToken;
     this.left    = left;
     this.right   = right;
 }
 public XppRegexExpr(XppParserSymbol val, XppParserSymbol pattern, bool not)
 {
     this.val     = val;
     this.pattern = pattern;
     this.not     = not;
 }
        private void EvaluateStack()
        {
            bool repeat;

            do
            {
                repeat = false;
                XppParserSymbol top = Peek(0);
                switch (top.TokenType)
                {
                case XppTokenType.Production:
                    if (top.IsExpr)
                    {
                        XppTokenType tt1 = Peek(1).TokenType;
                        if (tt1 == XppTokenType.NOT)
                        {
                            XppParserSymbol expr = Pop();
                            Pop();
                            Push(new XppParserSymbol(XppTokenType.Production, null, new XppAstNotExpr((XppAstExpr)expr.Node)));
                            repeat = true;
                            continue;
                        }
                        else if (tt1 == XppTokenType.AND || tt1 == XppTokenType.OR)
                        {
                            if (Peek(2).IsExpr)
                            {
                                XppParserSymbol right = Pop();
                                Pop();                                         // operand
                                XppParserSymbol left = Pop();
                                Push(
                                    new XppParserSymbol(XppTokenType.Production, null,
                                                        new XppCompositeExpr(tt1 == XppTokenType.OR, (XppAstExpr)left.Node, (XppAstExpr)right.Node)));
                            }
                        }
                    }
                    break;

                case XppTokenType.Rparen:
                    if (Peek(1).IsExpr)
                    {
                        if (Peek(2).TokenType == XppTokenType.Lparen)
                        {
                            Pop();
                            XppParserSymbol expr = Pop();
                            Pop();
                            Push(expr);
                            repeat = true;
                            continue;
                        }
                    }
                    throw new ArgumentException("Didn't expect a right parenthesis here");

                case XppTokenType.Identifier:
                case XppTokenType.StringLiteral:
                case XppTokenType.VersionLiteral:
                    switch (Peek(1).TokenType)
                    {
                    case XppTokenType.LT:
                    case XppTokenType.LTE:
                    case XppTokenType.EQ:
                    case XppTokenType.NEQ:
                    case XppTokenType.GT:
                    case XppTokenType.GTE:
                        XppTokenType tt2 = Peek(2).TokenType;
                        if (tt2 == XppTokenType.StringLiteral || tt2 == XppTokenType.Identifier || tt2 == XppTokenType.VersionLiteral)
                        {
                            XppParserSymbol right = Pop();
                            XppParserSymbol op    = Pop();
                            XppParserSymbol left  = Pop();
                            Push(new XppParserSymbol(XppTokenType.Production, null, new XppCompareExpr(op.TokenType, left, right)));
                            repeat = true;
                            continue;
                        }
                        break;
                    }

                    if (top.TokenType == XppTokenType.Identifier && (Peek(1).TokenType == XppTokenType.REGEX || Peek(1).TokenType == XppTokenType.NOTREGEX))
                    {
                        XppTokenType tt2 = Peek(2).TokenType;
                        if (tt2 == XppTokenType.StringLiteral || tt2 == XppTokenType.Identifier)
                        {
                            bool not = Peek(1).TokenType == XppTokenType.NOTREGEX;

                            XppParserSymbol pattern = Pop();
                            Pop();
                            XppParserSymbol val = Pop();
                            Push(new XppParserSymbol(XppTokenType.Production, null, new XppRegexExpr(val, pattern, not)));
                        }
                    }
                    break;

                case XppTokenType.RegexLiteral:
                    if (Peek(1).TokenType == XppTokenType.REGEX || Peek(1).TokenType == XppTokenType.NOTREGEX)
                    {
                        bool not = Peek(1).TokenType == XppTokenType.NOTREGEX;

                        XppTokenType tt2 = Peek(2).TokenType;
                        if (tt2 == XppTokenType.StringLiteral || tt2 == XppTokenType.Identifier)
                        {
                            XppParserSymbol pattern = Pop();
                            Pop();
                            XppParserSymbol val = Pop();
                            Push(new XppParserSymbol(XppTokenType.Production, null, new XppRegexExpr(val, pattern, not)));
                            repeat = true;
                            continue;
                        }
                    }
                    throw new ArgumentException("Didn't expect a regex literal here");

                case XppTokenType.TRUE:
                case XppTokenType.FALSE:
                    Pop();
                    Push(new XppParserSymbol(XppTokenType.Production, null, new XppBoolLiteralExpr(top.TokenType == XppTokenType.TRUE)));
                    repeat = true;
                    continue;
                }
            } while (repeat);
        }
 private XppParserSymbol Push(XppParserSymbol o)
 {
     nodeStack.Add(o);
     return(o);
 }
 public XppCompareExpr(XppTokenType opToken, XppParserSymbol left, XppParserSymbol right)
 {
     this.opToken = opToken;
     this.left = left;
     this.right = right;
 }
 public XppRegexExpr(XppParserSymbol val, XppParserSymbol pattern, bool not)
 {
     this.val = val;
     this.pattern = pattern;
     this.not = not;
 }
 private XppParserSymbol Push(XppParserSymbol o)
 {
     nodeStack.Add(o);
     return o;
 }