Example #1
0
        /// <summary>
        /// Helper method for generating the string representation of a given VarName.
        /// </summary>
        /// <param name="name">The VarName for which to generate a string representation.</param>
        /// <returns>The string representation of the VarName.</returns>
        public static string GetString(VarName name)
        {
            switch (name)
            {
            case VarName.Tc:
            case VarName.FirstLocal:
            case VarName.SecondLocal:
                return(name.ToString());

            case VarName.StaticObjectField:
                return(GetString(VarType.TestClass) + "." +
                       nameof(TestClass.StaticObjectField));

            case VarName.StaticIntegerField:
                return(GetString(VarType.TestClass) + "." +
                       nameof(TestClass.StaticIntegerField));

            case VarName.InstanceObjectField:
                return(VarName.Tc.ToString() + "." +
                       nameof(TestClass.InstanceObjectField));

            default:
                throw new NotImplementedException("Unhandled VarName");
            }
        }
Example #2
0
 public override AstStatement Clone()
 => CopyValuesTo(new AstForStmt(
                     VarName?.Clone() as AstIdExpr,
                     IndexName?.Clone() as AstIdExpr,
                     Collection.Clone(),
                     Body.Clone(),
                     Arguments?.Select(a => a.Clone() as AstArgument)?.ToList(),
                     Label?.Clone() as AstIdExpr));
Example #3
0
        /// <summary>
        /// Method for generating a string representation of a call to a non-TestClass method.
        /// </summary>
        /// <param name="callingVar">The variable that calls this method.</param>
        /// <param name="methodName">The method name to be called.</param>
        /// <param name="args">The list of arguments of the method.</param>
        /// <returns>A string representation of the method call.</returns>
        public static string CallMethod(VarName callingVar,
                                        string methodName,
                                        string[] args = null)
        {
            var concatArgs = args == null ? string.Empty : string.Join(",", args);

            return(GetString(callingVar) + "." + methodName +
                   "(" + concatArgs + ");\n");
        }
 public override string ToString()
 {
     if (!string.IsNullOrEmpty(VarName))
     {
         return(VarName.ToString());
     }
     else
     {
         return(this.ID.ToString());
     }
 }
Example #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (VarName != null ? VarName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (VarTag != null ? VarTag.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (VarArrays != null ? VarArrays.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DefaultValue != null ? DefaultValue.GetHashCode() : 0);
         return(hashCode);
     }
 }
Example #6
0
        /// <summary>
        /// Parse all variables in template
        /// </summary>
        private void ParseVariables()
        {
            int idxCurrent = 0;

            while ((idxCurrent = this._ParsedBlock.IndexOf(this.VariableTagBegin, idxCurrent)) != -1)
            {
                string VarName, VarValue;
                int    idxVarTagEnd;

                idxVarTagEnd = this._ParsedBlock.IndexOf(this.VariableTagEnd, (idxCurrent + this.VariableTagBegin.Length));
                if (idxVarTagEnd == -1)
                {
                    throw new Exception(String.Format("Index {0}: could not find Variable End Tag", idxCurrent));
                }

                // Getting Variable Name

                VarName = this._ParsedBlock.Substring((idxCurrent + this.VariableTagBegin.Length), (idxVarTagEnd - idxCurrent - this.VariableTagBegin.Length));

                // Checking for Modificators

                string[] VarParts = VarName.Split(this.ModificatorTag.ToCharArray());
                VarName = VarParts[0];

                // Getting Variable Value
                // If Variable doesn't exist in _hstValue then
                // Variable Value equal empty string

                // [added 6/6/2006] If variable is null than it will also has empty string

                VarValue = String.Empty;
                if (this._hstValues.ContainsKey(VarName) && this._hstValues[VarName] != null)
                {
                    VarValue = this._hstValues[VarName].ToString();
                }

                // Apply All Modificators to Variable Value

                for (int i = 1; i < VarParts.Length; i++)
                {
                    this.ApplyModificator(ref VarValue, VarParts[i]);
                }

                // Replace Variable in Template

                this._ParsedBlock = this._ParsedBlock.Substring(0, idxCurrent) + VarValue + this._ParsedBlock.Substring(idxVarTagEnd + this.VariableTagEnd.Length);

                // Add Length of added value to Current index
                // to prevent looking for variables in the added value
                // Fixed Date: April 5, 2006
                idxCurrent += VarValue.Length;
            }
        }
Example #7
0
        private void UpdateVar()
        {
            if (IsVarable)
            {
                try
                {
                    var vars = TWS.Vars.Where(v => v.VarName.ToLower() == VarName.ToLower());

                    if (vars.Count() > 0)
                    {
                        vars.Single().Update(Value);
                    }
                    else
                    {
                        TWS.Vars.Add(new Param(VarName, Value));
                    }
                }
                catch { }
            }
        }
Example #8
0
        protected override CalResult SingOperate()
        {
            if (!IsSetValue)
            {
                if (CalCurrent.VarDataPool.ContainsKey(VarName))
                {
                    if (CalCurrent.CurrentIndex == -1)
                    {
                        return(CalCurrent.VarDataPool[VarName]);
                    }
                    else
                    {
                        var y = CalCurrent.VarDataPool[VarName];
                        if (y.Results != null)
                        {
                            return(new CalResult
                            {
                                Result = y.Results[CalCurrent.CurrentIndex],
                                ResultType = y.ResultType
                            });
                        }
                        else
                        {
                            return(y);
                        }
                    }
                }
                else
                {
                    throw new ExpressErrorException("变量" + VarName + "未赋值!");
                }
            }


            return(new CalResult
            {
                Result = VarName.ToString(),
                ResultType = typeof(string)
            });
        }
Example #9
0
    private void ReadFromPlayerPrefs()
    {
        VarName v       = 0;
        int     i       = 0;
        string  varName = VarName.Players.ToString();

        // check language and set default
        if (!PlayerPrefs.HasKey(VarName.Language.ToString()))
        {
            //if user runs the game for the first time
            if (Application.systemLanguage == SystemLanguage.English)
            {
                Config.SetVar(VarName.Language, 0);
            }
            else if (Application.systemLanguage == SystemLanguage.Russian)
            {
                Config.SetVar(VarName.Language, 1);
            }
        }
        //iterate through enum.
        //while enum has such name.
        //when getting out of enum`s range varName will become integer without name.
        while (varName != i.ToString())
        {
            int c;
            //check if there is such key, if not then player prefs does not exist. So leave default config values.
            if (PlayerPrefs.HasKey(varName))
            {
                c = PlayerPrefs.GetInt(varName);
                Config.SetVar(v, c);
                //print("Read " + c.ToString() + varName);
            }
            i++;
            v++;
            varName = ((VarName)i).ToString();
        }
    }
Example #10
0
 /// <summary>
 /// Generates a string representation of value assignment to a variable.
 /// </summary>
 /// <param name="name">The name of the variable to be assigned to.</param>
 /// <param name="value">The string representation of the value to be assigned.</param>
 /// <returns>String representation of the value assignment statement.</returns>
 public static string Assign(VarName name, string value) =>
 $"{GetString(name)} = {value};\n";
Example #11
0
 /// <summary>
 /// Generates a string representation for object dereference via GetHashCode.
 /// </summary>
 /// <param name="name">The variable name for the object being dereferenced.</param>
 /// <returns>The string representation of the variable dereference.</returns>
 public static string DerefObject(VarName name) =>
 name == VarName.None ? string.Empty : $"_ = {GetString(name)}.GetHashCode();\n";
Example #12
0
 /// <summary>
 /// Generates a string representation for variable declaration.
 /// </summary>
 /// <param name="type">The type of the variable being declared.</param>
 /// <param name="name">The name of the variable being declared.</param>
 /// <returns>The string representation of the variable declaration.</returns>
 public static string Declare(VarType type, VarName name) =>
 $"{GetString(type)} {GetString(name)};\n";
Example #13
0
 /// <summary>
 /// Returns a string representing the first array element for the input variable name. The
 /// variable must correspond to an array type.
 /// </summary>
 /// <param name="name">The variable name referencing the array.</param>
 /// <returns>The string representation for the first element of the array.</returns>
 public static string GetFirstArrayElement(VarName name) => GetString(name) + "[0]";
Example #14
0
    public static void SwitchVar(VarName name)
    {
        switch (name)
        {
        case VarName.Players:
            Players = Cycle(Players, MinPlayers, MaxPlayers);
            break;

        case VarName.Cards:
            if (Cards == MinCards)
            {
                Cards = MaxCards;
            }
            else
            {
                Cards = MinCards;
            }
            break;

        case VarName.Face:
            CardsFace++;
            if (CardsFace >= totalFaces)
            {
                CardsFace = 0;
            }

            break;

        case VarName.Background:

            CardsBackground++;
            if (CardsBackground >= totalBackgrounds)
            {
                CardsBackground = 0;
            }

            break;

        case VarName.Table:
            Table++;
            if (Table >= totalTables)
            {
                Table = 0;
            }
            break;

        case VarName.Language:
            Language++;
            if (Language >= totalLanguages)
            {
                Language = 0;
            }

            break;

        case VarName.AutoBet:
            AutoBet = !AutoBet;
            break;

        case VarName.TwoBeatsAce:
            TwoBeatsAce = !TwoBeatsAce;
            break;

        case VarName.UntilOneEliminated:
            UntilOneEliminated = !UntilOneEliminated;
            break;

        case VarName.Giveaway:
            Giveaway = !Giveaway;
            break;

        default:
            break;
        }
    }
Example #15
0
    public static void SetVar(VarName name, int val)
    {
        switch (name)
        {
        case VarName.Players:
            if (val >= MinPlayers && val <= MaxPlayers)
            {
                Players = val;
            }
            break;

        case VarName.Cards:
            if (val >= MinCards && val <= MaxCards)
            {
                Cards = val;
            }
            break;

        case VarName.AutoBet:
            if (val > 0)
            {
                AutoBet = true;
            }
            else
            {
                AutoBet = false;
            }
            break;

        case VarName.TwoBeatsAce:
            if (val > 0)
            {
                TwoBeatsAce = true;
            }
            else
            {
                TwoBeatsAce = false;
            }
            break;

        case VarName.UntilOneEliminated:
            if (val > 0)
            {
                UntilOneEliminated = true;
            }
            else
            {
                UntilOneEliminated = false;
            }
            break;

        case VarName.Giveaway:
            if (val > 0)
            {
                Giveaway = true;
            }
            else
            {
                Giveaway = false;
            }
            break;

        case VarName.Face:
            if (val < totalFaces && val >= 0)
            {
                CardsFace = val;
            }
            break;

        case VarName.Background:
            if (val < totalBackgrounds && val >= 0)
            {
                CardsBackground = val;
            }
            break;

        case VarName.Table:
            if (val < totalTables && val >= 0)
            {
                Table = val;
            }
            break;

        case VarName.Language:
            if (val < totalLanguages && val >= 0)
            {
                Language = val;
            }
            break;
        }
    }
Example #16
0
        /// <summary>
        /// Find next Token in Program
        /// </summary>
        /// <returns>Found Token Type</returns>
        private Token FindNextToken(ref ArrayList ProgramToTokenize)
        {
            /* Workings of method
             * 1. Search for End of Program
             * 2. Search for Numbers
             * 3. Search for Special characters
             * 4. Search for Quoted Strings
             * 5. Search for Keywords
             * 6. Search for Known variables
             * 7. Search for New variables
             */

            ///////////////////////////////////////////////////////////////////////////
            //
            //                      Search for End of Program
            //
            ///////////////////////////////////////////////////////////////////////////


            // Check for End of program
            if ((SourceCode[SourceCodePosition] == (char)0) || (SourceCodePosition > SourceCode.Length))
            {
                return(new EndOfInputToken(this, ""));
            }


            ///////////////////////////////////////////////////////////////////////////
            //
            //                      Search for Numbers
            //
            ///////////////////////////////////////////////////////////////////////////

            // Token is a Number
            if (CHECK_FOR_NUMBER.IndexOf(SourceCode[SourceCodePosition]) != -1)
            {
                // Retrieve number
                for (int i = 0; i < (MAX_NUM_LENGTH + 1); ++i)
                {
                    // Check if next char is numeric
                    if (CHECK_FOR_NUMBER.IndexOf(SourceCode[SourceCodePosition + i]) == -1)
                    {
                        // Check number length
                        if (i > 0)
                        {
                            // Incease Program Search Position
                            SourceCodeNextPosition = SourceCodePosition + i;

                            // If we expect a Line number return LineNumberToken else return NumberToken
                            if (ExpectLineNumber)
                            {
                                ExpectLineNumber = false;
                                return(new LineNumberToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                            }
                            else
                            {
                                ExpectLineNumber = false;
                                return(new NumericToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                            }
                        }
                        else
                        {
                            throw new BasicParserException(BasicParserException.UNKNOWN_ERROR);
                        }
                    }
                }
                throw new BasicParserException(BasicParserException.NUMBER_TO_LONG);
            }

            // Reset ExectLineNumber
            ExpectLineNumber = false;



            ///////////////////////////////////////////////////////////////////////////
            //
            //                      Search for Special characters
            //
            ///////////////////////////////////////////////////////////////////////////



            // Check for Single character tokens
            switch (SourceCode[SourceCodePosition])
            {
            // NewLine Character
            case '\n':

                // Increase Program Search Position
                SourceCodeNextPosition = SourceCodePosition + 1;

                // After new line expect line number
                ExpectLineNumber = true;

                // A Single Text Token on a Line is a LabelToken
                if (ProgramToTokenize.Count >= 2)
                {
                    if (ProgramToTokenize[ProgramToTokenize.Count - 1].GetType().Equals(typeof(TextToken)) && ProgramToTokenize[ProgramToTokenize.Count - 2].GetType().Equals(typeof(EndOfLineToken)))
                    {
                        ProgramToTokenize[ProgramToTokenize.Count - 1] = new LabelToken(this, ((TextToken)ProgramToTokenize[ProgramToTokenize.Count - 1]).Content);
                    }
                }
                else if (ProgramToTokenize.Count == 1)
                {
                    if (ProgramToTokenize[ProgramToTokenize.Count - 1].GetType().Equals(typeof(TextToken)))
                    {
                        ProgramToTokenize[ProgramToTokenize.Count - 1] = new LabelToken(this, ((TextToken)ProgramToTokenize[ProgramToTokenize.Count - 1]).Content);
                    }
                }

                // Return EndOfLine Token
                return(new EndOfLineToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // NewLine within CodeLine
            case ':':

                // Increase Program Search Position
                SourceCodeNextPosition = SourceCodePosition + 1;

                // After new line expect line number
                ExpectLineNumber = true;

                // A Single Text Token on a Line is a LabelToken
                if (ProgramToTokenize.Count >= 2)
                {
                    if (ProgramToTokenize[ProgramToTokenize.Count - 1].GetType().Equals(typeof(TextToken)) && ProgramToTokenize[ProgramToTokenize.Count - 2].GetType().Equals(typeof(EndOfLineToken)))
                    {
                        ProgramToTokenize[ProgramToTokenize.Count - 1] = new LabelToken(this, ((TextToken)ProgramToTokenize[ProgramToTokenize.Count - 1]).Content);
                    }
                }
                else if (ProgramToTokenize.Count == 1)
                {
                    if (ProgramToTokenize[ProgramToTokenize.Count - 1].GetType().Equals(typeof(TextToken)))
                    {
                        ProgramToTokenize[ProgramToTokenize.Count - 1] = new LabelToken(this, ((TextToken)ProgramToTokenize[ProgramToTokenize.Count - 1]).Content);
                    }
                }

                // Return EndOfLine Token
                return(new EndOfLineToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));


            // Comma
            case ',':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new CommaToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Semicolon
            case ';':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new SemicolonToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Plus
            case '+':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new PlusToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Minus
            case '-':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new MinusToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Logical And
            case '&':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new AndToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Logical Or
            case '|':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new OrToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Multiply
            case '*':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new MultiplyToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Divide
            case '/':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new DivideToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Modulus
            case '%':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new ModulusToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Left Parenthis
            case '(':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new LeftParenToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Right Parenthis
            case ')':
                SourceCodeNextPosition = SourceCodePosition + 1;
                return(new RightParenToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Less Than
            case '<':
                SourceCodeNextPosition = SourceCodePosition + 1;


                if (SourceCodeNextPosition < SourceCode.Length)
                {
                    // <> becomes NotEqual
                    if (SourceCode[SourceCodeNextPosition] == '>')
                    {
                        SourceCodeNextPosition = SourceCodeNextPosition + 1;
                        return(new NotEqualToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                    }

                    // <= becomes LessOrEqual
                    if (SourceCode[SourceCodeNextPosition] == '=')
                    {
                        SourceCodeNextPosition = SourceCodeNextPosition + 1;
                        return(new LessOrEqualToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                    }
                }

                // Return Less Than
                return(new LessThenToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // In combination with = becomes NotEqual Token
            case '!':
                SourceCodeNextPosition = SourceCodePosition + 1;
                if (SourceCodeNextPosition < SourceCode.Length)
                {
                    // Check if next Token is EqualToken
                    if (SourceCode[SourceCodeNextPosition] == '=')
                    {
                        SourceCodeNextPosition = SourceCodeNextPosition + 1;
                        return(new NotEqualToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                    }
                }

                // If not != then ignore
                break;

            // Greater Than
            case '>':
                SourceCodeNextPosition = SourceCodePosition + 1;

                if (SourceCodeNextPosition < SourceCode.Length)
                {
                    // >= becomes MoreOrEqual
                    if (SourceCode[SourceCodeNextPosition] == '=')
                    {
                        SourceCodeNextPosition = SourceCodeNextPosition + 1;
                        return(new MoreOrEqualToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                    }
                }

                // return GreaterThen
                return(new GreaterThenToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // Equals
            case '=':
                SourceCodeNextPosition = SourceCodePosition + 1;

                // If previous token is an Text token make it a variables
                // (Equal becomes assignment character)
                if (ProgramToTokenize[ProgramToTokenize.Count - 1].GetType().Equals(typeof(TextToken)))
                {
                    String VariableName = ((TextToken)ProgramToTokenize[ProgramToTokenize.Count - 1]).Content;
                    VariableNames.Add(VariableName);

                    // If $ then it is an String variable else Numeric
                    if (VariableName[VariableName.Length - 1] == '$')
                    {
                        ProgramToTokenize[ProgramToTokenize.Count - 1] = new StringVariableToken(this, VariableName);
                    }
                    else
                    {
                        ProgramToTokenize[ProgramToTokenize.Count - 1] = new NumericVariableToken(this, VariableName);
                    }
                }

                // Return Equals
                return(new EqualToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));

            // REM
            case '\'':
                SourceCodeNextPosition = SourceCodePosition + 1;

                // Skip source until EndOfLine or EndOfProgram
                while (SourceCodeNextPosition < SourceCode.Length)
                {
                    if (SourceCode[SourceCodeNextPosition] == '\n')
                    {
                        break;
                    }
                    SourceCodeNextPosition++;
                }
                return(new RemToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
            }

            ///////////////////////////////////////////////////////////////////////////
            //
            //                      Search for Quoted Strings
            //
            ///////////////////////////////////////////////////////////////////////////


            // Check for quote
            if (SourceCode[SourceCodePosition] == '\"')
            {
                SourceCodeNextPosition = SourceCodePosition;

                // Use extra string to check for backslashes
                String QuotedString    = "";
                bool   IgnoreNextQuote = false;

                // Search for end of string
                do
                {
                    // Check for backslash, Don't ignore a second backslash
                    if ((!IgnoreNextQuote) && (SourceCode[SourceCodeNextPosition] == '\\'))
                    {
                        // Backslash found, ignore next quote as string end
                        // Don't add to string
                        IgnoreNextQuote = true;
                    }
                    else
                    {
                        // Add to string
                        QuotedString += SourceCode[SourceCodeNextPosition];

                        // Reset quote search
                        IgnoreNextQuote = false;
                    }

                    SourceCodeNextPosition++;
                } while ((IgnoreNextQuote) || (SourceCode[SourceCodeNextPosition] != '\"'));

                SourceCodeNextPosition++;

                // Return String
                return(new StringToken(this, QuotedString + "\""));
            }


            ///////////////////////////////////////////////////////////////////////////
            //
            //                      Search for Keywords
            //
            ///////////////////////////////////////////////////////////////////////////


            // Check for keywords
            foreach (KeywordTokenConstructor kt in KeywordTokens)
            {
                // Check if keyword is not longer then remaining program code
                if (kt.Keyword.Length <= (SourceCode.Length - SourceCodePosition))
                {
                    // Check for token
                    if (SourceCodeLower.Substring(SourceCodePosition, kt.Keyword.Length) == kt.Keyword)
                    {
                        // Check if it's the whole keyword that we've found
                        if ((SourceCode.Length - SourceCodePosition - kt.Keyword.Length) != 0)
                        {
                            if (CHECK_END_OF_TOKEN.IndexOf(SourceCode[SourceCodePosition + kt.Keyword.Length]) == -1)
                            {
                                continue;
                            }
                        }

                        // Return keyword if found
                        SourceCodeNextPosition = SourceCodePosition + kt.Keyword.Length;

                        if (kt.Keyword == "rem")
                        {
                            SourceCodeNextPosition = SourceCodePosition + 1;
                            while (SourceCodeNextPosition < SourceCode.Length)
                            {
                                if (SourceCode[SourceCodeNextPosition] == '\n')
                                {
                                    break;
                                }
                                SourceCodeNextPosition++;
                            }
                        }

                        return(kt.TokenConstructor(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                    }
                }
            }

            ///////////////////////////////////////////////////////////////////////////
            //
            //                      Search for Known variables
            //
            ///////////////////////////////////////////////////////////////////////////


            // Check for variables
            foreach (String VarName in VariableNames)
            {
                // Check if variable name is not longer then remaining program code
                if (VarName.Length <= (SourceCode.Length - SourceCodePosition))
                {
                    // Check for token
                    if (SourceCodeLower.Substring(SourceCodePosition, VarName.Length) == VarName.ToLower())
                    {
                        // Check if it's the whole keyword that we've found
                        if ((SourceCode.Length - SourceCodePosition - VarName.Length) != 0)
                        {
                            if (CHECK_END_OF_VARIABLE_NAME.IndexOf(SourceCode[SourceCodePosition + VarName.Length]) == -1)
                            {
                                continue;
                            }
                        }

                        // Return keyword if found
                        SourceCodeNextPosition = SourceCodePosition + VarName.Length;

                        if (VarName[VarName.Length - 1] == '$')
                        {
                            return(new StringVariableToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                        }
                        else
                        {
                            return(new NumericVariableToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                        }
                    }
                }
            }

            ///////////////////////////////////////////////////////////////////////////
            //
            //                      Search for New variables
            //
            ///////////////////////////////////////////////////////////////////////////


            // Search for new Variable Names, If preceeded by LET or FOR then make it a new variable
            for (int i = 0; i < (MAX_VARIABLENAME_LENGTH + 1); ++i)
            {
                // Search for End of TextToken
                if ((CHECK_END_OF_VARIABLE_NAME.IndexOf(SourceCode[SourceCodePosition + i])) != -1)
                {
                    if (i > 0)
                    {
                        SourceCodeNextPosition = SourceCodePosition + i;
                        String TxtPart = SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition);
                        if (ProgramToTokenize.Count > 0)
                        {
                            if (ProgramToTokenize[ProgramToTokenize.Count - 1].GetType().Equals(typeof(ForToken)))
                            {
                                String VariableName = SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition);
                                VariableNames.Add(VariableName);

                                if (VariableName[VariableName.Length - 1] == '$')
                                {
                                    return(new StringVariableToken(this, VariableName));
                                }
                                else
                                {
                                    return(new NumericVariableToken(this, VariableName));
                                }
                            }

                            if (ProgramToTokenize[ProgramToTokenize.Count - 1].GetType().Equals(typeof(LetToken)))
                            {
                                String VariableName = SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition);
                                VariableNames.Add(VariableName);

                                if (VariableName[VariableName.Length - 1] == '$')
                                {
                                    return(new StringVariableToken(this, VariableName));
                                }
                                else
                                {
                                    return(new NumericVariableToken(this, VariableName));
                                }
                            }
                        }

                        // No FOR or LET make it a TextToken
                        return(new TextToken(this, SourceCode.Substring(SourceCodePosition, SourceCodeNextPosition - SourceCodePosition)));
                    }
                    else
                    {
                        throw new BasicParserException(BasicParserException.VARIABLENAME_UNEXPECTED_END);
                    }
                }
            }


            // Failed to find next token
            throw new BasicParserException(BasicParserException.UNKNOWN_ERROR);
        }
Example #17
0
        public override string ToString()
        {
            var nl = Environment.NewLine;

            return($"catch ({(Type != null ? Type.ToString() : "")} {(VarName != null ? VarName.ToString() : "")}) {{{nl}    {Body}{nl}}}{nl}");
        }
Example #18
0
 /// <summary>
 /// Method for generating a string representation of a returned variable.
 /// </summary>
 /// <param name="returnedVar">The variable that is returned in this statement.</param>
 /// <returns>A string representation of the return statement.</returns>
 public static string ReturnVar(VarName returnedVar)
 {
     return("return " + GetString(returnedVar) + ";\n");
 }
 public StepBuilder Done()
 {
     VarName.NotNull("name").NotEmptyString("name");
     _parent.AddReplaceVarMap(this);
     return(_parent);
 }
Example #20
0
 public override int GetHashCode()
 {
     return(VarName.GetHashCode() ^ VarValue.GetHashCode());
 }
Example #21
0
 public override string ToString()
 {
     return($"catch ({Type.ToStringWithTrailSpace()}{(VarName.ToStringNullable())})\n{{{Body}}}");
 }