Exemple #1
0
        public NovelScript ParseText(string fileName, string scriptCode, NovelFunctionPool funcPool = null)
        {
            //Setup variables
            CharacterPointer = 0;

            //Setting up parsed text
            ParsedText = scriptCode;

            //Setting up parsed file name
            ParsedFile = fileName;

            //Setting up parsedline
            ParsedLine = -1;

            //Main block of grouped code
            var mainBlock = new NovelParserBlock();

            //For reading purposes
            int endIndex           = 0;
            NovelParserBlock block = null;

            //Read all the blocks in file
            while ((block = ReadBlock(scriptCode, endIndex, out endIndex)) != null)
            {
                mainBlock.Content.Add(block);
            }

            return(ParseScript(fileName, mainBlock, funcPool));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var text = File.ReadAllText("kitchen.txt");

            NovelFunctionPool delegates = new NovelFunctionPool();

            delegates.AddFunction(new Func <int, string, int>(C1));
            delegates.AddFunction(new Func <int, int>(C2));
            delegates.AddFunction(new Func <int, int>(C3));
            delegates.AddFunction(new Func <int, int>(C4));
            delegates.AddFunction(new Func <int, int>(C5));

            var script   = new NovelParser().ParseText("kitchen.txt", text, delegates);
            var executor = new NovelExecutor(script);

            executor.Reset();
            executor.CallScriptFunction("main", null);
            executor.ContinueExecution();
        }
        private NovelScript ParseScript(string name, NovelParserBlock block, NovelFunctionPool funcPool = null)
        {
            //Setup script
            ParsedScript = new NovelScript(name);
            ParsedScript.DelegateFunctionList = funcPool;

            try
            {
                ParsedScript = ParseScript(ParsedScript, block, ParentBlockType.StartBlock, 0);
            }
            catch (NovelException exception)
            {
                //TODO remove
                //Print the exception
                Console.WriteLine(exception.Message);
            }

            return(ParsedScript);
        }