public List <object> Allow; //判断条件 public TempCase(Script script, List <object> allow, ScriptExecutable executable, Executable_Block block) { m_Script = script; this.Allow = allow; this.Executable = executable; this.Block = block; }
public CodeObject Allow; //判断条件 public TempCondition(Script script, CodeObject allow, ScriptExecutable executable, Executable_Block block) { m_Script = script; this.Allow = allow; this.Executable = executable; this.Block = block; }
private ScriptExecutable ParseStatementBlock(Executable_Block block, bool readLeftBrace, Scorpio.Compiler.TokenType finished) { this.BeginExecutable(block); if (readLeftBrace && (this.PeekToken().Type != Scorpio.Compiler.TokenType.LeftBrace)) { this.ParseStatement(); if (this.PeekToken().Type == Scorpio.Compiler.TokenType.SemiColon) { this.ReadToken(); } } else { if (readLeftBrace) { this.ReadLeftBrace(); } while (this.HasMoreTokens()) { if (this.ReadToken().Type == finished) { break; } this.UndoToken(); this.ParseStatement(); } } ScriptExecutable scriptExecutable = this.m_scriptExecutable; scriptExecutable.EndScriptInstruction(); this.EndExecutable(); return(scriptExecutable); }
/// <summary> /// Conscructs a script associated with the given ScriptManager /// and using the given resource name. /// </summary> /// <param name="scriptManager">ScriptManager associated with /// the script.</param> /// <param name="strScriptName">Resource name for loading the /// script.</param> public Script(ScriptManager scriptManager, String strScriptName) { m_scriptManager = scriptManager; m_strName = strScriptName; try { LoadScript(strScriptName); ScriptLexer scriptLexer = new ScriptLexer(m_listSourceLines); List <Token> listTokens = scriptLexer.GetTokens(); // parse/compile script ScriptParser scriptParser = new ScriptParser(this, listTokens); scriptParser.DebugMode = m_scriptManager.DebugMode; m_scriptExecutable = scriptParser.Parse(); // optimise if (m_scriptManager.OptimiseCode) { ExecutionOptimiser executionOptimiser = new ExecutionOptimiser(m_scriptExecutable); executionOptimiser.OptimiserInfo = false; executionOptimiser.Optimise(); } } catch (Exception exception) { throw new UbikException( "Error while loading or compiling script '" + strScriptName + "'.", exception); } }
//解析区域代码内容( {} 之间的内容) private ScriptExecutable ParseStatementBlock(Executable_Block block, bool readLeftBrace, TokenType finished) { BeginExecutable(block); if (readLeftBrace && PeekToken().Type != TokenType.LeftBrace) { ParseStatement(); if (PeekToken().Type == TokenType.SemiColon) { ReadToken(); } } else { if (readLeftBrace) { ReadLeftBrace(); } TokenType tokenType; while (HasMoreTokens()) { tokenType = ReadToken().Type; if (tokenType == finished) { break; } UndoToken(); ParseStatement(); } } ScriptExecutable ret = m_scriptExecutable; ret.EndScriptInstruction(); EndExecutable(); return(ret); }
public ScorpioScriptFunction(Script script, List <String> listParameters, ScriptExecutable scriptExecutable, bool bParams) { this.m_Script = script; this.m_ListParameters = listParameters.ToArray(); this.m_ScriptExecutable = scriptExecutable; this.m_ParameterCount = listParameters.Count; this.m_Params = bParams; }
private ScriptScriptFunction ParseFunctionDeclaration(bool needName) { Token token = this.ReadToken(); if (token.Type != Scorpio.Compiler.TokenType.Function) { throw new ParserException("Function declaration must start with the 'function' keyword.", token); } string name = needName ? this.ReadIdentifier() : ((this.PeekToken().Type == Scorpio.Compiler.TokenType.Identifier) ? this.ReadIdentifier() : ""); List <string> listParameters = new List <string>(); bool bParams = false; Token token2 = this.ReadToken(); if (token2.Type != Scorpio.Compiler.TokenType.LeftPar) { goto Label_0107; } if (this.PeekToken().Type == Scorpio.Compiler.TokenType.RightPar) { goto Label_00F9; } Label_0073: token = this.ReadToken(); if (token.Type == Scorpio.Compiler.TokenType.Params) { token = this.ReadToken(); bParams = true; } if (token.Type != Scorpio.Compiler.TokenType.Identifier) { throw new ParserException("Unexpected token '" + token.Lexeme + "' in function declaration.", token); } string item = token.Lexeme.ToString(); listParameters.Add(item); token = this.PeekToken(); if ((token.Type == Scorpio.Compiler.TokenType.Comma) && !bParams) { this.ReadComma(); goto Label_0073; } if (token.Type != Scorpio.Compiler.TokenType.RightPar) { throw new ParserException("Comma ',' or right parenthesis ')' expected in function declararion.", token); } Label_00F9: this.ReadRightParenthesis(); token2 = this.ReadToken(); Label_0107: if (token2.Type == Scorpio.Compiler.TokenType.LeftBrace) { this.UndoToken(); } ScriptExecutable scriptExecutable = this.ParseStatementBlock(Executable_Block.Function); return(new ScriptScriptFunction(this.m_script, name, new ScorpioScriptFunction(this.m_script, listParameters, scriptExecutable, bParams))); }
//解析函数(返回一个函数) private ScriptScriptFunction ParseFunctionDeclaration(bool needName) { Token token = ReadToken(); if (token.Type != TokenType.Function) { throw new ParserException("Function declaration must start with the 'function' keyword.", token); } String strFunctionName = needName ? ReadIdentifier() : (PeekToken().Type == TokenType.Identifier ? ReadIdentifier() : ""); List <String> listParameters = new List <String>(); bool bParams = false; Token peek = ReadToken(); if (peek.Type == TokenType.LeftPar) { if (PeekToken().Type != TokenType.RightPar) { while (true) { token = ReadToken(); if (token.Type == TokenType.Params) { token = ReadToken(); bParams = true; } if (token.Type != TokenType.Identifier) { throw new ParserException("Unexpected token '" + token.Lexeme + "' in function declaration.", token); } String strParameterName = token.Lexeme.ToString(); listParameters.Add(strParameterName); token = PeekToken(); if (token.Type == TokenType.Comma && !bParams) { ReadComma(); } else if (token.Type == TokenType.RightPar) { break; } else { throw new ParserException("Comma ',' or right parenthesis ')' expected in function declararion.", token); } } } ReadRightParenthesis(); peek = ReadToken(); } if (peek.Type == TokenType.LeftBrace) { UndoToken(); } ScriptExecutable executable = ParseStatementBlock(Executable_Block.Function); return(new ScriptScriptFunction(m_script, strFunctionName, new ScorpioScriptFunction(m_script, listParameters, executable, bParams))); }
/// <summary> /// Constructs a script function for the given /// <see cref="ScriptExecutable"/>, with the given name, parameter /// count and entry point into the executable. /// </summary> /// <param name="scriptExecutable">Executable form of the /// <see cref="Script"/>.</param> /// <param name="strName">Script function name.</param> /// <param name="listParameters">List of parameter names.</param> /// <param name="scriptInstructionEntryPoint">Entry point /// <see cref="ScriptInstruction"/> in the executable.</param> public ScriptFunction(ScriptExecutable scriptExecutable, String strName, List <String> listParameters, ScriptInstruction scriptInstructionEntryPoint) { m_scriptExecutable = scriptExecutable; m_strName = strName; m_listParameters = new List <string>(listParameters); m_scriptInstructionEntryPoint = scriptInstructionEntryPoint; }
public ScorpioScriptFunction(Script script, List <String> listParameters, ScriptExecutable scriptExecutable, bool bParams) { this.m_Script = script; this.m_ListParameters = new List <string>(listParameters); this.m_ScriptExecutable = scriptExecutable; this.m_ParameterCount = listParameters.Count; this.m_Params = bParams; this.m_ParamsArray = bParams ? script.CreateArray() : null; this.m_Context = new ScriptContext(m_Script, m_ScriptExecutable, null, Executable_Block.Function); }
public ScriptObject LoadTokens(String strBreviary, List <Token> tokens) { try { m_StackInfoStack.Clear(); ScriptParser scriptParser = new ScriptParser(this, tokens, strBreviary); ScriptExecutable scriptExecutable = scriptParser.Parse(); return(new ScriptContext(this, scriptExecutable, null, Executable_Block.Context).Execute()); } catch (System.Exception e) { throw new ScriptException("load tokens [" + strBreviary + "] is error : " + e.ToString()); } }
private ScriptObject Load(String strBreviary, List <Token> tokens, ScriptContext context) { if (tokens.Count == 0) { return(m_Null); } ScriptParser scriptParser = new ScriptParser(this, tokens, strBreviary); ScriptExecutable scriptExecutable = scriptParser.Parse(); return(new ScriptContext(this, scriptExecutable, context, Executable_Block.Context).Execute()); }
internal ScriptObject LoadString(String strBreviary, String strBuffer, ScriptContext context) { try { m_StackInfoStack.Clear(); ScriptLexer scriptLexer = new ScriptLexer(strBuffer); strBreviary = Util.IsNullOrEmpty(strBreviary) ? scriptLexer.GetBreviary() : strBreviary; ScriptParser scriptParser = new ScriptParser(this, scriptLexer.GetTokens(), strBreviary); ScriptExecutable scriptExecutable = scriptParser.Parse(); return(new ScriptContext(this, scriptExecutable, context, Executable_Block.Context).Execute()); } catch (System.Exception e) { throw new ScriptException("load buffer [" + strBreviary + "] is error : " + e.ToString()); } }
/** * Evaluate script * * @param stream The stream that contains the script * @return The exit status * @throws IOException */ public JavaScriptObject Execute(Stream stream) { foreach (Function customFunction in CustomFunctions) { this.scope.SetFunction(customFunction); } Lexer lexer = new Lexer(stream); Parser parser = new Parser(lexer); ScriptExecutable executable = parser.Parse(); return(executable.Run(scope)); }
/// <summary> /// Calls the executable operation and runs the script /// </summary> public void Run() { Running = true; CurrentRunningScript = ScriptPath; Debug.Assert(ScriptExecutable != null, "Call Compile on this script before you run it"); ScriptExecutable.PerformOperation(); // Reset the current scope to the global scope CelesteStack.Scopes.Remove(ScriptScope); CelesteStack.CurrentScope = CelesteStack.GlobalScope; // Clear the stack - there should be no objects on the stack over different scripts CelesteStack.Clear(); Running = false; }
//解析try catch private void ParseTry() { CodeTry ret = new CodeTry(); { ScriptExecutable exec = ParseStatementBlock(Executable_Block.Context); ret.TryContext = new ScriptContext(m_script, exec); } { ReadCatch(); ReadLeftParenthesis(); ret.Identifier = ReadIdentifier(); ReadRightParenthesis(); ScriptExecutable exec = ParseStatementBlock(Executable_Block.Context); ret.CatchContext = new ScriptContext(m_script, exec); } m_scriptExecutable.AddScriptInstruction(new ScriptInstruction(Opcode.CALL_TRY, ret)); }
public ScriptContext Context; //指令执行 public TempCondition(Script script, CodeObject allow, ScriptExecutable executable, Executable_Block block) { this.Allow = allow; this.Executable = executable; this.Context = new ScriptContext(script, executable, null, block); }
public CodeObject[] Allow; //判断条件 public TempCase(Script script, List <CodeObject> allow, ScriptExecutable executable) { this.Allow = allow != null?allow.ToArray() : new CodeObject[0]; this.Executable = executable; }
public ScriptScriptFunction Parse() { ScriptExecutable executable = ParseStatementBlock(Executable_Block.Function, false, TokenType.Finished); return(new ScriptScriptFunction(m_script, "", new ScorpioScriptFunction(m_script, new List <String>(), executable, false))); }
public void EndExecutable() { this.m_Executables.Pop(); this.m_scriptExecutable = (this.m_Executables.Count > 0) ? this.m_Executables.Peek() : null; }
public void BeginExecutable(Executable_Block block) { this.m_scriptExecutable = new ScriptExecutable(block); this.m_Executables.Push(this.m_scriptExecutable); }
public ScriptContext Context; //指令执行 public TempCase(Script script, List <object> allow, ScriptExecutable executable, Executable_Block block) { this.Allow = allow; this.Executable = executable; this.Context = new ScriptContext(script, executable, null, block); }
public void SetContextExecutable(ScriptExecutable blockExecutable) { BlockExecutable = blockExecutable; BlockContext = new ScriptContext(m_Script, blockExecutable, null, Executable_Block.For); }
public void EndExecutable() { m_Executables.Pop(); m_scriptExecutable = (m_Executables.Count > 0) ? m_Executables.Peek() : null; }
public void BeginExecutable(Executable_Block block) { m_scriptExecutable = new ScriptExecutable(block); m_Executables.Push(m_scriptExecutable); }
public ExecutionOptimiser(ScriptExecutable scriptExecutable) { m_bOptimiserInfo = false; m_scriptExecutable = scriptExecutable; }
public CodeCallBlock(ScriptExecutable executable) { this.Executable = executable; }