From c91f9b978191a77d51948c46b4a24280c33a32ac Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Fri, 10 Mar 2023 04:12:36 -0600 Subject: [PATCH] AST pretty much complete --- tlang/Program.cs | 12 +- tlang/code.tlang | 12 +- tlang/tlang.csproj | 7 +- tlanglib/ClosureNode.cs | 2 + tlanglib/EachLoop.cs | 2 + tlanglib/EnvironmentNode.cs | 2 + tlanglib/FunctionCallNode.cs | 3 + tlanglib/Lexer.cs | 2 + tlanglib/MemberFunctionCallNode.cs | 4 + tlanglib/MemberGetValueNode.cs | 2 + tlanglib/Parser.cs | 224 ++++++++++++++++++++++++++++- tlanglib/Program.cs | 6 +- tlanglib/ScopeEnvironment.cs | 1 + tlanglib/ScopeNode.cs | 2 + tlanglib/TArray.cs | 2 + tlanglib/TDictionary.cs | 2 + tlanglib/TMethod.cs | 2 + tlanglib/tlanglib.csproj | 4 +- 18 files changed, 281 insertions(+), 10 deletions(-) diff --git a/tlang/Program.cs b/tlang/Program.cs index d38f663..6086947 100644 --- a/tlang/Program.cs +++ b/tlang/Program.cs @@ -1,4 +1,12 @@ using tlang; +using System.Collections.Generic; +using System; +using System.IO; +public class Program +{ +public static void Main(string[] args) +{ + List tokens; using(var sr = new StreamReader(ApplicationRunner.GetLauncherScript())) @@ -6,4 +14,6 @@ using(var sr = new StreamReader(ApplicationRunner.GetLauncherScript())) var lexer=new Lexer(sr); tokens=lexer.Tokens; } -Environment.Exit(ApplicationRunner.Run(tokens,args)); \ No newline at end of file +Environment.Exit(ApplicationRunner.Run(tokens,args)); +} +} diff --git a/tlang/code.tlang b/tlang/code.tlang index 6c663ec..a38485d 100644 --- a/tlang/code.tlang +++ b/tlang/code.tlang @@ -1 +1,11 @@ -console.writeln(42); + +ls = create.array(); + +each(v : "GET /api/AddItem/https://www.youtube.com/watch?v=U1jjngDGd_Y HTTP/1.1\r\nHost: 192.168.0.112:3252\r\n\r\n") +{ + ls.add(v); +} +netstrm=net.tcpclient("192.168.0.112",3252); +netstrm.write(ls,ls.length); +netstrm.close(); + diff --git a/tlang/tlang.csproj b/tlang/tlang.csproj index 7144fcf..3b3d8c4 100644 --- a/tlang/tlang.csproj +++ b/tlang/tlang.csproj @@ -5,11 +5,14 @@ + + + + Exe net7.0 - enable - enable + diff --git a/tlanglib/ClosureNode.cs b/tlanglib/ClosureNode.cs index 2736870..1e9221a 100644 --- a/tlanglib/ClosureNode.cs +++ b/tlanglib/ClosureNode.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace tlang { public class ClosureNode : Node diff --git a/tlanglib/EachLoop.cs b/tlanglib/EachLoop.cs index 5072d5a..0a6e639 100644 --- a/tlanglib/EachLoop.cs +++ b/tlanglib/EachLoop.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace tlang { public class EachLoop : Node diff --git a/tlanglib/EnvironmentNode.cs b/tlanglib/EnvironmentNode.cs index 3188325..b89b54a 100644 --- a/tlanglib/EnvironmentNode.cs +++ b/tlanglib/EnvironmentNode.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace tlang { internal class EnvironmentNode : Node diff --git a/tlanglib/FunctionCallNode.cs b/tlanglib/FunctionCallNode.cs index 10038ea..0309ce9 100644 --- a/tlanglib/FunctionCallNode.cs +++ b/tlanglib/FunctionCallNode.cs @@ -1,3 +1,6 @@ +using System.Collections.Generic; +using System.Linq; + namespace tlang { internal class FunctionCallNode : Node diff --git a/tlanglib/Lexer.cs b/tlanglib/Lexer.cs index 703b368..06063fa 100644 --- a/tlanglib/Lexer.cs +++ b/tlanglib/Lexer.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using System.IO; using System.Text; namespace tlang diff --git a/tlanglib/MemberFunctionCallNode.cs b/tlanglib/MemberFunctionCallNode.cs index e24aafe..7d24cce 100644 --- a/tlanglib/MemberFunctionCallNode.cs +++ b/tlanglib/MemberFunctionCallNode.cs @@ -1,3 +1,7 @@ +using System; +using System.Collections.Generic; +using System.Linq; + namespace tlang { internal class MemberFunctionCallNode : FunctionCallNode diff --git a/tlanglib/MemberGetValueNode.cs b/tlanglib/MemberGetValueNode.cs index 097b206..bfde1c5 100644 --- a/tlanglib/MemberGetValueNode.cs +++ b/tlanglib/MemberGetValueNode.cs @@ -1,3 +1,5 @@ +using System; + namespace tlang { public class MemberGetVariableValue : GetVariableValue diff --git a/tlanglib/Parser.cs b/tlanglib/Parser.cs index 61d7e7d..4a7a230 100644 --- a/tlanglib/Parser.cs +++ b/tlanglib/Parser.cs @@ -1,3 +1,10 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Sockets; +using System.Threading; + namespace tlang { internal class Parser @@ -45,7 +52,7 @@ namespace tlang } private Node ParseAssignable(List tokens,ref int i) { - Node myExpression = ParseSum(tokens,ref i); + Node myExpression = ParseLOR(tokens,ref i); while(i tokens,ref int i) + { + Node myExpression = ParseLAnd(tokens,ref i); + while(i tokens,ref int i) + { + Node myExpression = ParseBOr(tokens,ref i); + while(i tokens,ref int i) + { + Node myExpression = ParseXOr(tokens,ref i); + while(i tokens,ref int i) + { + Node myExpression = ParseBAnd(tokens,ref i); + while(i tokens,ref int i) + { + Node myExpression = ParseEq(tokens,ref i); + while(i tokens,ref int i) + { + Node myExpression = ParseRo(tokens,ref i); + while(i=" || tokens[i].Text == "<" || tokens[i].Text == ">")) + { + + if(i=") + { + i++; + myExpression = new GreaterThanEqualsNode(myExpression,ParseShift(tokens,ref i)); + } + if(i") + { + i++; + myExpression = new GreaterThanNode(myExpression,ParseShift(tokens,ref i)); + } + + + } + return myExpression; + } + + private Node ParseShift(List tokens,ref int i) + { + Node myExpression = ParseSum(tokens,ref i); + while(i>")) + { + + if(i>") + { + i++; + myExpression = new RightShiftNode(myExpression,ParseSum(tokens,ref i)); + } + + + } + return myExpression; + } + + private Node ParseSum(List tokens,ref int i) { Node myExpression = ParseFactor(tokens,ref i); @@ -842,7 +1005,7 @@ namespace tlang }); - env["reflection"] = reflection; + env["reflection"] = reflection; var con = new TDictionary(); con["write"] = new TExternalMethod((args2)=>{ foreach(var arg in args2) @@ -869,6 +1032,34 @@ namespace tlang instance["dict"] = new TExternalMethod((args2)=>{ return new TDictionary(); }); + instance["mutex"] = new TExternalMethod((args2)=>{ + TDictionary dictionary=new TDictionary(); + Mutex mtx = new Mutex(); + dictionary["lock"]=new TExternalMethod((args3)=>{ + mtx.WaitOne(); + return TObject.Uninit; + }); + dictionary["unlock"] = new TExternalMethod((args3)=>{ + mtx.ReleaseMutex(); + return TObject.Uninit; + }); + return dictionary; + }); + instance["thread"] = new TExternalMethod((args2)=>{ + if(args2.Length > 0) + { + ICallable callable = args2[0] as ICallable; + + if(callable !=null){ + Thread thread=new Thread(()=>{ + callable.Call(); + }); + thread.Start(); + } + + } + return TObject.Uninit; + }); env["create"] =instance; env["console"]=con; env["int"] = new TExternalMethod((args2)=>{ @@ -894,6 +1085,33 @@ namespace tlang } return TObject.Null; }); + TDictionary net = new TDictionary(); + net["tcpclient"] = new TExternalMethod((args2)=>{ + if(args2.Length > 1) + { + var ipOrFQDN = args2[0] as TString; + var port = args2[1] as TNumber; + if(ipOrFQDN!= null && port != null) + { + var c = new TcpClient(ipOrFQDN.Value,(int)port.Value); + + return CreateStream(c.GetStream()); + } + } + return TObject.Uninit; + }); + net["sslclient"] = new TExternalMethod((args2)=>{ + + return TObject.Uninit; + }); + + net["tcpserver"] = new TExternalMethod((args2)=>{ + + return TObject.Uninit; + }); + + env["net"] =net; + } diff --git a/tlanglib/Program.cs b/tlanglib/Program.cs index 869438b..1cd7236 100644 --- a/tlanglib/Program.cs +++ b/tlanglib/Program.cs @@ -1,4 +1,7 @@ -namespace tlang +using System.Collections.Generic; +using System.IO; + +namespace tlang { public class ApplicationRunner { @@ -9,6 +12,7 @@ public class ApplicationRunner { return File.OpenRead(fileName); } + return typeof(ApplicationRunner).Assembly.GetManifestResourceStream("tlanglib.launcher.launcher.tlang"); } diff --git a/tlanglib/ScopeEnvironment.cs b/tlanglib/ScopeEnvironment.cs index 6901590..53608d8 100644 --- a/tlanglib/ScopeEnvironment.cs +++ b/tlanglib/ScopeEnvironment.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; namespace tlang diff --git a/tlanglib/ScopeNode.cs b/tlanglib/ScopeNode.cs index 064d2f3..6daf5b7 100644 --- a/tlanglib/ScopeNode.cs +++ b/tlanglib/ScopeNode.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace tlang { public class ScopeNode : Node diff --git a/tlanglib/TArray.cs b/tlanglib/TArray.cs index b44ec9c..2450037 100644 --- a/tlanglib/TArray.cs +++ b/tlanglib/TArray.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace tlang { public class TArray : TObject diff --git a/tlanglib/TDictionary.cs b/tlanglib/TDictionary.cs index fbb1449..e244bd1 100644 --- a/tlanglib/TDictionary.cs +++ b/tlanglib/TDictionary.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace tlang { public class TRootDict : TDictionary diff --git a/tlanglib/TMethod.cs b/tlanglib/TMethod.cs index 0cdc251..baeb935 100644 --- a/tlanglib/TMethod.cs +++ b/tlanglib/TMethod.cs @@ -1,3 +1,5 @@ +using System; + namespace tlang { public class TInternalMethod : TObject, ICallable diff --git a/tlanglib/tlanglib.csproj b/tlanglib/tlanglib.csproj index 13785cd..2c95dfd 100644 --- a/tlanglib/tlanglib.csproj +++ b/tlanglib/tlanglib.csproj @@ -3,13 +3,13 @@ netstandard2.0 - enable - 10.0 + true +