コード例 #1
0
 public tokenObject(tokenType type, string content, int column, int row)
 {
     _type    = type;
     _content = new tokenContent();
     _content.setValue(content);
     _coordinates = new tokenCoordinates(column, row);
 }
コード例 #2
0
 public Token(string name = "", tokenType type = tokenType.Error, int line = 0, string text = "")
 {
     this.token_Name = name;
     this.token_Type = type;
     this.lineNumber = line;
     this.Text       = text;
 }
コード例 #3
0
 public tokenObject(tokenType type, string content, tokenCoordinates coordinates)
 {
     _type    = type;
     _content = new tokenContent();
     _content.setValue(content);
     _coordinates = coordinates;
 }
コード例 #4
0
 public lexicalToken(tokenType type, string value, int lineNumber)
 {
     this.type = type;
     if (type == tokenType.identifer && value == "#define")
     {
         this.type = tokenType.define;
     }
     else if (type == tokenType.identifer && value == "enum")
     {
         this.type = tokenType.tenum;
     }
     if (type == tokenType.symbol && value == "(")
     {
         this.type = tokenType.parenthesis_open;
     }
     else if (type == tokenType.symbol && value == ")")
     {
         this.type = tokenType.parenthesis_close;
     }
     else if (type == tokenType.symbol && value == "{")
     {
         this.type = tokenType.brace_open;
     }
     else if (type == tokenType.symbol && value == "}")
     {
         this.type = tokenType.brace_close;
     }
     else if (type == tokenType.symbol && value == ";")
     {
         this.type = tokenType.semicolon;
     }
     this.value = value;
     this.line  = lineNumber;
 }
コード例 #5
0
 public tokenAccess(HttpRequest request, tokenType type, string token = null, int delay = 0)
 {
     this.type  = type;
     this.ip    = request.getIPAddress();
     this.delay = delay;
     this.token = token;
     this.last  = DateTime.Now;
 }
コード例 #6
0
        public tokenType identifyString(string input)
        {
            tokenType result = tokenType.ID;

            if (_reservedWords.ContainsKey(input))
            {
                result = _reservedWords[input];
            }
            return(result);
        }
コード例 #7
0
 public static bool IsAnyOfTheseTypes(this tokenType ct, params tokenType[] types)
 {
     foreach (var type in types)
     {
         if (type == (ct & type))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #8
0
ファイル: Parser.cs プロジェクト: MohamedHosnie/TINY-Compiler
 private bool match(tokenType expected)
 {
     if (expected == current_token.token_Type)
     {
         current_token = getNextToken();
         return(true);
     }
     else
     {
         error("Expected: " + expected.ToString() + ", found: " + current_token.token_Name.ToString());
         return(false);
     }
 }
コード例 #9
0
 public static void createToken(HttpRequest request, tokenType type, string token = null, int delay = 0)
 {
     if (request == null)
     {
         return;
     }
     try
     {
         var index = accesses.FindIndex(a => a.ip == request.getIPAddress() && a.type == type);
         if (index != -1)
         {
             accesses[index] = new tokenAccess(request, type, token, delay);
         }
         else
         {
             accesses.Add(new tokenAccess(request, type, token, delay));
         }
     }
     catch
     {
     }
 }
コード例 #10
0
            public static bool validateToken(HttpRequest request, tokenType type, string token = null)
            {
                tokenAccess tkn = null;

                if (token != null)
                {
                    tkn = accesses.Find(a => a.ip == request.getIPAddress() && a.type == type && a.token == token);
                }
                else
                {
                    tkn = accesses.Find(a => a.ip == request.getIPAddress() && a.type == type);
                }
                if (tkn != null)
                {
                    if (tkn.delay > 0 && (int)(DateTime.Now - tkn.last).TotalSeconds < tkn.delay)
                    {
                        return(false);
                    }

                    accesses.Remove(tkn);
                    return(true);
                }
                return(false);
            }
コード例 #11
0
 public ParsedOperator(string Data, tokenType TokenType, operatorType OperatorType)
     : base(Data, TokenType)
 {
     this.OperatorType = OperatorType;
 }
コード例 #12
0
        public void Scan()
        {
            buffer = buffer.Replace("\r\n", "\n") + " ";
            byte   state         = (byte)State.START;
            string current_token = "";
            int    line_num      = 1;

            for (int i = 0; i < buffer.Length; i++)
            {
                byte input = checkType(buffer[i]);
                state = (byte)transition_table[state, input];

                if (accept[(byte)state]) //Accept
                {
                    object    newToken;
                    tokenType current_category = tokenType.None;
                    if (!backState(state))
                    {
                        current_token += buffer[i];
                    }
                    else
                    {
                        i--;
                    }

                    current_category = getCategory(state, current_token);

                    /// Add each Token to it's specified list
                    if (current_category == tokenType.Comment)
                    {
                        newToken = new Token("", tokenType.Comment, line_num, current_token);
                        comments.Add((Token)newToken);
                    }
                    else if (current_category == tokenType.Error)
                    {
                        newToken = new Token("", tokenType.Error, line_num, current_token);
                        errors.Add((Token)newToken);
                        tokens.Add((Token)newToken);
                    }
                    else if (current_category == tokenType.ID)
                    {
                        newToken = new Token(current_token, current_category);
                        if (!symbolTable.ContainsKey(((Token)newToken).token_Name))
                        {
                            symbolTable.Add(((Token)newToken).token_Name, 0);
                        }
                        tokens.Add((Token)newToken);
                    }
                    else
                    {
                        if (current_category != tokenType.Num)
                        {
                            current_token = "";
                        }
                        newToken = new Token(current_token, current_category);
                        tokens.Add((Token)newToken);
                    }

                    /// start over
                    current_token = "";
                    state         = (byte)State.START;
                }    //End if Accept
                else //Not Accept
                {
                    if (state == (byte)State.INCOMMENT)
                    {
                        current_token += buffer[i];
                    }
                    else
                    {
                        if (!delimeters.ContainsValue(buffer[i]))
                        {
                            current_token += buffer[i];
                        }
                    }
                }


                if (buffer[i] == '\n')
                {
                    line_num++;
                }
            } //End for loop

            return;
        } //End function start
コード例 #13
0
            dtok.dtt = DTT.Unk;     // Assume the token is unkown.

            str.GetRegularToken(out tokenType, out tokenValue, dtfi);
コード例 #14
0
ファイル: Scanner.cs プロジェクト: Ruzzie/Textorizer
 return(new Token(tokenType,
                  state.SourceData[state.StartIndex..state.CurrentPos],
コード例 #15
0
ファイル: DiscordClient.cs プロジェクト: Miimik/test
 : this(new RestDiscordClient(tokenType, token, configuration ??= new DiscordClientConfiguration()), configuration)
コード例 #16
0
ファイル: Text.cs プロジェクト: Gnusznak/CrystalsOfTime
 private static void parseTokenMethod(string code, tokenType tt)
 {
     int icode = Convert.ToInt16(code);
     if (tt == tokenType.FCOLOR)
     {
         switch (icode)
         {
             case 0:
                 {
                     Console.ForegroundColor = ConsoleColor.Black;
                     break;
                 }
             case 1:
                 {
                     Console.ForegroundColor = ConsoleColor.Blue;
                     break;
                 }
             case 2:
                 {
                     Console.ForegroundColor = ConsoleColor.Cyan;
                     break;
                 }
             case 3:
                 {
                     Console.ForegroundColor = ConsoleColor.DarkBlue;
                     break;
                 }
             case 4:
                 {
                     Console.ForegroundColor = ConsoleColor.DarkCyan;
                     break;
                 }
             case 5:
                 {
                     Console.ForegroundColor = ConsoleColor.DarkGray;
                     break;
                 }
             case 6:
                 {
                     Console.ForegroundColor = ConsoleColor.DarkGreen;
                     break;
                 }
             case 7:
                 {
                     Console.ForegroundColor = ConsoleColor.DarkMagenta;
                     break;
                 }
             case 8:
                 {
                     Console.ForegroundColor = ConsoleColor.DarkRed;
                     break;
                 }
             case 9:
                 {
                     Console.ForegroundColor = ConsoleColor.DarkYellow;
                     break;
                 }
             case 10:
                 {
                     Console.ForegroundColor = ConsoleColor.Gray;
                     break;
                 }
             case 11:
                 {
                     Console.ForegroundColor = ConsoleColor.Green;
                     break;
                 }
             case 12:
                 {
                     Console.ForegroundColor = ConsoleColor.Magenta;
                     break;
                 }
             case 13:
                 {
                     Console.ForegroundColor = ConsoleColor.Red;
                     break;
                 }
             case 14:
                 {
                     Console.ForegroundColor = ConsoleColor.White;
                     break;
                 }
             case 15:
                 {
                     Console.ForegroundColor = ConsoleColor.Yellow;
                     break;
                 }
             default:
                 {
                     Console.ForegroundColor = ConsoleColor.White;
                     break;
                 }
         }
     }
     if (tt == tokenType.BGCOLOR)
     {
         switch (icode)
         {
             case 0:
                 {
                     Console.BackgroundColor = ConsoleColor.Black;
                     break;
                 }
             case 1:
                 {
                     Console.BackgroundColor = ConsoleColor.Blue;
                     break;
                 }
             case 2:
                 {
                     Console.BackgroundColor = ConsoleColor.Cyan;
                     break;
                 }
             case 3:
                 {
                     Console.BackgroundColor = ConsoleColor.DarkBlue;
                     break;
                 }
             case 4:
                 {
                     Console.BackgroundColor = ConsoleColor.DarkCyan;
                     break;
                 }
             case 5:
                 {
                     Console.BackgroundColor = ConsoleColor.DarkGray;
                     break;
                 }
             case 6:
                 {
                     Console.BackgroundColor = ConsoleColor.DarkGreen;
                     break;
                 }
             case 7:
                 {
                     Console.BackgroundColor = ConsoleColor.DarkMagenta;
                     break;
                 }
             case 8:
                 {
                     Console.BackgroundColor = ConsoleColor.DarkRed;
                     break;
                 }
             case 9:
                 {
                     Console.BackgroundColor = ConsoleColor.DarkYellow;
                     break;
                 }
             case 10:
                 {
                     Console.BackgroundColor = ConsoleColor.Gray;
                     break;
                 }
             case 11:
                 {
                     Console.BackgroundColor = ConsoleColor.Green;
                     break;
                 }
             case 12:
                 {
                     Console.BackgroundColor = ConsoleColor.Magenta;
                     break;
                 }
             case 13:
                 {
                     Console.BackgroundColor = ConsoleColor.Red;
                     break;
                 }
             case 14:
                 {
                     Console.BackgroundColor = ConsoleColor.White;
                     break;
                 }
             case 15:
                 {
                     Console.BackgroundColor = ConsoleColor.Yellow;
                     break;
                 }
             default:
                 {
                     Console.BackgroundColor = ConsoleColor.White;
                     break;
                 }
         }
     }
 }
コード例 #17
0
 public ParsedToken(string Data, tokenType TokenType)
     : base(Data, elementType.token)
 {
     this.TokenType = TokenType;
 }
コード例 #18
0
        private tokenObject ProcessSymbolsAndPunctuations()
        {
            if (_currentCharacterRead == '_' && char.IsLetterOrDigit(_nextCharacterRead))
            {
                return(ProcessWord());
            }

            _currentLexeme = _currentCharacterRead.ToString();
            tokenType probableTokenType = tokenType.NaN;

            if (_dictionary.identifySymbolAndPunctuation(_currentLexeme) != tokenType.ErrorToken)
            {
                probableTokenType = _dictionary.identifySymbolAndPunctuation(_currentLexeme);
                switch (_currentLexeme)
                {
                case "<":
                    if (char.IsLetter(_nextCharacterRead))
                    {
                        return(ProcessFileName());
                    }
                    break;

                case "\'":
                    return(ProcessCharacter());

                    break;

                case "\"":
                    return(ProcessString());

                    break;

                case "#":
                    if (char.IsDigit(_nextCharacterRead))
                    {
                        return(ProcessDate());
                    }
                    break;
                }

                while (_dictionary.identifySymbolAndPunctuation(_currentLexeme + _nextCharacterRead) != tokenType.ErrorToken)
                {
                    AdvanceCursors();
                    _currentLexeme += _currentCharacterRead.ToString();

                    probableTokenType = _dictionary.identifySymbolAndPunctuation(_currentLexeme);
                    if (probableTokenType == tokenType.symbol_COMMENTLINE)
                    {
                        while (_nextCharacterRead != '\n')
                        {
                            AdvanceCursors();
                        }
                        ////var returnToken = new tokenObject(probableTokenType, _currentLexeme, _lastLocation);
                        var returnToken = GenerateToken();
                        ClearContent();
                        return(returnToken);
                    }
                    if (probableTokenType == tokenType.symbol_commentOpen)
                    {
                        AddLayer("COMMENTBLOCK");
                        // var returnToken = new tokenObject(probableTokenType, _currentLexeme, _lastLocation);
                        var returnToken = GenerateToken();
                        ClearContent();
                        return(returnToken);
                    }
                }
            }
            else
            {
                throw new Exception("This Symbol Does not Exist. " + _currentLexeme + " At: " + _lastLocation);
            }
            var newToken = new tokenObject(probableTokenType, _currentLexeme, _lastLocation);

            ClearContent();
            return(newToken);
        }
コード例 #19
0
 : base(new DiscordSharder(tokenType, token, configuration ??= new DiscordBotSharderConfiguration()), prefixProvider, configuration)