Пример #1
0
        /// <summary>
        /// Reads the keywords from file.
        /// </summary>
        private static void ReadKeyWords()
        {

#if MyCode

            Keywords = File.ReadAllLines(Compiler.CoreResource.KeyWordsFile).
                            Select(str => str.Trim()).
                            ToDictionary(str => str, str => (TypeSymbol)Enum.Parse(typeof(TypeSymbol), str, false));

#elif ModifiedCode

            keywordsSymbol = File.ReadAllLines(Compiler.CoreResource.KeyWordsFile).Select(str => str.Trim()).
                Select(str => new Symbol { Name = str, Kind = (TypeSymbol)Enum.Parse(typeof(TypeSymbol), str, false) }).
                Reverse().Aggregate((one, two) =>
                {
                    two.Next = one;
                    return two;
                });
            
            // this is the old way using modified structure (IEnumerable Symbol) sequence
 
            //List<Symbol> list = File.ReadAllLines(Compiler.CoreResource.KeyWordsFile).Select(str => str.Trim()).
            //    Select(str => new Symbol { Name = str, Kind = (TypeSymbol)Enum.Parse(typeof(TypeSymbol), str, false) }).ToList();
            //keywordsSymbol = list.First();
            //Symbol last = list.Aggregate((one, two) => one.Next = two);
#else
            TSymbol last = null;
            int counter = 0;

            using (StreamReader reader = File.OpenText(CompilerLibraryResource.KeyWordsFile))
            {
                while (!reader.EndOfStream)
                {
                    string key = reader.ReadLine().Trim();
                    TSymbol symbol = new TSymbol() { Name = key, Next = null, UL = (TypeSymbol)counter };
                    counter++;

                    if (Gsymbol == null)
                    {
                        Gsymbol = symbol;
                    }
                    else
                    {
                        last.Next = symbol;
                    }

                    last = symbol;
                }
            }
#endif
        }
Пример #2
0
        private TypeSymbol HandleIdentifier()
        {
            id = CC.ToString();
            CI++;

            while (CCInLine && (char.IsNumber(CC) || char.IsLetter(CC) || CC == '_'))
            {
                id += CC;
                CI++;
            }

            TSymbol symAux = TSymbol.FindSymbol(id, AubCompiler.Gsymbol);
            if (symAux != null)
            {
                return symAux.UL;
            }

            string idUpperCase = id.ToUpper();
            G_curr_ID = IdentifierInstruction.FindIdentifer(idUpperCase, gVar);
            if (G_curr_ID != null)
            {
                return TypeSymbol.U_Var;
            }

            G_curr_ID = IdentifierInstruction.FindIdentifer(idUpperCase, gDefine);
            if (G_curr_ID != null)
            {
                return TypeSymbol.U_VarDefine;
            }

            G_curr_ID = IdentifierInstruction.FindIdentifer(idUpperCase, gProc);
            if (G_curr_ID != null)
            {
                return TypeSymbol.U_VarProcedure;
            }

            G_curr_Str = id.ToUpper();
            return TypeSymbol.U_UnKown;
        }