Esempio n. 1
0
        public static void Add(LexicalComponent component)
        {
            if (component != null)
            {
                component = ReservedKeywordsTable.CheckReservedKeyword(component);
                component = LiteralsTable.CheckLiteral(component);
                switch (component.ComponentType)
                {
                case ComponentType.Symbol:
                    SymbolsTable.Add(component);
                    break;

                case ComponentType.ReservedKeyword:
                    ReservedKeywordsTable.Add(component);
                    break;

                case ComponentType.Dummy:
                    DummiesTable.Add(component);
                    break;

                case ComponentType.Literal:
                    LiteralsTable.Add(component);
                    break;

                default:
                    throw new Exception("Unsupported lexical component type");
                }
            }
        }
Esempio n. 2
0
 public static LexicalComponent CheckLiteral(LexicalComponent component)
 {
     if (component != null && (component.Category == Category.Decimal || component.Category == Category.Integer))
     {
         return(LexicalComponent.CreateLiteral(
                    component.Category,
                    component.Lexeme,
                    component.LineNumber,
                    component.InitialPosition,
                    component.FinalPosition));
     }
     return(component);
 }
Esempio n. 3
0
        private static void Initialize()
        {
            _baseReservedKeywords.Add("AND", LexicalComponent.CreateReservedKeyword(Category.And, "AND"));
            _baseReservedKeywords.Add("OR", LexicalComponent.CreateReservedKeyword(Category.Or, "OR"));
            _baseReservedKeywords.Add("ORDER BY", LexicalComponent.CreateReservedKeyword(Category.Order_by, "ORDER BY"));
            _baseReservedKeywords.Add("ASC", LexicalComponent.CreateReservedKeyword(Category.Asc, "ASC"));
            _baseReservedKeywords.Add("DESC", LexicalComponent.CreateReservedKeyword(Category.Desc, "DESC"));
            _baseReservedKeywords.Add("FROM", LexicalComponent.CreateReservedKeyword(Category.From, "FROM"));
            _baseReservedKeywords.Add("WHERE", LexicalComponent.CreateReservedKeyword(Category.Where, "WHERE"));
            _baseReservedKeywords.Add("SELECT", LexicalComponent.CreateReservedKeyword(Category.Select, "SELECT"));

            _tableInitialized = true;
        }
Esempio n. 4
0
 public static void Add(LexicalComponent component)
 {
     if (component != null && component.ComponentType == ComponentType.Symbol)
     {
         if (_symbolsTable.ContainsKey(component.Lexeme))
         {
             _symbolsTable[component.Lexeme].Add(component);
         }
         else
         {
             _symbolsTable.Add(component.Lexeme, new List <LexicalComponent> {
                 component
             });
         }
     }
 }
Esempio n. 5
0
 public static void Add(LexicalComponent component)
 {
     if (component != null && component.ComponentType == ComponentType.ReservedKeyword)
     {
         if (_reservedKeywords.ContainsKey(component.Lexeme))
         {
             _reservedKeywords[component.Lexeme].Add(component);
         }
         else
         {
             _reservedKeywords.Add(component.Lexeme, new List <LexicalComponent> {
                 component
             });
         }
     }
 }
Esempio n. 6
0
        public static LexicalComponent CheckReservedKeyword(LexicalComponent component)
        {
            if (!_tableInitialized)
            {
                Initialize();
            }

            if (_baseReservedKeywords.ContainsKey(component?.Lexeme?.ToUpper()) && component.Category == Category.Identifier)
            {
                return(LexicalComponent.CreateReservedKeyword(
                           _baseReservedKeywords[component.Lexeme.ToUpper()].Category,
                           component.Lexeme,
                           component.LineNumber,
                           component.InitialPosition,
                           component.FinalPosition));
            }

            return(component);
        }