示例#1
0
        private static Expr ParseBinOpSeq(Parser parser, bool uniOpPrivilege = false)
        {
            var operands  = new List <Expr>();
            var operators = new List <Token>();

            while (true)
            {
                try
                {
                    operands.Add(ParseOperand(parser));
                    if (uniOpPrivilege)
                    {
                        break;
                    }
                    operators.Add(ParseOperator(parser));
                } catch (ParserError ex)
                {
                    if (!ex.IsExceptionFictive())
                    {
                        throw ex;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (operands.Count == 0)
            {
                throw new ParserError(
                          new FailedConsumer(), parser.Cursor
                          );
            }
            else if (operators.Count > operands.Count - 1)
            {
                throw new ParserError(
                          new UnexpectedTokenException(operators.Last().Type),
                          operators.Last().Pos
                          );
            }
            else if (operands.Count == 1)
            {
                return(operands[0]);
            }

            return(ShuntingYard.Go(operands, operators));
        }