Ejemplo n.º 1
0
        internal void SetBackgroundColor(TokenClassification tokenKind, ConsoleColor color)
        {
            switch (tokenKind)
            {
            case TokenClassification.None:      DefaultTokenBackgroundColor = color; break;

            case TokenClassification.Comment:   CommentBackgroundColor = color; break;

            case TokenClassification.Keyword:   KeywordBackgroundColor = color; break;

            case TokenClassification.String:    StringBackgroundColor = color; break;

            case TokenClassification.Operator:  OperatorBackgroundColor = color; break;

            case TokenClassification.Variable:  VariableBackgroundColor = color; break;

            case TokenClassification.Command:   CommandBackgroundColor = color; break;

            case TokenClassification.Parameter: ParameterBackgroundColor = color; break;

            case TokenClassification.Type:      TypeBackgroundColor = color; break;

            case TokenClassification.Number:    NumberBackgroundColor = color; break;

            case TokenClassification.Member:    MemberBackgroundColor = color; break;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Standard constructor
 /// </summary>
 protected TokenDescription(int priority,
                            TokenDescriptionOptions options,
                            TokenClassification classification = TokenClassification.Unknown)
 {
     Priority       = priority;
     Options        = options;
     Classification = classification;
 }
Ejemplo n.º 3
0
 void AddToken(string sem, TokenClassification cl)
 {
     if (!tokenchain.AddToken(file.GetLineNum(), sem, cl))
     {
         //若未添加Token成功则进行错误处理
         //TODO
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Create
 /// </summary>
 public static TokenDescription Create(TokenKeyWords keyWords,
                                       int priority = DefaultPriority - 200,
                                       TokenClassification classification = TokenClassification.Unknown)
 {
     return(new TokenDescriptionKeyWords(keyWords, priority)
     {
         Classification = classification
     });
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Create
 /// </summary>
 public static TokenDescription Create(TokenDescriptionFunc.Locator entireLocator,
                                       int priority = DefaultPriority,
                                       TokenDescriptionOptions options    = TokenDescriptionOptions.None,
                                       TokenClassification classification = TokenClassification.Unknown)
 {
     return(new TokenDescriptionFunc(entireLocator, priority, options)
     {
         Classification = classification
     });
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Create
 /// </summary>
 public static TokenDescription Create(string entirePattern,
                                       int priority = DefaultPriority,
                                       TokenDescriptionOptions options    = TokenDescriptionOptions.None,
                                       TokenClassification classification = TokenClassification.Unknown)
 {
     return(new TokenDescriptionRegex(entirePattern, priority, options)
     {
         Classification = classification
     });
 }
Ejemplo n.º 7
0
        public bool AddToken(int line, string sem, TokenClassification type)
        {
            Token token = TokenFactor(line, sem, type);

            if (token != null)
            {
                list.Add(token); return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create
        /// </summary>
        public static TokenDescription Create(IEnumerable <string> words,
                                              int priority = DefaultPriority,
                                              TokenDescriptionOptions options    = TokenDescriptionOptions.None,
                                              TokenClassification classification = TokenClassification.Unknown)
        {
            bool          caseSensitive = !((options & TokenDescriptionOptions.IgnoreCase) == TokenDescriptionOptions.IgnoreCase);
            TokenKeyWords keyWords      = new TokenKeyWords(caseSensitive, words);

            return(new TokenDescriptionKeyWords(keyWords, priority)
            {
                Classification = classification
            });
        }
Ejemplo n.º 9
0
        static Token TokenFactor(int line, string sem, TokenClassification type)
        {
            if (type == TokenClassification.Ididentifier)
            {
                switch (sem)
                {
                case "main": return(new Token(line, sem, TokenType.Main));

                case "if": return(new Token(line, sem, TokenType.If));

                case "else": return(new Token(line, sem, TokenType.Else));

                case "for": return(new Token(line, sem, TokenType.For));

                case "int": return(new Token(line, sem, TokenType.Int));

                case "void": return(new Token(line, sem, TokenType.Void));

                case "return": return(new Token(line, sem, TokenType.Return));

                default: return(new Token(line, sem, TokenType.ID));
                }
            }
            else if (type == TokenClassification.Num)
            {
                return(new Token(line, sem, TokenType.NUM));
            }
            else if (type == TokenClassification.Sign)
            {
                switch (sem)
                {
                case "=": return(new Token(line, sem, TokenType.Assign));

                case "<=": return(new Token(line, sem, TokenType.LowerEqual));

                case "<": return(new Token(line, sem, TokenType.Lower));

                case ">": return(new Token(line, sem, TokenType.Greater));

                case ">=": return(new Token(line, sem, TokenType.GreaterEqual));

                case "==": return(new Token(line, sem, TokenType.Equal));

                case "!=": return(new Token(line, sem, TokenType.Unequal));

                case "+": return(new Token(line, sem, TokenType.Plus));

                case "-": return(new Token(line, sem, TokenType.Minus));

                case "*": return(new Token(line, sem, TokenType.Multiply));

                case "/": return(new Token(line, sem, TokenType.Divide));

                case ";": return(new Token(line, sem, TokenType.EndSentence));

                case ",": return(new Token(line, sem, TokenType.Dot));

                case "[": return(new Token(line, sem, TokenType.RBL));

                case "]": return(new Token(line, sem, TokenType.RBR));

                case "(": return(new Token(line, sem, TokenType.CBL));

                case ")": return(new Token(line, sem, TokenType.CBR));

                case "{": return(new Token(line, sem, TokenType.FBL));

                case "}": return(new Token(line, sem, TokenType.FBR));

                default: return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 10
0
 internal void SetForegroundColor(TokenClassification tokenKind, ConsoleColor color)
 {
     switch (tokenKind)
     {
     case TokenClassification.None:      DefaultTokenForegroundColor = color; break;
     case TokenClassification.Comment:   CommentForegroundColor = color; break;
     case TokenClassification.Keyword:   KeywordForegroundColor = color; break;
     case TokenClassification.String:    StringForegroundColor = color; break;
     case TokenClassification.Operator:  OperatorForegroundColor = color; break;
     case TokenClassification.Variable:  VariableForegroundColor = color; break;
     case TokenClassification.Command:   CommandForegroundColor = color; break;
     case TokenClassification.Parameter: ParameterForegroundColor = color; break;
     case TokenClassification.Type:      TypeForegroundColor = color; break;
     case TokenClassification.Number:    NumberForegroundColor = color; break;
     case TokenClassification.Member:    MemberForegroundColor = color; break;
     }
 }