Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public ConcatPeekingIterator(IPeekingEnumerator <T> first, IPeekingEnumerator <T> second)
 {
     this.first  = first;
     this.second = second;
 }
Ejemplo n.º 3
0
 static IPeekingEnumerator <T> Comparing(IPeekingEnumerator <T> first, IPeekingEnumerator <T> second, IComparer <T> comparer)
 {
     return(new ComparingPeekingIterator <T>(first, second, comparer));
 }
Ejemplo n.º 4
0
 static IPeekingEnumerator <T> Concat(IPeekingEnumerator <T> first, IPeekingEnumerator <T> second)
 {
     return(new ConcatPeekingIterator <T>(first, second));
 }
Ejemplo n.º 5
0
 public ComparingPeekingIterator(IPeekingEnumerator <T> first, IPeekingEnumerator <T> second, IComparer <T> comparer)
 {
     this.first    = first;
     this.second   = second;
     this.comparer = comparer;
 }
Ejemplo n.º 6
0
        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);
        }