Beispiel #1
0
        static void PrintLexmes(Lexer.Lexer lexer)
        {
            //print all found tokens (except whitespace ones, they will be processed for easier reading)
            foreach (Lexer.Line line in lexer.LexedLines)
            {
                foreach (Lexer.Lexme lexme in line.Tokens)
                {
                    if (lexme.Type == Stellarmass.LPC.Lexer.LexmeType.Whitespace)
                    {
                        string tab       = "\t\t";
                        int    remainder = lexme.Data.Length / 5;
                        for (int index = 1; index > remainder; index--)
                        {
                            tab += "\t";
                        }

                        if (lexme.Data.ToString() == Environment.NewLine)
                        {
                            Console.WriteLine("-\\n-" + tab + "TYPE: " + lexme.Type.ToString());
                        }
                        if (lexme.Data.ToString() == "\t")
                        {
                            Console.WriteLine("-\\t-" + tab + "TYPE: " + lexme.Type.ToString());
                        }
                    }
                    else if (lexme.Type == Stellarmass.LPC.Lexer.LexmeType.NewLine)
                    {
                        string tab       = "\t\t";
                        int    remainder = lexme.Data.Length / 5;
                        for (int index = 1; index > remainder; index--)
                        {
                            tab += "\t";
                        }

                        Console.WriteLine("-\\n-" + tab + "TYPE: " + lexme.Type.ToString());
                    }
                    else
                    {
                        string tab       = "\t\t";
                        int    remainder = lexme.Data.Length / 5;
                        if (lexme.Data.Length < 15)
                        {
                            for (int index = 1; index > remainder; index--)
                            {
                                tab += "\t";
                            }
                        }

                        if (lexme.Data.ToString() == Environment.NewLine)
                        {
                            Console.WriteLine("-\\n-" + tab + "TYPE: " + lexme.Type.ToString());
                        }
                        else
                        {
                            Console.WriteLine("-" + lexme.Data + "-" + tab + "TYPE: " + lexme.Type.ToString());
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public bool LoadLPC(string filePath)
        {
            System.IO.StreamReader stream;
            try {
                stream = new System.IO.StreamReader(filePath, Globals.WorkspaceSave.LPCEncoding);
            }
            catch (System.IO.IOException exception)
            {
                string str = "File error:\n\n" + exception.Message;
                System.Windows.Forms.MessageBox.Show(str);
                return(false);
            }

            Scanner.Scanner scanner;
            Lexer.Lexer     lexer;
            Parser.Parser   parser;

            try
            {
                scanner = new Scanner.Scanner(stream);
                stream.Close();
                lexer  = new Lexer.Lexer(scanner);
                parser = new Parser.Parser(lexer, DecomposedCode.map);
            }
            catch (Exception exception)
            {
                string str = "Error parsing LPC file: \n\n" + exception.Message;
                System.Windows.Forms.MessageBox.Show(str);
                return(false);
            }

            this.Tokens = parser.LPCTokens;

            BuildFunctionBodyMap();
            return(true);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //last - 25 - 33
            int UNIT_TEST = 37;

            StreamReader stream = new StreamReader(new MemoryStream(Globals.LpcInternalCodec.GetBytes(LPC.RoomUnitTests.GetUnitTest("section 1", UNIT_TEST))), Stellarmass.LPC.Globals.LpcFileCodec, false);

            Parser.ParseMap    map;
            Parser.SyntaxRules lpcRules = new Stellarmass.LPC.Parser.SyntaxRules(out map);


            Scanner.Scanner scanner;
            Lexer.Lexer     lexer;
            Parser.Parser   parser;

            Console.BufferHeight = 13000;
            Console.WindowWidth  = 120;
            Console.WindowHeight = 60;

            try{
                scanner = new Scanner.Scanner(stream);
                lexer   = new Lexer.Lexer(scanner);
                parser  = new Parser.Parser(lexer, map);
            }
            catch (Exception e)
            {
                Console.WriteLine("Syntax Error:\n\n" + e.Message);
                End();
                return;
            }

            List <Parser.Token> TokenCopies = parser.LPCTokens;



            //start over
            stream = new StreamReader(new MemoryStream(Globals.LpcInternalCodec.GetBytes(LPC.RoomUnitTests.GetUnitTest("section 1", UNIT_TEST))), Stellarmass.LPC.Globals.LpcFileCodec, false);

            lpcRules = new Stellarmass.LPC.Parser.SyntaxRules(out map);
            try{
                scanner = new Scanner.Scanner(stream);
                lexer   = new Lexer.Lexer(scanner);
                parser  = new Parser.Parser(lexer, map);
            }
            catch (Exception e)
            {
                Console.WriteLine("Syntax Error:\n\n" + e.Message);
                End();
                return;
            }



            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.White;
            Console.WriteLine("\n\n\n---- LPC LEXMES FOUND ----\n\n");
            Console.ResetColor();
            PrintLexmes(lexer);

            //print all tokens found (process whitespace accordingly)
            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.White;
            Console.WriteLine("\n\n\n---- LPC TOKENS FOUND ----\n\n");
            Console.ResetColor();
            PrintTokens(parser.LPCTokens, "\t");

            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.White;
            Console.WriteLine("\n\n\n---- ORIGINAL CODE FILE ----\n\n");
            Console.ResetColor();
            PrintOriginalCode(LPC.RoomUnitTests.UnitTests[UNIT_TEST]);
            Console.ResetColor();
            Console.WriteLine("\n\n\n");

            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.White;
            Console.WriteLine("\n\n\n---- RECOMPOSED CODE FILE ----\n\n");
            Console.ResetColor();
            PrintRecomposedCode(parser.LPCTokens);
            Console.ResetColor();
            Console.WriteLine("\n\n\n");
            LPC.RoomUnitTests.CompareUnitTests(parser.LPCTokens, UNIT_TEST);



            End();
        }