Exemple #1
0
        public bool LoadSource(string sourceCode)
        {
            bool succ = true;

            source = sourceCode;
            reader = new Reader(source);
            Token t = Scan();

            do
            {
                if (!ExistInTokens((int)t.TokenTag))
                {
                    Console.WriteLine("Ln " + currentLine + ", Cannot read: " + reader.CurrentChar);
                    succ = false;
                }
                tokens.Add(t);
                t = Scan();
            } while (t.TokenTag != Tag.PROGRAM_END);
            tokens.Add(new Token(Tag.PROGRAM_END, currentLine + 1, reader.CurrentPosition));
            return(succ);
        }
Exemple #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var table = new TokenTable();
            var json  = JObject.Load(reader);

            foreach (JToken jsonColumn in json.SelectToken("columns"))
            {
                var column = new Dictionary <char, Tuple <char, int> >();
                foreach (JToken jsonRow in jsonColumn.SelectToken("rows"))
                {
                    column.Add(Convert.ToChar((int)jsonRow.SelectToken("f")), new Tuple <char, int>(Convert.ToChar((int)jsonRow.SelectToken("t")), (int)jsonRow.SelectToken("n")));
                }
                table.Add(column);
            }

            return(table);
        }
Exemple #3
0
        public void GenerateRandomColumn(int size, List <char> characters, TokenTable forwardTable, TokenTable reverseTable)
        {
            var forwardColumn = new Dictionary <char, Tuple <char, int> >();
            var reverseColumn = new Dictionary <char, Tuple <char, int> >();

            var replacements = characters.ToList();

            replacements.Shuffle();
            for (var i = 0; i < characters.Count; i++)
            {
                var columnReference = ThreadSafeRandom.ThisThreadsRandom.Next(0, size - 1);
                forwardColumn.Add(characters[i], new Tuple <char, int>(replacements[i], columnReference));
                reverseColumn.Add(replacements[i], new Tuple <char, int>(characters[i], columnReference));
            }

            forwardTable.Add(forwardColumn);
            reverseTable.Add(reverseColumn);
        }