Fixed minor bugs and made the library thread safe

This commit is contained in:
Ryan 2017-08-26 11:25:44 -04:00
parent 433ec4eb81
commit 2c849eb01b
24 changed files with 76114 additions and 158 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.flac

12
ReadMe.md Normal file
View File

@ -0,0 +1,12 @@
ParseManagerCS Version!
TODO:
- [ ] Allow the use of functions in arguments (Tough)
- [ ] Allow the use of statements in conditionals: `if num+5>=GETAGE()-1 then STOP(song)|SKIP(0)` (Tough)
- [ ] Add other cool built in things (Fun)
- [ ] Add object support (Tough)
- [ ] Improve audio support (Simple)
- [ ] Add simple threading (Alright)
- [ ] Fix Bugs! (Death)
Maybe:
- [ ] Add While/for loops (With labels this can easily be done. So it isn't really needed, I may add it in the future though!)

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<EmbedderSignAssembly Condition="$(EmbedderSignAssembly) == '' Or $(EmbedderSignAssembly) == '*Undefined*'">$(SignAssembly)</EmbedderSignAssembly>
<IntermediateDir>$(ProjectDir)$(IntermediateOutputPath)</IntermediateDir>
<EmbedderPath Condition="$(EmbedderPath) == '' Or $(EmbedderPath) == '*Undefined*'">$(MSBuildThisFileDirectory)..\</EmbedderPath>
</PropertyGroup>
<UsingTask TaskName="ResourceEmbedder.MsBuild.SatelliteAssemblyEmbedderTask" AssemblyFile="$(EmbedderPath)ResourceEmbedder.MsBuild.dll" />
<UsingTask TaskName="ResourceEmbedder.MsBuild.SatelliteAssemblyCleanupTask" AssemblyFile="$(EmbedderPath)ResourceEmbedder.MsBuild.dll" />
<!-- We want to run as soon as the satellite assemblies are generated -->
<Target AfterTargets="GenerateSatelliteAssemblies" Name="EmbedderTarget" DependsOnTargets="$(EmbedderDependsOnTargets)">
<ResourceEmbedder.MsBuild.SatelliteAssemblyEmbedderTask AssemblyPath="@(IntermediateAssembly)" ProjectDirectory="$(ProjectDir)" TargetPath="$(TargetPath)" SignAssembly="$(EmbedderSignAssembly)" References="@(ReferencePath)" DebugSymbols="$(DebugSymbols)" DebugType="$(DebugType)" />
</Target>
<!--Cleanup after generating -->
<Target AfterTargets="AfterBuild" Name="CleanupTarget" DependsOnTargets="$(EmbedderDependsOnTargets)">
<ResourceEmbedder.MsBuild.SatelliteAssemblyCleanupTask AssemblyPath="@(IntermediateAssembly)" ProjectDirectory="$(ProjectDir)" TargetPath="$(TargetPath)" SignAssembly="$(EmbedderSignAssembly)" />
</Target>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\parseManager\packages.config" />
</repositories>

View File

@ -7,42 +7,82 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers. * To change this template use Tools | Options | Coding | Edit Standard Headers.
*/ */
using System; using System;
using parseManager; // IMPORTANT using System.Threading;
using CSCore;
using CSCore.Codecs;
using CSCore.SoundOut;
using parseManagerCS;
public class define : standardDefine // If you want the standard methods you must include this, Also this class cannot be static! public class define : standardDefine // If you want the standard methods you must include this, Also this class cannot be static!
{ {
public void testM(object arg1,object arg2) double count;
ISoundOut GetSoundOut()
{ {
Console.WriteLine(arg1+"\t"+arg2); if (WasapiOut.IsSupportedOnCurrentPlatform)
return new WasapiOut();
else
return new DirectSoundOut();
} }
public void testM2(string arg1) IWaveSource GetSoundSource(string path)
{ {
Console.WriteLine(arg1 + " it works!!!"); return CodecFactory.Instance.GetCodec(path);
} }
public void TEST() public void _play()
{ {
var test=GLOBALS.GetPM(); string path = (string)GLOBALS.GetData("__MUSIC");
var env=test.GetENV(); double id = (double)GLOBALS.GetData("__MUSICH");
Console.WriteLine(env["test"]); using (IWaveSource soundSource = GetSoundSource(path)) {
using (ISoundOut soundOut = GetSoundOut()) {
soundOut.Initialize(soundSource);
GLOBALS.AddData("__MUSICH" + id, soundOut);
soundOut.Play();
soundOut.WaitForStopped();
} }
public void TEST2(object msg) }
}
public void STOP(parseManager PM, double id)
{ {
Console.WriteLine(msg); var sound = (ISoundOut)GLOBALS.GetData("__MUSICH" + id);
sound.Stop();
} }
public void TEST3(double msg, string msg2) public void RESUME(parseManager PM, double id)
{ {
Console.WriteLine(msg + "|" + msg2); var sound = (ISoundOut)GLOBALS.GetData("__MUSICH" + id);
sound.Resume();
} }
public double TEST4(double num){ public void SETV(parseManager PM, double id, double vol)
return num+1; {
var sound = (ISoundOut)GLOBALS.GetData("__MUSICH" + id);
sound.Volume = (float)vol;
}
public void PAUSE(parseManager PM, double id)
{
var sound = (ISoundOut)GLOBALS.GetData("__MUSICH" + id);
sound.Pause();
}
public double PLAY(parseManager PM, string filepath)
{
GLOBALS.AddData("__MUSIC", filepath);
GLOBALS.AddData("__MUSICH", count++);
var oThread = new Thread(new ThreadStart(_play));
oThread.Start();
return count - 1;
} }
} }
namespace parseManager namespace parseManagerCS
{ {
class Program class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
parseManager test = new parseManager("parsetest2.txt","define"); // define is where your methods will be held if (args.Length == 0) {
Console.Write("Please Include a file path!");
Console.ReadLine();
Environment.Exit(0);
}
parseManager test = new parseManager(args[0], "define"); // define is where your methods will be held
//parseManager test = new parseManager("parsetest2.txt","define");
nextType next = test.Next(); // TODO implement the next method nextType next = test.Next(); // TODO implement the next method
string type; string type;
while (next.GetCMDType() != "EOF") { while (next.GetCMDType() != "EOF") {
@ -53,8 +93,6 @@ namespace parseManager
} }
next = test.Next(); next = test.Next();
} }
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +1,13 @@
[TEST]{ ENTRY START
"Jump was successful!"
--GOTO("HERE")
}
[START]{ [START]{
"Test 1:" "Hello"
-- t=15 song=PLAY("test.flac")
-- test=2*100 print("Hello!")
-- test2=[1,2,3,4,"HI"] "Don't hit enter!"
-- test2[5]="HELLO" "Am I still going?"
-- "test2 = $test2$" PAUSE(song)
-- "test = $test$" "I'm alive!"
-- c=5 "Lets resume"
-- ::HERE:: RESUME(song)
-- a,b="sdf",true ":)"
-- "a,b,c = $a$ $b$ $c$"
-- food="yum"
-- test=true
-- stop=21
-- "food = $food$"
-- "test = $test$"
-- "stop = $stop$"
-- "Test 2:"
-- "test2[1] = $test2[1]$"
-- testM(2+2,"Test")
-- testM(2+2,test2[5])
-- count=0
-- ::loop::
-- "Count = $count$"
-- count=count+1
-- if count>10 then GOTO("end")|GOTO("loop")
-- ::end::
-- "Done!"
--JUMP("CallMe")
env=CreateENV()
msg="Hi"
SetENV(env)
"BEFORE_CHANGE: $msg$"
msg=21+7
"IN_HERE $msg$"
env=GetDefualtENV()
SetENV(env)
"OUT_HERE $msg$"
test=CallMe("This","is a test!")
"FENV: $test$"
"Did it work!"
"HMMM"
test=CallMe("This","is a test too!")
"FENV: $test$"
EXIT()
} }
[CallMe:function(args1,args2)]{
"function was called!"
"CALL_TEST: $args1$ $args2$"
}
-- (count==stop and name=="bob") ? GOTO(end) : GOTO(loop)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
ILRepack.exe /target:exe /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.x" /out:MergedFile.exe parsemanagertester.exe cscore.dll

View File

@ -0,0 +1,6 @@
<?xml version="1.0" standalone="yes"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" standalone="yes"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>

View File

@ -0,0 +1,50 @@
ENTRY TESTSTART
[TESTSTART]{
"Hello (Press Enter)"
print("PLAY SONG (1)")
print("MESSAGE (2)")
print("An Adventure (3)")
print("QUIT (4)")
::choice::
write("Choose: ")
choice=GetInput()
if choice=="1" then JUMP("SONG")|SKIP(0)
if choice=="2" then JUMP("YO")|SKIP(0)
if choice=="4" then QUIT()|SKIP(0)
if choice=="3" then SKIP(2)|SKIP(0)
GOTO("choice")
"We are here now! Time for some fun..."
write("Please enter your name: ")
name=GetInput()
if name=="" then SKIP(-3)|SKIP(0)
print("So your name is $name$ huh...")
"I won't judge haha"
"Anyway let's get controls for that song"
print("Stop (s)")
print("Play (t)")
print("Pause (a)")
print("Resume (r)")
print("Quit (q)")
::control::
write("Choose: ")
choice=GetInput()
if choice=="s" then STOP(song)|SKIP(0)
if choice=="t" then JUMP("PLAYS")|SKIP(0)
if choice=="a" then PAUSE(song)|SKIP(0)
if choice=="r" then RESUME(song)|SKIP(0)
if choice=="q" then QUIT()|SKIP(0)
GOTO("control")
}
[PLAYS]{
PAUSE(song)
song=PLAY("test.flac")
GOTO("control")
}
[SONG]{
song=PLAY("test.flac")
GOTO("choice")
}
[YO]{
"How are you doing?"
GOTO("choice")
}

View File

@ -0,0 +1,36 @@
ENABLE leaking
[START]{
loaded = LOAD()
if loaded==true then print("Loaded!")|print("No save file found!")
write("Hello! Please enter your name: ")
name=GetInput()
if name=="" then SKIP(-3)|SKIP(0)
print("So your name is $name$ Cool!")
}
[Test]{
SAVE()
"In here now"
Choice("Choose: ")
}
[Test2]{
SAVE()
"Over here lol"
Choice("Choose: ")
}
[Tired]{
SAVE()
"Done now!"
Choice("Choose: ")
"We are done!"
}
[Choice:function(msg)]{
print("Keep Playing (k)")
print("Quit (q)")
::control::
write(msg)
choice=GetInput()
if choice=="k" then GOTO("end")|SKIP(0)
if choice=="q" then QUIT()|SKIP(0)
GOTO("control")
::end::
}

View File

@ -0,0 +1,4 @@
[START]{
print("Testing")
"Done!"
}

View File

@ -4,3 +4,5 @@ C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Debu
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Debug\parseManagerTester.pdb C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Debug\parseManagerTester.pdb
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\obj\Debug\parseManagerTester.exe C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\obj\Debug\parseManagerTester.exe
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\obj\Debug\parseManagerTester.pdb C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\obj\Debug\parseManagerTester.pdb
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Debug\CSCore.dll
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Debug\CSCore.xml

View File

@ -0,0 +1,6 @@
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Release\parseManagerTester.exe.config
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Release\parseManagerTester.exe
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Release\CSCore.dll
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\bin\Release\CSCore.xml
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\obj\Release\parseManagerTester.csprojResolveAssemblyReference.cache
C:\Users\Ryan\Documents\SharpDevelop Projects\parseManager\parseManager\obj\Release\parseManagerTester.exe

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="CSCore" version="1.2.1.1" targetFramework="net40" />
<package id="MediaToolkit" version="1.1.0.1" targetFramework="net40" /> <package id="MediaToolkit" version="1.1.0.1" targetFramework="net40" />
<package id="Resource.Embedder" version="1.2.4" targetFramework="net40" developmentDependency="true" />
</packages> </packages>

View File

@ -4,13 +4,13 @@
* Time: 11:54 AM * Time: 11:54 AM
*/ */
using System; using System;
using System.Collections;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Reflection; using System.Reflection;
using parseManager; using parseManagerCS;
namespace parseManager using System.Threading;
namespace parseManagerCS
{ {
/// The parseManager is an Advance Config Script /// The parseManager is an Advance Config Script
/// It allows the user to run code while also definine variables /// It allows the user to run code while also definine variables
@ -28,12 +28,16 @@ namespace parseManager
object _defineClassObject; object _defineClassObject;
chunk _currentChunk; chunk _currentChunk;
chunk _lastChunk = null; chunk _lastChunk = null;
readonly ENV _mainENV = new ENV(); ENV _mainENV = new ENV();
public ENV _defualtENV; public ENV _defualtENV;
Stack<ENV> _fStack = new Stack<ENV>(); Stack<ENV> _fStack = new Stack<ENV>();
Dictionary<string, bool> _flags = new Dictionary<string, bool>(); Dictionary<string, bool> _flags = new Dictionary<string, bool>();
Dictionary<string, chunk> _chunks = new Dictionary<string, chunk>(); Dictionary<string, chunk> _chunks = new Dictionary<string, chunk>();
Dictionary<string, string> _methods = new Dictionary<string, string>(); Dictionary<string, string> _methods = new Dictionary<string, string>();
public void _SetDENV(ENV env)
{
_mainENV = env;
}
public parseManager(string filepath) public parseManager(string filepath)
{ {
InitFlags(); InitFlags();
@ -74,7 +78,7 @@ namespace parseManager
} }
return false; return false;
} }
void debug(object msg) public void debug(object msg)
{ {
if (_flags["debugging"]) if (_flags["debugging"])
Console.WriteLine("DEBUGGING: " + msg); Console.WriteLine("DEBUGGING: " + msg);
@ -90,6 +94,9 @@ namespace parseManager
foreach (Match m in Regex.Matches(data, @"ENTRY ([a-zA-Z0-9_\./]+)")) { foreach (Match m in Regex.Matches(data, @"ENTRY ([a-zA-Z0-9_\./]+)")) {
_entry = m.Groups[1].ToString(); _entry = m.Groups[1].ToString();
} }
// foreach (Match m in Regex.Matches(data, @"USING ([a-zA-Z0-9_\./]+)")) {
// m.Groups[1].ToString();
// }
var match = Regex.Matches(data, @"\[(.+)\][\r\n]*?\{([^\0]+?)\}"); var match = Regex.Matches(data, @"\[(.+)\][\r\n]*?\{([^\0]+?)\}");
var count = 0; var count = 0;
foreach (Match m in match) { foreach (Match m in match) {
@ -154,10 +161,13 @@ namespace parseManager
public bool isRegisteredFunction(string method, out chunk o) public bool isRegisteredFunction(string method, out chunk o)
{ {
if (_chunks.TryGetValue(method, out o)) { if (_chunks.TryGetValue(method, out o)) {
if (o.isFunction()) {
return true; return true;
} }
return false; return false;
} }
return false;
}
public object InvokeI(string method, object[] argsV, chunk c) public object InvokeI(string method, object[] argsV, chunk c)
{ {
var ccP = _currentChunk.GetPos(); var ccP = _currentChunk.GetPos();
@ -177,7 +187,7 @@ namespace parseManager
PushError("Stack Overflow!"); PushError("Stack Overflow!");
} }
_defualtENV = fEnv; _defualtENV = fEnv;
def.JUMP(method); def.JUMP(this,method);
return fEnv; // TODO Handle returns return fEnv; // TODO Handle returns
} }
public object InvokeR(string method, object[] args) public object InvokeR(string method, object[] args)
@ -188,7 +198,7 @@ namespace parseManager
} }
try { try {
_defineMethod = _defineType.GetMethod(method); _defineMethod = _defineType.GetMethod(method);
return _defineMethod.Invoke(_defineClassObject, args); return _defineMethod.Invoke(_defineClassObject, tackBArgs(this, args));
} catch { } catch {
PushError("Invalid method: " + method); PushError("Invalid method: " + method);
return null; return null;
@ -200,17 +210,25 @@ namespace parseManager
if (isRegisteredFunction(method, out c)) { if (isRegisteredFunction(method, out c)) {
InvokeI(method, args, c); InvokeI(method, args, c);
return 0; return 0;
} else { }
try { try {
_defineMethod = _defineType.GetMethod(method); _defineMethod = _defineType.GetMethod(method);
_defineMethod.Invoke(_defineClassObject, args); _defineMethod.Invoke(_defineClassObject, tackBArgs(this, args));
return 0; return 0;
} catch { } catch {
PushError("Invalid method: " + method); PushError("Invalid method: " + method);
} }
}
return -1; return -1;
} }
public object[] tackBArgs(object o,object[] args){
var len = args.Length;
var newargs=new object[len+1];
for(int i = 0;i<len;i++){
newargs[i+1]=args[i];
}
newargs[0]=o;
return newargs;
}
public void SetBlock(string BLOCK) public void SetBlock(string BLOCK)
{ {
chunk cchunk; chunk cchunk;
@ -253,8 +271,9 @@ namespace parseManager
} }
public void PushError(string err) public void PushError(string err)
{ {
Console.WriteLine(err); Console.WriteLine(err + "\nPress Enter!");
def.EXIT(); Console.ReadLine();
def.EXIT(this);
} }
public nextType Next(string BLOCK) public nextType Next(string BLOCK)
{ {
@ -284,6 +303,11 @@ namespace parseManager
tempReturn.SetText("Reached the end of the file!"); tempReturn.SetText("Reached the end of the file!");
return tempReturn; return tempReturn;
} }
if (!_active) {
tempReturn.SetCMDType("EOF");
tempReturn.SetText("Reached the end of the file!");
return tempReturn;
}
var type = cCMD.GetCMDType(); var type = cCMD.GetCMDType();
stuff = cCMD.GetArgs(); stuff = cCMD.GetArgs();
if (type == "LOGIC") {//{conds,andors,_funcif,_resultif,_funcelse,_resultelse} if (type == "LOGIC") {//{conds,andors,_funcif,_resultif,_funcelse,_resultelse}
@ -319,10 +343,8 @@ namespace parseManager
} }
var truth = truths[0]; var truth = truths[0];
if (truths.Length == 1 && truth) { if (truths.Length == 1 && truth) {
//Console.WriteLine(funcif+"|"+ResolveVar(argsif)[0]);
InvokeNR(funcif, ResolveVar(argsif)); InvokeNR(funcif, ResolveVar(argsif));
} else if (truths.Length == 1) { } else if (truths.Length == 1) {
//Console.WriteLine(funcelse + "|"+ResolveVar(argselse)[0]);
InvokeNR(funcelse, ResolveVar(argselse)); InvokeNR(funcelse, ResolveVar(argselse));
} else { } else {
for (int i = 1; i < andors.Length; i++) { for (int i = 1; i < andors.Length; i++) {
@ -335,10 +357,8 @@ namespace parseManager
} }
} }
if (truth) { if (truth) {
//Console.WriteLine(funcif);
InvokeNR(funcif, ResolveVar(argsif)); InvokeNR(funcif, ResolveVar(argsif));
} else { } else {
//Console.WriteLine("|" + funcelse + "|");
InvokeNR(funcelse, ResolveVar(argselse)); InvokeNR(funcelse, ResolveVar(argselse));
} }
} }
@ -346,18 +366,8 @@ namespace parseManager
tempReturn.SetText("test turned out to be: " + truth); tempReturn.SetText("test turned out to be: " + truth);
return tempReturn; return tempReturn;
} else if (type == "LABEL") { } else if (type == "LABEL") {
cCMD = _currentChunk.GetCLine(); tempReturn.SetCMDType("label");
if (cCMD == null) { tempReturn.SetText("Jumped to a label!");
if (_flags["leaking"] && _active) {
SetBlock(_currentChunk.GetNextChunk());
return Next();
}
tempReturn.SetCMDType("EOF");
tempReturn.SetText("Reached the end of the file!");
return tempReturn;
}
type = cCMD.GetCMDType();
stuff = cCMD.GetArgs();
return tempReturn; return tempReturn;
} }
if (type == "FUNC") { if (type == "FUNC") {
@ -463,6 +473,13 @@ namespace parseManager
ex = evaluater.Evaluate(v[i]); ex = evaluater.Evaluate(v[i]);
else else
ex = double.NaN; ex = double.NaN;
if (v[i].Length == 0 && len == 1) {
return new object[]{ };
}
if (v[i] == "[]") {
args[i] = new ENV();
continue;
}
if (v[i].StartsWith("[")) { if (v[i].StartsWith("[")) {
var result = GLOBALS.Split(v[i].Substring(1, v[i].Length - 2)); // TODO make ENV var result = GLOBALS.Split(v[i].Substring(1, v[i].Length - 2)); // TODO make ENV
var res = ResolveVar(result); var res = ResolveVar(result);
@ -619,10 +636,10 @@ namespace parseManager
var argselse = Regex.Match(tempelse, @"^([a-zA-Z0-9_]+)\s?\((.*)\)"); var argselse = Regex.Match(tempelse, @"^([a-zA-Z0-9_]+)\s?\((.*)\)");
string _funcif = (argsif.Groups[1]).ToString(); string _funcif = (argsif.Groups[1]).ToString();
var _argsif = (argsif.Groups[2]).ToString(); var _argsif = (argsif.Groups[2]).ToString();
string[] _resultif = Regex.Split(_argsif, ",(?=(?:[^\"'\\[\\]]*[\"'\\[\\]][^\"'\\[\\]]*[\"'\\[\\]])*[^\"'\\[\\]]*$)"); string[] _resultif = GLOBALS.Split(_argsif);
string _funcelse = (argselse.Groups[1]).ToString(); string _funcelse = (argselse.Groups[1]).ToString();
var _argselse = (argselse.Groups[2]).ToString(); var _argselse = (argselse.Groups[2]).ToString();
string[] _resultelse = Regex.Split(_argselse, ",(?=(?:[^\"'\\[\\]]*[\"'\\[\\]][^\"'\\[\\]]*[\"'\\[\\]])*[^\"'\\[\\]]*$)"); string[] _resultelse = GLOBALS.Split(_argselse);
var mm = Regex.Matches(condition, "(.+?)([and ]+?[or ]+)"); var mm = Regex.Matches(condition, "(.+?)([and ]+?[or ]+)");
var conds = new string[(mm.Count + 1) * 3]; var conds = new string[(mm.Count + 1) * 3];
var andors = new string[mm.Count]; var andors = new string[mm.Count];
@ -664,8 +681,8 @@ namespace parseManager
var var1 = (FuncWReturn.Groups[1]).ToString(); var var1 = (FuncWReturn.Groups[1]).ToString();
var func = (FuncWReturn.Groups[2]).ToString(); var func = (FuncWReturn.Groups[2]).ToString();
var args2 = (FuncWReturn.Groups[3]).ToString(); var args2 = (FuncWReturn.Groups[3]).ToString();
var retargs = var1.Split(','); var retargs = GLOBALS.Split(var1);
var result = Regex.Split(args2, ",(?=(?:[^\"'\\[\\]]*[\"'\\[\\]][^\"'\\[\\]]*[\"'\\[\\]])*[^\"'\\[\\]]*$)"); var result = GLOBALS.Split(args2);
_compiledlines.Add(new CMD("FUNC_R", new object[] { _compiledlines.Add(new CMD("FUNC_R", new object[] {
retargs, retargs,
func, func,
@ -674,12 +691,12 @@ namespace parseManager
} else if (FuncWOReturn.ToString() != "") { } else if (FuncWOReturn.ToString() != "") {
var func = (FuncWOReturn.Groups[1]).ToString(); var func = (FuncWOReturn.Groups[1]).ToString();
var args2 = (FuncWOReturn.Groups[2]).ToString(); var args2 = (FuncWOReturn.Groups[2]).ToString();
var result = Regex.Split(args2, ",(?=(?:[^\"'\\[\\]]*[\"'\\[\\]][^\"'\\[\\]]*[\"'\\[\\]])*[^\"'\\[\\]]*$)"); var result = GLOBALS.Split(args2);
_compiledlines.Add(new CMD("FUNC", new object[]{ func, result })); _compiledlines.Add(new CMD("FUNC", new object[]{ func, result }));
} else if (pureLine.ToString() != "") { } else if (pureLine.ToString() != "") {
_compiledlines.Add(new CMD("LINE", new object[]{ pureLine.ToString() })); _compiledlines.Add(new CMD("LINE", new object[]{ pureLine.ToString() }));
} else if (assignment.ToString() != "") { } else if (assignment.ToString() != "") {
var vars = Regex.Split(assignment.Groups[1].ToString(), ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)"); var vars = GLOBALS.Split(assignment.Groups[1].ToString());
var tabTest = assignment.Groups[2].ToString(); var tabTest = assignment.Groups[2].ToString();
string[] vals = GLOBALS.Split(tabTest); string[] vals = GLOBALS.Split(tabTest);
//vals = Regex.Split(assignment.Groups[2].ToString(), ",(?=(?:[^\"'\\[\\]]*[\"'\\[\\]][^\"'\\[\\]]*[\"'\\[\\]])*[^\"'\\[\\]]*$)"); //vals = Regex.Split(assignment.Groups[2].ToString(), ",(?=(?:[^\"'\\[\\]]*[\"'\\[\\]][^\"'\\[\\]]*[\"'\\[\\]])*[^\"'\\[\\]]*$)");
@ -825,6 +842,9 @@ namespace parseManager
public static double Evaluate(string cmd, double v) public static double Evaluate(string cmd, double v)
{ {
double test; double test;
if (cmd.Length == 0) {
return double.NaN;
}
if (double.TryParse(cmd, out test)) { if (double.TryParse(cmd, out test)) {
return test; return test;
} }
@ -871,6 +891,7 @@ namespace parseManager
return v; // TODO grab current ENV and does the calculation return v; // TODO grab current ENV and does the calculation
} }
} }
[Serializable]
public class ENV public class ENV
{ {
ENV _Parent; ENV _Parent;
@ -880,6 +901,16 @@ namespace parseManager
{ {
_Parent = other; _Parent = other;
} }
public object[] GetList()
{
var temp = new object[_varsI.Count];
var count = 0;
foreach (KeyValuePair<int, object> entry in _varsI) {
temp[count] = entry.Value;
count++;
}
return temp;
}
public override string ToString() public override string ToString()
{ {
string str = "("; string str = "(";
@ -1010,6 +1041,20 @@ namespace parseManager
static parseManager _current; static parseManager _current;
static readonly ENV _env = new ENV(); static readonly ENV _env = new ENV();
static List<string> _numvars = new List<string>(); static List<string> _numvars = new List<string>();
public static void WriteToBinaryFile(string filePath, ENV objectToWrite, bool append = false)
{
using (Stream stream = File.Open(filePath, append ? FileMode.Append : FileMode.Create)) {
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryFormatter.Serialize(stream, objectToWrite);
}
}
public static ENV ReadFromBinaryFile(string filePath)
{
using (Stream stream = File.Open(filePath, FileMode.Open)) {
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
return (ENV)binaryFormatter.Deserialize(stream);
}
}
public static object GetData(string ind) public static object GetData(string ind)
{ {
return _env[ind]; return _env[ind];
@ -1095,102 +1140,156 @@ namespace parseManager
} }
public class standardDefine public class standardDefine
{ {
public void TRACEBACK() public void SAVE(parseManager PM)
{ {
var test = GLOBALS.GetPM(); var env = PM.GetDENV();
ENV env = test.Pop(); var c = PM.GetCurrentChunk();
test.SetBlock((string)env[0]); env["__CurrentChunkName"] = c.GetName();
var c = test.GetCurrentChunk(); env["__CurrentChunkPos"] = c.GetPos();
env["__DefualtENV"] = PM.GetENV();
GLOBALS.WriteToBinaryFile("savedata.dat", env);
}
public bool LOAD(parseManager PM)
{
try {
ENV env = GLOBALS.ReadFromBinaryFile("savedata.dat");
var name = (string)env["__CurrentChunkName"];
var pos = (int)env["__CurrentChunkPos"];
var denv = (ENV)env["__DefualtENV"];
PM._SetDENV(env);
PM.SetENV(denv);
PM.SetBlock(name);
PM.GetCurrentChunk().SetPos(pos);
return true;
} catch {
return false;
}
}
public void TRACEBACK(parseManager PM)
{
ENV env = PM.Pop();
PM.SetBlock((string)env[0]);
var c = PM.GetCurrentChunk();
c.SetPos((int)env[1]); c.SetPos((int)env[1]);
SetENV((ENV)env[3]); SetENV(PM,(ENV)env[3]);
} }
public void EXIT() public void EXIT(parseManager PM)
{ {
GLOBALS.GetPM().Deactivate(); PM.Deactivate();
} }
public void QUIT() public void QUIT(parseManager PM)
{ {
Environment.Exit(0); Environment.Exit(0);
} }
public void SetENV(ENV env) public void SetENV(parseManager PM, ENV env)
{ {
var test = GLOBALS.GetPM(); PM.SetENV(env);
test.SetENV(env);
} }
public ENV GetENV() public ENV GetENV(parseManager PM)
{ {
var test = GLOBALS.GetPM(); return PM.GetENV();
return test.GetENV();
} }
public ENV GetDefualtENV() public ENV GetDefualtENV(parseManager PM)
{ {
var test = GLOBALS.GetPM(); return PM.GetDENV();
return test.GetDENV();
} }
public ENV CreateENV() public ENV CreateENV(parseManager PM)
{ {
var temp = new ENV(); var temp = new ENV();
var PM = GLOBALS.GetPM();
temp.SetParent(PM.GetENV()); temp.SetParent(PM.GetENV());
return temp; return temp;
} }
public int GOTO(string label) public string GetInput(parseManager PM)
{ {
var test = GLOBALS.GetPM(); return Console.ReadLine();
var c = test.GetCurrentChunk(); }
public int GOTO(parseManager PM, string label)
{
var c = PM.GetCurrentChunk();
int pos; int pos;
if (c.TryGetLabel(label, out pos)) { if (c.TryGetLabel(label, out pos)) {
c.SetPos(pos); c.SetPos(pos);
return 0; return 0;
} else if (test.GetFlag("forseelabels")) { } else if (PM.GetFlag("forseelabels")) {
var chunks = test.GetChunks(); var chunks = PM.GetChunks();
for (int i = 0; i < chunks.Length; i++) { for (int i = 0; i < chunks.Length; i++) {
if (chunks[i].TryGetLabel(label, out pos)) { if (chunks[i].TryGetLabel(label, out pos)) {
test.SetBlock(chunks[i].GetName()); PM.SetBlock(chunks[i].GetName());
chunks[i].SetPos(pos); chunks[i].SetPos(pos);
return 0; return 0;
} }
} }
} }
test.PushError("Unable to GOTO a non existing label: " + label + "!"); PM.PushError("Unable to GOTO a non existing label: " + label + "!");
return 0; return 0;
} }
public void JUMP(string block) public double LEN(parseManager PM, object o)
{ {
var test = GLOBALS.GetPM(); string type = o.GetType().ToString();
var c = test.GetCurrentChunk(); if (type.Contains("String")) {
c.ResetPos(); return (double)((string)o).Length;
test.SetBlock(block);
} }
public void SKIP(double n) if (type.Contains("ENV")) {
return (double)((ENV)o).GetList().Length;
}
return 0;
}
public void JUMP(parseManager PM, string block)
{ {
var test = GLOBALS.GetPM(); var c = PM.GetCurrentChunk();
var c = test.GetCurrentChunk(); c.ResetPos();
PM.SetBlock(block);
}
public void SKIP(parseManager PM, double n)
{
var c = PM.GetCurrentChunk();
var pos = c.GetPos(); var pos = c.GetPos();
c.SetPos(pos + (int)n); c.SetPos(pos + (int)n);
} }
public double ADD(double a, double b) public double tonumber(parseManager PM, string strn)
{
double d;
if (double.TryParse(strn, out d)) {
return d;
}
PM.debug("Cannot convert to a number!");
return double.NaN;
}
public void SLEEP(parseManager PM, double n)
{
int i = int.Parse(n.ToString()) * 1000;
Thread.Sleep(i);
}
public double ADD(parseManager PM, double a, double b)
{ {
return a + b; return a + b;
} }
public double SUB(double a, double b) public double SUB(parseManager PM, double a, double b)
{ {
return a - b; return a - b;
} }
public double MUL(double a, double b) public double MUL(parseManager PM, double a, double b)
{ {
return a * b; return a * b;
} }
public double DIV(double a, double b) public double DIV(parseManager PM, double a, double b)
{ {
return a / b; return a / b;
} }
public double MOD(double a, double b) public double MOD(parseManager PM, double a, double b)
{ {
return a % b; return a % b;
} }
public double CALC(string ex) public double CALC(parseManager PM, string ex)
{ {
return evaluater.Evaluate(ex); return evaluater.Evaluate(ex);
} }
public void print(parseManager PM, object o)
{
Console.WriteLine(o);
}
public void write(parseManager PM, object o)
{
Console.Write(o);
}
} }

View File

@ -31,6 +31,9 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="CSCore">
<HintPath>..\packages\CSCore.1.2.1.1\lib\net35-client\CSCore.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp"> <Reference Include="Microsoft.CSharp">
<RequiredTargetFramework>4.0</RequiredTargetFramework> <RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference> </Reference>
@ -57,4 +60,5 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Resource.Embedder.1.2.4\build\Resource.Embedder.targets" Condition="Exists('..\packages\Resource.Embedder.1.2.4\build\Resource.Embedder.targets')" />
</Project> </Project>