示例#1
0
文件: Program.cs 项目: baban/lp
        static long runNode(string[] argv)
        {
            string fileName = argv[0];
            string code     = readFile(fileName);

            var       parser   = new Parser.LpGrammer();
            var       language = new LanguageData(parser);
            ScriptApp app      = new ScriptApp(language);
            var       tree     = app.Parser.Parse(code);

            Object.LpObject result = null;
            try
            {
                result = (Object.LpObject)app.Evaluate(tree);
                if (result == null)
                {
                    Debug.WriteLine("null");
                }
                else
                {
                    Console.WriteLine(result);
                    Console.WriteLine("result: {0}", result);
                    result.funcall("display", new Object.LpObject[] { }, null);
                }
            }
            catch (Error.LpError e)
            {
                Console.WriteLine(e.ToString());
            }
            Debug.WriteLine("Finish");

            return(0);
        }
示例#2
0
文件: Program.cs 项目: baban/lp
        static void consoleReadFile()
        {
            printVersion();
            // Console.WriteLine("[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin");
            // Console.WriteLine("[Type 'help' 'copyright' 'credits' or 'licence' for more information");
            Debug.WriteLine("initialize");
            var parser = new Parser.LpGrammer();
            //Console.WriteLine("initialize parser");
            var language = new LanguageData(parser);
            //Console.WriteLine("initialize language");
            ScriptApp app = new ScriptApp(language);

            Debug.WriteLine("parse");

            string line = null;

            do
            {
                Console.Write(" >> ");
                line = Console.ReadLine();
                try {
                    var tree = app.Parser.Parse(line);
                    if (tree == null)
                    {
                        Debug.WriteLine("parse error");
                    }
                    else
                    {
                        Object.LpObject result = (Object.LpObject)app.Evaluate(tree);
                        if (result == null)
                        {
                            Debug.WriteLine("null");
                        }
                        else
                        {
                            result.funcall("display", new Object.LpObject[] { }, null);
                        }
                    }
                }
                catch (Error.LpError e) {
                    printError(e);
                }
            } while (true);
        }
示例#3
0
文件: Program.cs 项目: baban/lp
        static void Main(string[] args)
        {
            //runTestCode();
            //return;

            if (args.Length == 0)
            {
                sysInit("", args, 0);
                consoleReadFile();
            }
            var options = new Options();
            //コマンドライン引数を解析する
            bool isSuccess = CommandLine.Parser.Default.ParseArguments(args, options);

            if (isSuccess)
            {
                if (options.Verbose)
                {
                    printVersion();
                    return;
                }

                if (options.Evaluate != null)
                {
                    sysInit("", args, 0);
                    Debug.WriteLine("initialize");
                    var       parser   = new Parser.LpGrammer();
                    var       language = new LanguageData(parser);
                    ScriptApp app      = new ScriptApp(language);
                    Debug.WriteLine("parse");
                    return;
                }

                if (options.InputFiles.Count > 0)
                {
                    sysInit("", args, 0);
                    runNode(options.InputFiles.ToArray());
                }
            }
        }
示例#4
0
文件: Program.cs 项目: baban/lp
        static long runTestCode()
        {
            /*
             * Console.WriteLine("benckmark:start");
             * System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
             * sw.Start();
             */
            //string code = readFile(argv[0]);
            //string code = "/* 111 */ 2";
            //string code = "1";
            //string code = ":aaaa";
            //string code = "\"Hello\"";
            //string code = "true";
            //string code = "nl";
            //string code = "/regex/";
            //string code = "[]";
            //string code = "{}";
            //string code = "do |a| end";
            //string code = "-> do |a| end";
            //string code = "a=1";
            //string code = "a=1; a";
            //string code = "let a=1; a";
            //string code = "b? = 2; b?";
            //string code = "@a = 3; @a";
            //string code = "@@a = 4; @@a";
            //string code = "let a";
            //string code = "1; 2; 3";
            //string code = "a='(1+2); ?a";
            //string code = "a='(1+2); `(1+3)";
            //string code = "a='(2+3); `(1+?a)";
            //string code = "1+a";
            //string code = "1+1";
            //string code = "2*3";
            //string code = "!true";
            //string code = "1+2*3+4";
            //string code = "1.to_s()";
            //string code = "Console";
            string code = "Console.WriteLine(\"Hello,World\")";

            //string code = "def hoge() end";
            //string code = "def hoge(a) 1; 2; 3 end";
            //string code = "def hoge(a, b) 1; 2; 3 end";
            //string code = "public def hoge(a) 1; 2; 3 end";
            //string code = "abc=1+5*5; abc";
            //string code = "def bbb(a,b,c) 1; 2; c end; bbb(1,2,3)";
            //string code = "class Aaa; 1;2;3 end";
            //string code = "public class A; 1;2;3 end";
            //string code = "public class A < B; 1;2;3 end";
            //string code = "module Aaa; 1;2;3 end";
            //string code = "public module Aaa; 1;2;3 end";
            //string code = "if true; 1 end";
            //string code = "if false; 1 else 2 end";
            //string code = "if false; 1 elsif true; 2 end";
            //string code = "case 1; end";
            //string code = "case false; else 1 end";
            //string code = "case 1; when 1; 3 end";
            Debug.WriteLine("initialize");
            var parser = new Parser.LpGrammer();
            //Console.WriteLine("initialize parser");
            var language = new LanguageData(parser);
            //Console.WriteLine("initialize language");
            ScriptApp app = new ScriptApp(language);

            Debug.WriteLine("parse");
            var tree = app.Parser.Parse(code);

            //Console.WriteLine("tree");
            //Console.WriteLine(tree);

            /*
             * if (tree.HasErrors())
             * {
             *  Console.WriteLine(tree.ParserMessages.First().Message);
             *  Console.WriteLine(tree.FileName);
             *  Console.WriteLine(tree.ParserMessages.First().Location);
             *  return 0;
             * }
             */


            Debug.WriteLine("evaluate");

            Object.LpObject result = null;
            try
            {
                result = (Object.LpObject)app.Evaluate(tree);
                if (result == null)
                {
                    Debug.WriteLine("null");
                }
                else
                {
                    Console.WriteLine(result);
                    Console.WriteLine("result: {0}", result);
                    result.funcall("display", new Object.LpObject[] { }, null);
                }
            }
            catch (Error.LpError e)
            {
                Console.WriteLine(e.ToString());
            }
            Debug.WriteLine("Finish");

            /*
             * sw.Stop();
             * Console.WriteLine(sw.Elapsed.TotalSeconds);
             * Console.WriteLine("benckmark:end");
             */
            return(0);
        }