AST pretty much complete

This commit is contained in:
Mike Nolan 2023-03-10 04:12:36 -06:00
parent 1f5f0ce0d4
commit c91f9b9781
18 changed files with 281 additions and 10 deletions

View File

@ -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<LexToken> tokens;
using(var sr = new StreamReader(ApplicationRunner.GetLauncherScript()))
@ -7,3 +15,5 @@ using(var sr = new StreamReader(ApplicationRunner.GetLauncherScript()))
tokens=lexer.Tokens;
}
Environment.Exit(ApplicationRunner.Run(tokens,args));
}
}

View File

@ -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();

View File

@ -5,11 +5,14 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="IL2C.Build" Version="0.4.113" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace tlang
{
public class ClosureNode : Node

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace tlang
{
public class EachLoop : Node

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace tlang
{
internal class EnvironmentNode : Node

View File

@ -1,3 +1,6 @@
using System.Collections.Generic;
using System.Linq;
namespace tlang
{
internal class FunctionCallNode : Node

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace tlang

View File

@ -1,3 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace tlang
{
internal class MemberFunctionCallNode : FunctionCallNode

View File

@ -1,3 +1,5 @@
using System;
namespace tlang
{
public class MemberGetVariableValue : GetVariableValue

View File

@ -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<LexToken> tokens,ref int i)
{
Node myExpression = ParseSum(tokens,ref i);
Node myExpression = ParseLOR(tokens,ref i);
while(i<tokens.Count && (tokens[i].Text == "="))
{
if(i<tokens.Count && tokens[i].Text == "=")
@ -54,7 +61,7 @@ namespace tlang
var gvar = myExpression as GetVariableValue;
if(gvar != null)
{
myExpression= new SetVariableNode(gvar,ParseSum(tokens,ref i));
myExpression= new SetVariableNode(gvar,ParseLOR(tokens,ref i));
}
}
@ -62,6 +69,162 @@ namespace tlang
}
return myExpression;
}
private Node ParseLOR(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseLAnd(tokens,ref i);
while(i<tokens.Count && tokens[i].Text == "||")
{
i++;
myExpression = new LogicalOrNode(myExpression,ParseLAnd(tokens,ref i));
}
return myExpression;
}
private Node ParseLAnd(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseBOr(tokens,ref i);
while(i<tokens.Count && tokens[i].Text == "&&")
{
i++;
myExpression = new LogicalAndNode(myExpression,ParseBOr(tokens,ref i));
}
return myExpression;
}
private Node ParseBOr(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseXOr(tokens,ref i);
while(i<tokens.Count && tokens[i].Text == "|")
{
i++;
myExpression = new BitwiseOrNode(myExpression,ParseXOr(tokens,ref i));
}
return myExpression;
}
private Node ParseXOr(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseBAnd(tokens,ref i);
while(i<tokens.Count && tokens[i].Text == "^")
{
i++;
myExpression = new XOrNode(myExpression,ParseBAnd(tokens,ref i));
}
return myExpression;
}
private Node ParseBAnd(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseEq(tokens,ref i);
while(i<tokens.Count && tokens[i].Text == "&")
{
i++;
myExpression = new BitwiseAndNode(myExpression,ParseEq(tokens,ref i));
}
return myExpression;
}
private Node ParseEq(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseRo(tokens,ref i);
while(i<tokens.Count && (tokens[i].Text == "!=" || tokens[i].Text == "=="))
{
if(i<tokens.Count && tokens[i].Text == "!="){
i++;
myExpression = new NotEqualsNode(myExpression,ParseRo(tokens,ref i));
}
if(i<tokens.Count && tokens[i].Text == "==")
{
i++;
myExpression = new EqualsNode(myExpression,ParseRo(tokens,ref i));
}
}
return myExpression;
}
private Node ParseRo(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseShift(tokens,ref i);
while(i<tokens.Count && (tokens[i].Text == "<=" || tokens[i].Text == ">=" || tokens[i].Text == "<" || tokens[i].Text == ">"))
{
if(i<tokens.Count && tokens[i].Text == "<="){
i++;
myExpression = new LessThanEqualsNode(myExpression,ParseShift(tokens,ref i));
}
if(i<tokens.Count && tokens[i].Text == ">=")
{
i++;
myExpression = new GreaterThanEqualsNode(myExpression,ParseShift(tokens,ref i));
}
if(i<tokens.Count && tokens[i].Text == "<"){
i++;
myExpression = new LessThanNode(myExpression,ParseShift(tokens,ref i));
}
if(i<tokens.Count && tokens[i].Text == ">")
{
i++;
myExpression = new GreaterThanNode(myExpression,ParseShift(tokens,ref i));
}
}
return myExpression;
}
private Node ParseShift(List<LexToken> tokens,ref int i)
{
Node myExpression = ParseSum(tokens,ref i);
while(i<tokens.Count && (tokens[i].Text == "<<" || tokens[i].Text == ">>"))
{
if(i<tokens.Count && tokens[i].Text == "<<"){
i++;
myExpression = new LeftShiftNode(myExpression,ParseSum(tokens,ref i));
}
if(i<tokens.Count && tokens[i].Text == ">>")
{
i++;
myExpression = new RightShiftNode(myExpression,ParseSum(tokens,ref i));
}
}
return myExpression;
}
private Node ParseSum(List<LexToken> 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;
}

View File

@ -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");
}

View File

@ -1,4 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace tlang

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace tlang
{
public class ScopeNode : Node

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace tlang
{
public class TArray : TObject

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace tlang
{
public class TRootDict : TDictionary

View File

@ -1,3 +1,5 @@
using System;
namespace tlang
{
public class TInternalMethod : TObject, ICallable

View File

@ -3,13 +3,13 @@
<PropertyGroup>
<!--<OutputType>Exe</OutputType>-->
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>10.0</LangVersion>
<Packable>true</Packable>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="launcher\launcher.tlang" />
</ItemGroup>
</Project>