コード例 #1
0
 public override bool MoveNext()
 {
     if (first.MoveNext())
     {
         return(true);
     }
     else
     {
         return(second.MoveNext());
     }
 }
コード例 #2
0
        public override bool MoveNext()
        {
            // TODO: Look at this method in the PeekingIterator<E> class in the Java source. I really think these lines are a bug, unless there's some Java (f**k-me-magic) going on.
            //if (first.MoveNext())
            //    return true;
            //else if (second.MoveNext())
            //    return true;

            T obj1 = first.Peek();
            T obj2 = second.Peek();

            bool isFirstObjGreaterOrEqual = (comparer.Compare(obj1, obj2) >= 0);

            return(isFirstObjGreaterOrEqual ? first.MoveNext() : second.MoveNext());
        }
コード例 #3
0
        private bool CalculatePreProcessorCondition(Token token, IPeekingEnumerator <Token> enumerator,
                                                    ParserContext context, bool parseCondition)
        {
            if (!enumerator.MoveNext())
            {
                throw EndOfFile(token, context);
            }

            token = enumerator.Current;
            if (token.Type != TokenType.OpenParenthesis)
            {
                throw UnexpectedToken(token, context, true);
            }

            if (!enumerator.MoveNext()) //read the first eval token
            {
                throw EndOfFile(token, context);
            }

            token = enumerator.Current;

            var evalStatement = Parser.ReadEvaluationStatement(token, enumerator, context);

            if (!enumerator.MoveNext()) //read the close parenthesis
            {
                throw EndOfFile(token, context);
            }

            token = enumerator.Current;
            if (token.Type != TokenType.CloseParenthesis)
            {
                throw UnexpectedToken(token, context);
            }

            if (parseCondition)
            {
                try
                {
                    var stt = EvaluationStatementTranspilerBase.ProcessEvaluation(Context, Context.GeneralScope,
                                                                                  evalStatement);

                    if (stt is ConstantValueStatement constantValueStatement)
                    {
                        if (StatementHelpers.TryParseBooleanFromString(constantValueStatement.Value, out var boolVal))
                        {
                            return(boolVal);
                        }

                        throw UnexpectedToken(token, context);
                    }
                }
                catch (IdentifierNotFoundCompilerException)
                {
                    return(false);
                }

                throw UnexpectedToken(token, context);
            }

            return(false);
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: amkherad/ShellScript
        protected IStatement ReadStatement(IPeekingEnumerator <Token> enumerator, ParserContext context)
        {
            Token token;

            while (enumerator.MoveNext())
            {
                token = enumerator.Current;

                switch (token.Type)
                {
                case TokenType.Echo:
                    return(ReadEcho(token, enumerator, context));

                case TokenType.IdentifierName:
                    return(ReadIdentifierName(token, enumerator,
                                              context)); //ReadAssignmentOrFunctionCall(token, enumerator, context);

                case TokenType.DataType:
                    return(ReadVariableOrFunctionDefinition(token, enumerator, context));

                case TokenType.Delegate:
                    return(ReadDelegateDefinition(token, enumerator, context));

                case TokenType.If:
                    return(ReadIf(token, enumerator, context));

                case TokenType.For:
                    return(ReadFor(token, enumerator, context));

                case TokenType.ForEach:
                    return(ReadForEach(token, enumerator, context));

                case TokenType.While:
                    return(ReadWhile(token, enumerator, context));

                case TokenType.Do:
                    return(ReadDoWhile(token, enumerator, context));

                case TokenType.Loop:
                    return(ReadLoop(token, enumerator, context));

                //case TokenType.Class:
                //    return ReadClass(token, enumerator, info);
                //case TokenType.Function:
                //    return ReadFunction(token, enumerator, info);
                case TokenType.Return:
                    return(ReadReturn(token, enumerator, context));

                case TokenType.OpenBrace:
                    return(ReadBlockStatement(token, enumerator, context));

                case TokenType.Include:
                {
                    return(ReadIncludeStatement(token, enumerator, context));
                }

                case TokenType.OpenParenthesis:
                    break;
//                    case TokenType.Throw:
//                        break;
//                    case TokenType.Async:
//                        break;
//                    case TokenType.Await:
//                        break;
//                    case TokenType.Call:
//                        break;

                case TokenType.SequenceTerminator:
                case TokenType.SequenceTerminatorNewLine:
                    continue;

                case TokenType.Comment:
                case TokenType.MultiLineCommentOpen:
                case TokenType.MultiLineCommentClose:
                case TokenType.PreprocessorIf:
                case TokenType.PreprocessorElse:
                case TokenType.PreprocessorElseIf:
                case TokenType.PreprocessorEndIf:
                    throw UnexpectedSyntax(token, context);


                case TokenType.Minus:
                case TokenType.Plus:
                case TokenType.Else:
                case TokenType.AndLogical:
                case TokenType.And:
                case TokenType.OrLogical:
                case TokenType.Or:
                case TokenType.Equals:
                case TokenType.NotEquals:
                case TokenType.Asterisk:
                case TokenType.Assignment:
                case TokenType.CloseParenthesis:
                case TokenType.CloseBrace:
                case TokenType.OpenBracket:
                case TokenType.CloseBracket:
                case TokenType.Division:
                case TokenType.BackSlash:
                case TokenType.Dot:
                case TokenType.Case:
                case TokenType.Comma:
                case TokenType.In:
                case TokenType.NotIn:
                case TokenType.Like:
                case TokenType.NotLike:
                case TokenType.Number:
                case TokenType.StringValue1:
                case TokenType.StringValue2:
                    throw UnexpectedSyntax(token, context);

                case TokenType.NotDefined:
                    throw IllegalSyntax(token, context);

                case TokenType.Invalid:
                    throw IllegalSyntax(token, context);

                default:
                    throw UnexpectedSyntax(token, context);
                }
            }

            return(null);
        }