Example #1
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);
        }
Example #2
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();
        }