Пример #1
0
        private Expression ParseExpr(int precedence)
        {
            Expression ret = ParseFactor();
            while (true) {
                Token t = PeekToken();
                OperatorToken ot = t as OperatorToken;
                if (ot == null) return ret;

                int prec = ot.Precedence;
                if (prec >= precedence) {
                    NextToken();
                    string whiteSpace = _tokenWhiteSpace;
                    Expression right = ParseExpr(prec + 1);
                    var start = ret.StartIndex;
                    ret = new BinaryExpression(GetBinaryOperator(ot), ret, right);
                    if (_verbatim) {
                        AddPreceedingWhiteSpace(ret, whiteSpace);
                    }
                    ret.SetLoc(start, GetEnd());
                } else {
                    return ret;
                }
            }
        }
Пример #2
0
 // power: atom trailer* ['**' factor]
 private Expression ParsePower()
 {
     Expression ret = ParsePrimary();
     ret = AddTrailers(ret);
     if (MaybeEat(TokenKind.Power)) {
         var start = ret.StartIndex;
         string whitespace = _tokenWhiteSpace;
         ret = new BinaryExpression(JOperator.Power, ret, ParseFactor());
         if (_verbatim) {
             AddPreceedingWhiteSpace(ret, whitespace);
         }
         ret.SetLoc(start, GetEnd());
     }
     return ret;
 }
Пример #3
0
        //comparison: expr (comp_op expr)*
        //comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
        private Expression ParseComparison()
        {
            Expression ret = ParseStarExpression();
            while (true) {
                JOperator op;
                string whitespaceBeforeOperator = _lookaheadWhiteSpace;
                string secondWhiteSpace = null;
                bool isLessThanGreaterThan = false, isIncomplete = false;
                switch (PeekToken().Kind) {
                    case TokenKind.LessThan:  NextToken();  op = JOperator.LessThan;  break;
                    case TokenKind.LessThanOrEqual:  NextToken();  op = JOperator.LessThanOrEqual;  break;
                    case TokenKind.GreaterThan:  NextToken();  op = JOperator.GreaterThan;  break;
                    case TokenKind.GreaterThanOrEqual:  NextToken();  op = JOperator.GreaterThanOrEqual;  break;
                    case TokenKind.Equals:  NextToken();  op = JOperator.Equal;  break;
                    case TokenKind.NotEquals:  NextToken();  op = JOperator.NotEqual;  break;
                    case TokenKind.LessThanGreaterThan: NextToken(); op = JOperator.NotEqual; isLessThanGreaterThan = true; break;
                    case TokenKind.KeywordIn:  NextToken();  op = JOperator.In;  break;

                    case TokenKind.KeywordNot: NextToken(); isIncomplete = !Eat(TokenKind.KeywordIn); secondWhiteSpace = _tokenWhiteSpace; op = JOperator.NotIn; break;

                    case TokenKind.KeywordIs:
                        NextToken();
                        if (MaybeEat(TokenKind.KeywordNot)) {
                            op = JOperator.IsNot;
                            secondWhiteSpace = _tokenWhiteSpace;
                        } else {
                            op = JOperator.Is;
                        }
                        break;
                    default:
                        return ret;
                }
                Expression rhs = ParseComparison();
                BinaryExpression be = new BinaryExpression(op, ret, rhs);
                if (_verbatim) {
                    AddPreceedingWhiteSpace(be, whitespaceBeforeOperator);
                    GetNodeAttributes(be)[NodeAttributes.SecondPreceedingWhiteSpace] = secondWhiteSpace;
                    if (isLessThanGreaterThan) {
                        AddVerbatimImage(be, "<>");
                    }
                    if (isIncomplete) {
                        AddErrorIsIncompleteNode(be);
                    }
                }
                be.SetLoc(ret.StartIndex, GetEnd());
                ret = be;
            }
        }