Beispiel #1
0
        /// <summary>
        /// Parses a literal value where a full expression is not allowed, such
        /// as in declarations within the header (before any functions). Logs
        /// an error and returns false if a literal value was not found.
        /// </summary>
        /// <param name="variable">Returns the resulting variable if method returns true.</param>
        /// <param name="allowLineBreak">If true, a new lines is allowed before literal.
        /// Set to true when parsing array initialization within curly braces.</param>
        internal bool ParseLiteral(out Variable variable, bool allowLineBreak = false)
        {
            variable = null;
            bool negate = false;

            Token token = allowLineBreak ? Lexer.GetNextSkipNewLines() : Lexer.GetNext();

            if (token.Type == TokenType.LeftBracket)
            {
                // List size
                if (!ParseLiteral(out variable))
                {
                    return(false);
                }
                variable = Variable.CreateList(variable.ToInteger());
                // Parse right bracket
                token = Lexer.GetNext();
                if (token.Type != TokenType.RightBracket)
                {
                    Error(ErrorCode.ExpectedRightBracket, token);
                    NextLine();
                    return(false);
                }
                return(true);
            }
            if (token.Type == TokenType.LeftBrace)
            {
                // List initializers
                List <Variable> list = new List <Variable>();
                do
                {
                    if (!ParseLiteral(out variable, true))
                    {
                        return(false);
                    }
                    list.Add(variable);
                    token = Lexer.GetNextSkipNewLines();
                } while (token.Type == TokenType.Comma);
                // Parse right brace
                if (token.Type != TokenType.RightBrace)
                {
                    Error(ErrorCode.ExpectedRightBrace, token);
                    NextLine();
                    return(false);
                }
                variable = new Variable(list);
                return(true);
            }
            if (token.Type == TokenType.Minus || token.Type == TokenType.Plus)
            {
                negate = (token.Type == TokenType.Minus);
                token  = Lexer.GetNext();
            }
            if (token.IsLiteral)
            {
                variable = new Variable(token);
                if (negate)
                {
                    variable = variable.Negate();
                }
                return(true);
            }
            Error(ErrorCode.ExpectedLiteral, token);
            return(false);
        }
Beispiel #2
0
 public bool IsGreaterThan(Variable value) => CompareTo(value) > 0;
Beispiel #3
0
 public bool IsGreaterThanOrEqual(Variable value) => CompareTo(value) >= 0;
Beispiel #4
0
 public bool IsEqual(Variable value) => CompareTo(value) == 0;
Beispiel #5
0
 public bool IsNotEqual(Variable value) => CompareTo(value) != 0;
Beispiel #6
0
 public abstract Variable Modulus(Variable value);
Beispiel #7
0
 public abstract Variable Concat(Variable value);
Beispiel #8
0
 public abstract Variable Divide(Variable value);
Beispiel #9
0
 public abstract Variable Power(Variable value);
Beispiel #10
0
 public abstract Variable Multiply(Variable value);
Beispiel #11
0
 public abstract Variable Subtract(Variable value);
Beispiel #12
0
 public abstract Variable Add(Variable value);
Beispiel #13
0
 public bool IsLessThanOrEqual(Variable value) => CompareTo(value) <= 0;
Beispiel #14
0
 public bool IsLessThan(Variable value) => CompareTo(value) < 0;