public string Build() { GlobalVariables.Clear(); Main.Content = ""; StringBuilder result = new StringBuilder("#version " + Version + "\r\n"); #region prepare data VertexPositionBuilder.Build(); VertexNormalBuilder.Build(); Main.Build(); #endregion prepare data // Add global variables. foreach (var gVar in GlobalVariables) { result.Append(gVar.ToString() + ";"); } // Add Main function. result.Append(Main.Result); // return result return(result.ToString()); }
//starts the program public void Start() { builtInFunctions.Clear(); CallStack.Clear(); GlobalVariables.Clear(); CallStack.Push(new FunctionFrame("MAINSTRUCTURE")); (new StandardLibrary()).Install(ref builtInFunctions, this); (new MathLibrary()).Install(ref builtInFunctions, this); (new Linq()).Install(ref builtInFunctions, this); winInterop.Install(ref builtInFunctions, this); debugger.Install(ref builtInFunctions, this); builtInFunctions.Add("invoke", InvokeUserFunction); GlobalVariables["null"] = Value.Null; GlobalVariables["true"] = Value.True; GlobalVariables["false"] = Value.False; GlobalVariables["endl"] = new Value(Environment.NewLine); GlobalVariables["doubleType"] = new Value("fastcode.types." + ValueType.Double); GlobalVariables["stringType"] = new Value("fastcode.types." + ValueType.String); GlobalVariables["arrayType"] = new Value("fastcode.types." + ValueType.Array); GlobalVariables["charType"] = new Value("fastcode.types." + ValueType.Character); GlobalVariables["nullType"] = new Value("fastcode.types." + ValueType.Null); while (Exit == false) //program loop { while (lastToken == Token.Newline || lastToken == Token.Unkown) { keywordMarker = (Marker)lexer.Position.Clone(); ReadNextToken(); } if (lastToken == Token.EndOfFile || CallStack.Count == 0) { Exit = true; break; } ExecuteNextStatement(); //execute a statement if (debugger.RequestDebugInterrupt) { debugger.StartDebugger(); //used to step next } //expect an EOF or \n at the end of a line if (lastToken != Token.Newline && lastToken != Token.EndOfFile) { //error handling throw new UnexpectedStatementException("a newline or EOF", lastToken.ToString()); } } }