Exemple #1
0
        public Token GetDigit(ref Symbol currentSymbol, InputString inputString)
        {
            var line   = currentSymbol.Line;
            var col    = currentSymbol.Column;
            var lexeme = new StringBuilder();

            if (currentSymbol.Character.Equals('0'))
            {
                lexeme.Append(currentSymbol.Character);
                currentSymbol = inputString.GetNextSymbol();
                if (currentSymbol.Character.Equals('x') || currentSymbol.Character.Equals('X'))
                {
                    var t = GetHeximalNumber(ref currentSymbol, inputString, ref lexeme, col, line);
                    if (t != null)
                    {
                        return(t);
                    }
                }
                if (currentSymbol.Character.Equals(('B')) || currentSymbol.Character.Equals(('b')))
                {
                    var t = GetBinaryNumber(ref currentSymbol, inputString, ref lexeme, col, line);
                    if (t != null)
                    {
                        return(t);
                    }
                }
            }

            return(GetDecimalNumber(ref currentSymbol, inputString, ref lexeme, col, line));
        }
Exemple #2
0
        private void DrawInputHistory(Graphics gfx, byte[] inputHistory, AnchorPoint anchorPoint)
        {
            int yMultiplier = 0;

            for (int i = inputHistory.Length - 1; i >= 0; i--)
            {
                byte input = inputHistory.ElementAt(i);

                int         x           = 20;
                int         y           = (this.window.Height - 50) - (yMultiplier * 30) + 5;
                InputString inputString = InputToString(input);
                if (y > 15)
                {
                    if (anchorPoint == AnchorPoint.LEFT)
                    {
                        Point directionalStringSize = gfx.MeasureString(this.fonts["arial"], 30, inputString.DirectionalInput);
                        DrawShadedText(gfx, this.fonts["arial"], 30, this.brushes["magenta"], this.brushes["black"], 1, x + 2, y + 2, anchorPoint, inputString.DirectionalInput);
                        DrawShadedText(gfx, this.fonts["arial"], 20, this.brushes["magenta"], this.brushes["black"], 1, x + 2 + directionalStringSize.X, y + 13, anchorPoint, String.Join(' ', inputString.ButtonInputs));
                    }
                    else
                    {
                        string buttonsString     = String.Join(' ', inputString.ButtonInputs);
                        Point  buttonsStringSize = gfx.MeasureString(this.fonts["arial"], 20, buttonsString);
                        DrawShadedText(gfx, this.fonts["arial"], 30, this.brushes["magenta"], this.brushes["black"], 1, x + 2 + buttonsStringSize.X, y + 2, anchorPoint, inputString.DirectionalInput);
                        DrawShadedText(gfx, this.fonts["arial"], 20, this.brushes["magenta"], this.brushes["black"], 1, x + 2, y + 13, anchorPoint, buttonsString);
                    }
                }

                yMultiplier++;
            }
        }
Exemple #3
0
        public void TestCharacterOneOf()
        {
            InputString input = "Dog";

            Assert.AreEqual('D', Character.OneOf('A', 'B', 'C', 'D')(input).Value);
            Assert.AreEqual(false, Character.OneOf('E', 'F', 'G', 'H')(input).HasValue);
        }
Exemple #4
0
 void Update()
 {
     if (SceneManager.GetActiveScene().name == "TestScene")
     {
         Debug.Log(InputString.getValue());
     }
 }
Exemple #5
0
    public void CheckPhone()
    {
        bool        exist;
        InputString parameters = new InputString()
        {
            Value = phone
        };

        if (Regex.IsMatch(phone, Canvaser.Instance.RegistrationPanel.Region.PhonePattern))
        {
            CoroutineManager.SendRequest(CheckPhoneUrl, parameters,
                                         preSuccessMethod: (response) =>
            {
                exist = bool.Parse(response.Text);
                Debug.Log(exist);
                if (exist)
                {
                    CantContinue(PhoneAlreadyExists);
                }
                else
                {
                    NewUser.Email       = Email.text;
                    NewUser.PhoneNumber = phone;
                    NextPage();
                }
            });
        }
        else
        {
            CantContinue(InvalidFormatPhone);
        }
    }
        protected internal virtual void Initialize()
        {
            lock (_initLock)
            {
                if (!IsInitialized)
                {
                    OnInitializing();

                    if (HttpMethod.Equals("POST") && string.IsNullOrEmpty(Path.GetExtension(Request.Url.AbsolutePath)))
                    {
                        HttpArgs args = HttpArgs;
                        string   jsonParams;
                        if (args.Has("jsonParams", out jsonParams))
                        {
                            JsonParams = jsonParams;
                        }
                    }
                    else if (InputString.StartsWith("{")) // TODO: this should be reviewed for validity, check Content/Type
                    {
                        JsonParams = InputString;
                    }

                    ParseRequestUrl();
                    IsInitialized = true;

                    OnInitialized();
                }
            }
        }
        public void ValidLiteralIntDecimal()
        {
            var inputString = new InputString("7894561230");
            var literalIntTokenGenerator = new LiteralIntTokenGenerator();
            var currentSymbol            = inputString.GetNextSymbol();

            do
            {
                Assert.True(literalIntTokenGenerator.validStart(currentSymbol));
                currentSymbol = inputString.GetNextSymbol();
            }while(currentSymbol.character != '\0');

            inputString = new InputString("123 12 8 0");
            var expectedLexemes = new string[] { "123", "12", "8", "0" };
            var lexer           = new Compiler.Lexer(inputString, Resources.getTokenGenerators());
            var currentToken    = lexer.GetNextToken();
            int i = 0;

            do
            {
                Assert.True(currentToken.type == TokenType.LIT_INT);
                Assert.True(currentToken.lexeme == expectedLexemes[i++]);
                Console.WriteLine("lexeme: " + currentToken.lexeme + " | TokenType: " + TokenType.LIT_INT);
                currentToken = lexer.GetNextToken();
            }while(currentToken.type != TokenType.EOF);
        }
Exemple #8
0
        public Token GetToken(ref Symbol currentSymbol, InputString inputString)
        {
            var line   = currentSymbol.Line;
            var col    = currentSymbol.Column;
            var lexeme = new StringBuilder();

            lexeme.Append(currentSymbol.Character);
            currentSymbol = inputString.GetNextSymbol();
            if (currentSymbol.Character.IsLetterOrUnderscore())
            {
                while (currentSymbol.Character.IsLetterOrDigitOrUnderscore())
                {
                    lexeme.Append(currentSymbol.Character);
                    currentSymbol = inputString.GetNextSymbol();
                }
                return(new Token
                {
                    Type = TokenType.Id,
                    Lexeme = lexeme.ToString(),
                    Column = col,
                    Line = line
                });
            }
            if (currentSymbol.Character.IsDoubleQuotes())
            {
                return(GetVerbatinString(ref currentSymbol, inputString, ref lexeme, col, line));
            }
            throw new LexicalException("Cannot resolve symbol  " + lexeme.ToString() + "  Line: " + line + " Column: " + col);
        }
Exemple #9
0
        public void FloatLiteralMustFinishWithF()
        {
            var input = new InputString("1.5F 23.7F 5.0 5.0.0 \0");
            var lexer = new Lexer(input);

            var expectedTypes   = new TokenType[] { TokenType.LITERAL_FLOAT, TokenType.LITERAL_FLOAT };
            var expectedLexemas = new string[] { "1.5F", "23.7F" };

            var current = lexer.GetNextToken();
            var i       = 0;

            while (current.type != TokenType.EOF && i < expectedTypes.Length - 1)
            {
                Assert.Equal(expectedTypes[i], current.type);
                Assert.Equal(expectedLexemas[i++], current.lexema);
                current = lexer.GetNextToken();
            }

            // Exception ex = Assert.Throws<FloatLiteralException>(() => lexer.GetNextToken());

            // Assert.Equal("Float Literal must finish with F.", ex.Message);

            // ex = Assert.Throws<FloatLiteralException>(() => lexer.GetNextToken());

            // Assert.Equal("Float Literal must finish with F.", ex.Message);
        }
Exemple #10
0
        // 统计按钮监听事件
        private void Button1_Click_1(object sender, EventArgs e)
        {
            String       InputString; // 存储输入字符串
            int          count = 0;
            String       str1;
            StreamReader Str;

            if (checkBox1.Checked == true)
            {
                Str = new StreamReader(fName, Encoding.UTF8); // 创建一个StreamReader 的实例来读取文件
            }
            else
            {
                Str = new StreamReader(fName, Encoding.Default); // 创建一个StreamReader 的实例来读取文件
            }

            InputString = textBox2.Text; // 获取输入字符串

            str1 = Str.ReadToEnd();      // 读取文件中数据


            String[] sArray = InputString.Split(new string[] { "\r\n" }, StringSplitOptions.None);

            foreach (string i in sArray)
            {
                count = CalauteStringShowCount_For(str1, @i.ToString());                 // 计算字符串出现次数
                richTextBox1.AppendText(i.ToString() + ":" + count.ToString() + "\r\n"); // 显示数据
            }
        }
Exemple #11
0
 public Token GetVerbatinString(ref Symbol currentSymbol, InputString inputString, ref StringBuilder lexeme, int col, int line)
 {
     lexeme.Append(currentSymbol.Character);
     currentSymbol = inputString.GetNextSymbol();
     while (!currentSymbol.Character.IsDoubleQuotes() && !currentSymbol.Character.IsEof())
     {
         lexeme.Append(currentSymbol.Character);
         currentSymbol = inputString.GetNextSymbol();
     }
     if (currentSymbol.Character.IsDoubleQuotes())
     {
         lexeme.Append(currentSymbol.Character);
         currentSymbol = inputString.GetNextSymbol();
         if (currentSymbol.Character.IsDoubleQuotes())
         {
             return(GetVerbatinString(ref currentSymbol, inputString, ref lexeme, col, line));
         }
         return(new Token
         {
             Type = TokenType.LitString,
             Lexeme = lexeme.ToString(),
             Column = col,
             Line = line
         });
     }
     throw new LexicalException("Cannot resolve symbol  " + lexeme.ToString() + "  Line: " + line + " Column: " + col);
 }
Exemple #12
0
    public void MyFunction()
    {
        //Debug.LogError(InputString.getValue());
        textt  = InputString.getValue();
        strArr = textt.Split('.');

        //hasStarted = false;
        //oneTime = true;

        for (int i = 0; i < strArr.Length; i++)
        {
            isGood = false;
            for (int j = 0; j < termsManager.strings.Length; j++)
            {
                if (strArr[i].Contains(termsManager.strings[j]))
                {
                    //Debug.Log(textul.text);
                    textul += "<color=red>" + strArr[i] + "." + "</color>";
                    isGood  = true;
                }
            }
            if (isGood == false)
            {
                textul += strArr[i] + ".";
            }
        }

        InputString.setValue(textul);
        // Debug.LogError(InputString.getValue());
    }
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string temp = InputString.Replace("\\\"", "\\-/");

            temp         = temp.Replace("\\r", "").Replace("\\n", "").Replace("\r", "").Replace("\n", "\r\n").Replace("+", " ").Replace("\"", " ");
            OutputString = temp.Replace("\\-/", "\\\"");
        }
Exemple #14
0
        public override void Run()
        {
            var splitInput = InputString.Split("\n").ToList();

            int twos   = 0;
            int threes = 0;

            foreach (var word in splitInput)
            {
                var(twice, thrice) = FindTwosAndThrees(word);

                if (twice)
                {
                    twos++;
                }
                if (thrice)
                {
                    threes++;
                }
            }

            Console.WriteLine($"Checksum: {twos * threes}");

            for (var i = 0; i < splitInput.Count; ++i)
            {
                var word = splitInput[i];
                for (var j = i + 1; j < splitInput.Count; ++j)
                {
                    var secondWord = splitInput[j];

                    var mismatches    = 0;
                    var mismatchIndex = -1;
                    for (var c = 0; c < word.Length; ++c)
                    {
                        var wordChar       = word[c];
                        var secondWordChar = secondWord[c];

                        if (mismatches > 1)
                        {
                            break;
                        }

                        if (wordChar != secondWordChar)
                        {
                            mismatches++;
                            mismatchIndex = c;
                        }
                    }

                    if (mismatches == 1)
                    {
                        Console.WriteLine($"Remaining chars: {word.Substring(0, mismatchIndex)}{word.Substring(mismatchIndex + 1)}");
                        goto complete;
                    }
                }
            }

complete:
            Console.WriteLine();
        }
Exemple #15
0
        public void GreaterEqualThanOperator()
        {
            var input = new InputString(">=\0");
            var lexer = new Lexer(input);

            Assert.Equal(TokenType.OP_GREATER_EQUAL_THAN, lexer.GetNextToken().type);
        }
Exemple #16
0
        public void VariousClasss()
        {
            var input  = new InputString(@"
            namespace Hi{
                public class Hola{
                    void sayHello(){}
                    int sum(int a, int b);
                }

                public class Hola2{
                    void sayHello();
                    int sum(int a, int b);
                }
            }
            public class Hola{
                void sayHello();
                int sum(int a, int b);
            }

            public class Hola2{
                void sayHello();
                int sum(int a, int b);
            }
            ");
            var lexer  = new Lexer(input);
            var parser = new Parser(lexer);

            parser.parse();
        }
Exemple #17
0
        public void ShiftRightOperator()
        {
            var input = new InputString(">>\0");
            var lexer = new Lexer(input);

            Assert.Equal(TokenType.OP_BITS_SHIFT_RIGHT, lexer.GetNextToken().type);
        }
Exemple #18
0
        public char DigitFixup(int inputIndex, ref int newOffset)
        {
            char ch          = InputString[inputIndex];
            char replacement = char.MinValue;

            // Handle (One) = 1
            string restOfInput = InputString.Substring(inputIndex);
            string firstToken  = restOfInput.Split(' ').FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(firstToken))
            {
                string token = firstToken;
                if (DigitWordReplacementsTable.ContainsKey(token))
                {
                    replacement = DigitWordReplacementsTable[token];
                    newOffset   = inputIndex + token.Length;
                }
            }

            // Handle (A) = 8
            if (DigitReplacementsTable.ContainsKey(ch))
            {
                replacement = DigitReplacementsTable[ch];
            }

            Debug.WriteLine($"Digit {ch} was replaced by character {replacement}");
            return(replacement);
        }
        public void ValidIDReservedWord()
        {
            var inputString      = new InputString("abc");
            var idTokenGenerator = new IDReservedWordTokenGenerator();
            var currentSymbol    = inputString.GetNextSymbol();

            do
            {
                Assert.True(idTokenGenerator.validStart(currentSymbol));
                currentSymbol = inputString.GetNextSymbol();
            }while(currentSymbol.character != '\0');

            inputString = new InputString("hola Hola abd142_ hola_ adios_1542 true false");
            var expectedTypes   = new TokenType[] { TokenType.ID, TokenType.ID, TokenType.ID, TokenType.ID, TokenType.ID, TokenType.LIT_BOOL, TokenType.LIT_BOOL };
            var expectedLexemes = new string[] { "hola", "Hola", "abd142_", "hola_", "adios_1542", "true", "false" };
            var lexer           = new Compiler.Lexer(inputString, Resources.getTokenGenerators());
            var currentToken    = lexer.GetNextToken();
            int i = 0;

            do
            {
                Assert.True(currentToken.type == expectedTypes[i]);
                Assert.True(currentToken.lexeme == expectedLexemes[i]);
                Console.WriteLine("lexeme: " + currentToken.lexeme + " | TokenType: " + expectedTypes[i]);
                currentToken = lexer.GetNextToken();
                i++;
            }while(currentToken.type != TokenType.EOF);
        }
Exemple #20
0
        public char AlphabetFixup(int inputIndex, ref int offset)
        {
            char   ch          = InputString[inputIndex];
            string restOfInput = InputString.Substring(inputIndex);

            offset = 1;
            switch (DetectAlphabetFixup(InputString, inputIndex))
            {
            case FixupType.None:
                return(ch);

            case FixupType.AlphaMapping:
                char replacement = AlphabetReplacementsTable[ch];
                return(replacement);

            case FixupType.AsIn:
                AsInResult asInResult;
                asInResult = FindAsInFixup(restOfInput);
                if (asInResult.FixedUp)
                {
                    Debug.WriteLine($"'as in' fixed up {restOfInput} to letter {asInResult.Char}");
                    offset = asInResult.NewOffset;
                    return(asInResult.Char);
                }

                throw new Exception("Should have returned a char described by as in");
            }

            // TODO: Do additional fixups here
            return(ch);
        }
Exemple #21
0
        public void TestStringIs()
        {
            InputString text = "Dog";

            Assert.AreEqual(true, String.Is("Dog")(text).HasValue);
            Assert.AreEqual(false, String.Is("Cat")(text).HasValue);
        }
Exemple #22
0
        public void TestClassWithMaybeEmptyBlockInBody()
        {
            var txt         = @"
public class kevin : Nexer{
    public method(int a){
    }

    public method(int a) : base(a){
        {
            if(a==10){
                return a;
                {
                    for(;;){}
                }
            }
        }
    }
}
";
            var inputString = new InputString(txt);
            var lexer       = new Lexer(inputString);
            var parser      = new Parser(lexer);

            parser.parse();
        }
        protected override void Execute(CodeActivityContext context)
        {
            var inputString = InputString.Get(context);
            var delimiter   = Delimiter.Get(context);

            var strArray = inputString.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

            // Declare DataTable object.
            var dt = new System.Data.DataTable();

            // Add columns to the DataTable
            dt.Columns.Add("LINENUMBER", typeof(String));
            dt.Columns.Add("PARTNUMBER", typeof(String));
            dt.Columns.Add("DESCRIPTION", typeof(String));
            dt.Columns.Add("ORDERQTY", typeof(String));
            dt.Columns.Add("UNITPRICE", typeof(String));

            // Add strings from string array to datatable
            foreach (string str in strArray)
            {
                var drow = dt.NewRow();   // Here you will get an actual instance of a DataRow

                var strArrayTemp = str.Split(new string[] { delimiter }, StringSplitOptions.None);

                drow[0] = strArrayTemp[0];
                drow[1] = strArrayTemp[1];
                drow[2] = strArrayTemp[2];
                drow[3] = strArrayTemp[3];
                drow[4] = strArrayTemp[4];

                dt.Rows.Add(drow);             // Don't forget to add the row to the DataTable.
            }

            dtOutput.Set(context, dt);
        }
Exemple #24
0
        public void AssignationOperator()
        {
            var input = new InputString("=\0");
            var lexer = new Lexer(input);

            Assert.Equal(TokenType.OP_ASSIGN, lexer.GetNextToken().type);
        }
Exemple #25
0
        private void DoWorkAndReport(IProducerConsumerCollection <string> inputCollection, IProducerConsumerCollection <object[]> outputCollection, ManualResetEvent pauseEvent, IProgress <int> progress)
        {
            string[] _Delimiter = this._Delimiter;
            string   InputString;
            int      ProcessedCount = 0;

            while (HasWork)
            {
                pauseEvent.WaitOne();
                if (inputCollection.TryTake(out InputString))
                {
                    string[] OutputString = InputString.Split(_Delimiter, StringSplitOptions.None);
                    while (!outputCollection.TryAdd(OutputString))
                    {
                        pauseEvent.WaitOne();
                    }
                    ProcessedCount++;
                }
                if (ProcessedCount % 1000 == 0)
                {
                    progress.Report(ProcessedCount);
                }
            }
            progress.Report(ProcessedCount);
        }
Exemple #26
0
        public void ConditionalEqualOperator()
        {
            var input = new InputString("==\0");
            var lexer = new Lexer(input);

            Assert.Equal(TokenType.OP_CONDITIONAL_EQUAL, lexer.GetNextToken().type);
        }
Exemple #27
0
        public void TestCharacterIsNot()
        {
            InputString input = "Dog";

            Assert.AreEqual('D', Character.IsNot('C')(input).Value);
            Assert.AreEqual(false, Character.IsNot('D')(input).HasValue);
        }
Exemple #28
0
        public void LessEqualThanOperator()
        {
            var input = new InputString("<=\0");
            var lexer = new Lexer(input);

            Assert.Equal(TokenType.OP_LESS_EQUAL_THAN, lexer.GetNextToken().type);
        }
Exemple #29
0
        private void DoWorkAndReport(IProducerConsumerCollection <string> inputCollection, IProducerConsumerCollection <object[]> outputCollection, ManualResetEvent pauseEvent, IProgress <int> progress)
        {
            if (Delimiter == null)
            {
                var outputMessage = "Delimiter is not set for this Stringsplitter";
                LogService.Instance.Error(outputMessage);
                throw new InvalidOperationException(outputMessage);
            }
            string[] _Delimiter = new string[] { Delimiter };
            string   InputString;
            int      ProcessedCount = 0;

            if (Qualifier != null)
            {
                while (HasWork)
                {
                    pauseEvent.WaitOne();
                    if (inputCollection.TryTake(out InputString))
                    {
                        string[] OutputString = StringAndText.SplitRow(InputString, Delimiter, Qualifier, false);

                        while (!outputCollection.TryAdd(OutputString))
                        {
                            pauseEvent.WaitOne();
                        }
                        ProcessedCount++;
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }
                    if (ProcessedCount % 1000 == 0)
                    {
                        progress.Report(ProcessedCount);
                    }
                }
            }
            else
            {
                while (HasWork)
                {
                    pauseEvent.WaitOne();
                    if (inputCollection.TryTake(out InputString))
                    {
                        string[] OutputString = InputString.Split(_Delimiter, StringSplitOptions.None);

                        while (!outputCollection.TryAdd(OutputString))
                        {
                            pauseEvent.WaitOne();
                        }
                        ProcessedCount++;
                    }
                    if (ProcessedCount % 1000 == 0)
                    {
                        progress.Report(ProcessedCount);
                    }
                }
            }
            progress.Report(ProcessedCount);
        }
Exemple #30
0
        private Token GetFloatNumber(ref Symbol currentSymbol, InputString inputString, ref StringBuilder lexeme, int col, int line)
        {
            int result;

            if (currentSymbol.Character.Equals('.'))
            {
                lexeme.Append(currentSymbol.Character);
                currentSymbol = inputString.GetNextSymbol();
                while (currentSymbol.Character.IsDigit())
                {
                    lexeme.Append(currentSymbol.Character);
                    currentSymbol = inputString.GetNextSymbol();
                }
            }
            if (currentSymbol.Character.Equals('E') || currentSymbol.Character.Equals('e'))
            {
                return(GetExponent(ref currentSymbol, inputString, ref lexeme, col, line));
            }
            if ((currentSymbol.Character.Equals(('f')) || currentSymbol.Character.Equals(('F'))) && int.TryParse(lexeme[lexeme.Length - 1].ToString(), out result))
            {
                lexeme.Append(currentSymbol.Character);
                currentSymbol = inputString.GetNextSymbol();
                return(new Token
                {
                    Type = TokenType.LitFloat,
                    Lexeme = lexeme.ToString(),
                    Column = col,
                    Line = line
                });
            }
            throw new LexicalException("Invalid float syntax  " + lexeme.ToString() + "  Line: " + line +
                                       " Column: " + col);
        }