Benutzer-Werkzeuge

Webseiten-Werkzeuge


scriptstack

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
scriptstack [2025/12/15 02:36]
jango
scriptstack [2025/12/30 17:42] (aktuell)
admin [Models]
Zeile 1: Zeile 1:
 +=====Interna=====
 +
 +====Neuen Datentyp hinzufügen====
 +
 +Token.cs -> Neuen Tokentyp erstellen (Decimal)
 +Lexer.cs -> Neuen State hinzufügen (Decimal)
 +Lexer.cs::GetTokens() -> State und Daten erfassen
 +
 +Parser.cs::Literal() -> den Case decimal hinzufügen
 +Parser.cs::Atom() -> den case decimal hinzufügen 
 +
 +Interpreter.cd::Arithmetic() -> decimal auch berechnen
 +
 +Routine::Validate() -> decimal hinzufügen
 +
 =====Manager===== =====Manager=====
  
Zeile 112: Zeile 127:
 <code csharp> <code csharp>
 // define route // define route
-Routine routine = new Routine( +Routine routine = new Routine((Type)null, "Print", (Type)null, "A function to print text");
- (Type)null, "Print", (Type)null, "A function to print text");+
 </code> </code>
  
Zeile 129: Zeile 143:
 listParameterTypes.Add(typeof(ArrayList)); listParameterTypes.Add(typeof(ArrayList));
  
-// define function prototype with many parameters +// define routine with many parameters 
-Routine routine = new Routine( +Routine routine = new Routine((Type)null, "Print", listParameterTypes);
- (Type)null, "Print", listParameterTypes);+
 </code> </code>
  
Zeile 155: Zeile 168:
 public class Program : Host public class Program : Host
 { {
- // class implementation + 
- private Interpreter interpreter; +    private Interpreter interpreter; 
- public Main(script script) + 
- { +    public Main(script script) 
- interpreter = new Interpreter(script); +    
- interpreter.Handler = this; +        interpreter = new Interpreter(script); 
- } +        interpreter.Handler = this; 
- public object Invoke(String functionName, List<object> parameters) +    
- { +  
- if (functionName == "Print"+    public object Invoke(String functionName, List<object> parameters) 
- { +    
- string str = (int)listParameters[0]; +        if (functionName == "Print"
- Console.WriteLine(str); +        
- return; +            string str = (int)parameters[0]; 
- } +            Console.WriteLine(str); 
- return null; +            return; 
- }+        
 +        return null; 
 +    } 
 +     
 +}
 </code> </code>
  
Zeile 184: Zeile 201:
 <code csharp> <code csharp>
 // register global Sine function // register global Sine function
-HostFunctionPrototype hostFunctionPrototype = new HostFunctionPrototype( +Routine routine = new Routine(typeof(float), "Print", typeof(float)); 
- typeof(float), "Sin", typeof(float)); +manager.Register(routineprintHandler); 
-m_scriptManager.RegisterHostFunction(hostFunctionPrototypetrigHandler);+
 // register global Cosine function // register global Cosine function
-HostFunctionPrototype hostFunctionPrototype = new HostFunctionPrototype( +routine = new Routine(typeof(float), "Read", typeof(float)); 
- typeof(float), "Cos", typeof(float)); +manager.Register(routinereadHandler);
-m_scriptManager.RegisterHostFunction(hostFunctionPrototype, trigHandler); +
-// register global Tangent function +
-HostFunctionPrototype hostFunctionPrototype = new HostFunctionPrototype( +
- typeof(float), "Tan", typeof(float)); +
-m_scriptManager.RegisterHostFunction(hostFunctionPrototypetrigHandler);+
 </code> </code>
  
Zeile 212: Zeile 224:
  
 <code csharp>   <code csharp>  
-public class TrigonometryModule +using ScriptStack.Runtime; 
- HostModule +using System; 
-+ 
- // list of functions stored statically for one-off creation +namespace ScriptStack { 
- private static ReadOnlyCollection<hostfunctionprototype /> + 
-s_listHostFunctionPrototypes+    public class ExampleModel 
- // module constructor +     
- public TrigonometryModule() +        private static ReadOnlyCollection < Routine exportedRoutines
- + 
- // if list created, don't do anything else +        public Example() { 
- if (s_listHostFunctionPrototypes != null) return; + 
-  +            if (exportedRoutines != null) 
- // create list of function prototypes +                return; 
- List<hostfunctionprototype /> listHostFunctionPrototypes = + 
- new List<hostfunctionprototype />(); +            var r = new List<Routine>(); 
- HostFunctionPrototype hostFunctionPrototype = null; + 
- // add Sine prototype to list +            r.Add(new Routine(typeof (bool), "std.print", (Type) null, "Ausgabe auf der Konsole erzeugen.")); 
- hostFunctionPrototype =  +            r.Add(new Routine(typeof (int), "std.read", "Einen Tastenanschlag von der Konsole lesen.")); 
- new HostFunctionPrototype(typeof(float), "Sin", typeof(float)); +            r.Add(new Routine(typeof (string), "std.readLine", "Eine Zeile von der Konsole lesen.")); 
- listHostFunctionPrototypes.Add(hostFunctionPrototype); + 
- // add Cosine prototype to list +            exportedRoutines r.AsReadOnly(); 
- hostFunctionPrototype =  + 
- new HostFunctionPrototype(typeof(float), "Cos", typeof(float)); +        
- listHostFunctionPrototypes.Add(hostFunctionPrototype); + 
- // add Tangent prototype to list +        public ReadOnlyCollection < Routine Routines => exportedRoutines
- hostFunctionPrototype =  + 
- new HostFunctionPrototype(typeof(float), "Tan", typeof(float)); +        public object Invoke(string routine, List <object> parameters) { 
- listHostFunctionPrototypes.Add(hostFunctionPrototype); + 
- s_listHostFunctionPrototypes  +            if (routine == "std.print"{ 
- listHostFunctionPrototypes.AsReadOnly(); +                System.Console.Write(parameters[0]); 
- } +                return true; 
- // returns list of available functions +            } 
- public ReadOnlyCollection<hostfunctionprototype /HostFunctionPrototypes + 
- { +            if (routine == "std.read") 
- get { return s_listHostFunctionPrototypes} +                return (intSystem.Console.ReadKey().Key
- + 
- // implements functions +            if (routine == "std.readLine") 
- public object OnHostFunctionCall(String strFunctionName +                return System.Console.ReadLine(); 
- List<object> listParameters) + 
- +            return null; 
- if (strFunctionName == "Sin") +        } 
- // implement Sine +    }
- return (float)Math.Sin((float)listParameters[0]); +
- else if (strFunctionName == "Cos") +
- // implement Cosine +
- return (float)Math.Cos((float)listParameters[0]); +
- else if (strFunctionName == "Tan") +
- // implement Tangent +
- return (float)Math.Tan((float)listParameters[0]); +
- // unknown function (should not happen) +
- throw new ExecutionException( +
- "Unimplemented function '" + strFunctionName + "'."); +
- }+
 } }
 </code> </code>
Zeile 272: Zeile 273:
 <code csharp> <code csharp>
 // create module instance // create module instance
-TrigonometryModule trigonometryModule = new TrigonometryModule();+Model example = new Example();
 // register module // register module
-m_scriptManager.RegisterHostModule(trigonometryModule)+Manager.Register(example)
 </code> </code>
scriptstack.1765762600.txt.gz · Zuletzt geändert: 2025/12/15 02:36 von jango