Added threading support and fixed bugs
Internal functions fixed! now empty args on internal functions will not bug out! Added some new methods
This commit is contained in:
parent
2c849eb01b
commit
70fa89de8c
@ -79,11 +79,8 @@ namespace parseManagerCS
|
||||
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
|
||||
parseManager PM = new parseManager(args[0], "define");
|
||||
nextType next = PM.Next();
|
||||
string type;
|
||||
while (next.GetCMDType() != "EOF") {
|
||||
type = next.GetCMDType();
|
||||
@ -91,7 +88,7 @@ namespace parseManagerCS
|
||||
Console.Write(next.GetText());
|
||||
Console.ReadLine();
|
||||
}
|
||||
next = test.Next();
|
||||
next = PM.Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
[TESTER]{
|
||||
"Hello World"
|
||||
}
|
||||
61
parseManager/bin/Debug/test.txt
Normal file
61
parseManager/bin/Debug/test.txt
Normal file
@ -0,0 +1,61 @@
|
||||
ENTRY TESTSTART
|
||||
[TESTSTART]{
|
||||
SetFG(Color_Blue)
|
||||
write("This is blue ")
|
||||
SetFG(Color_Red)
|
||||
print("This is red")
|
||||
ResetColor()
|
||||
"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()
|
||||
setCC()
|
||||
if name=="" then SKIP(-4)|SKIP(0)
|
||||
ClearLine()
|
||||
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")
|
||||
}
|
||||
[ClearLine:function()]{
|
||||
whiteOut()
|
||||
setCC()
|
||||
}
|
||||
[PLAYS]{
|
||||
PAUSE(song)
|
||||
song=PLAY("test.flac")
|
||||
GOTO("control")
|
||||
}
|
||||
[SONG]{
|
||||
song=PLAY("test.flac")
|
||||
GOTO("choice")
|
||||
}
|
||||
[YO]{
|
||||
"How are you doing?"
|
||||
GOTO("choice")
|
||||
}
|
||||
@ -1,5 +1,10 @@
|
||||
ENTRY TESTSTART
|
||||
[TESTSTART]{
|
||||
SetFG(Color_Blue)
|
||||
write("This is blue ")
|
||||
SetFG(Color_Red)
|
||||
print("This is red")
|
||||
ResetColor()
|
||||
"Hello (Press Enter)"
|
||||
print("PLAY SONG (1)")
|
||||
print("MESSAGE (2)")
|
||||
@ -11,12 +16,15 @@ ENTRY TESTSTART
|
||||
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)
|
||||
if choice=="3" then SKIP(3)|SKIP(0)
|
||||
setCC()
|
||||
GOTO("choice")
|
||||
"We are here now! Time for some fun..."
|
||||
write("Please enter your name: ")
|
||||
name=GetInput()
|
||||
if name=="" then SKIP(-3)|SKIP(0)
|
||||
setCC()
|
||||
if name=="" then SKIP(-4)|SKIP(0)
|
||||
ClearLine()
|
||||
print("So your name is $name$ huh...")
|
||||
"I won't judge haha"
|
||||
"Anyway let's get controls for that song"
|
||||
@ -35,6 +43,10 @@ ENTRY TESTSTART
|
||||
if choice=="q" then QUIT()|SKIP(0)
|
||||
GOTO("control")
|
||||
}
|
||||
[ClearLine:function()]{
|
||||
whiteOut()
|
||||
setCC()
|
||||
}
|
||||
[PLAYS]{
|
||||
PAUSE(song)
|
||||
song=PLAY("test.flac")
|
||||
|
||||
@ -1,4 +1,20 @@
|
||||
[START]{
|
||||
print("Testing")
|
||||
"Done!"
|
||||
[THREAD]{
|
||||
::loop::
|
||||
n=random(1,4)
|
||||
if n==1 then SetFG(Color_Blue)|SKIP(0)
|
||||
if n==2 then SetFG(Color_Red)|SKIP(0)
|
||||
if n==3 then SetFG(Color_Green)|SKIP(0)
|
||||
if n==4 then SetFG(Color_Yellow)|SKIP(0)
|
||||
sleep(.1)
|
||||
GOTO("loop")
|
||||
}
|
||||
[START]{
|
||||
print("Testing threading!")
|
||||
n==0
|
||||
newThread("THREAD")
|
||||
c=0
|
||||
::loop::
|
||||
c=c+1
|
||||
"c = $c$ n = $n$"
|
||||
GOTO("loop")
|
||||
}
|
||||
@ -20,8 +20,9 @@ namespace parseManagerCS
|
||||
standardDefine _invoke = new standardDefine();
|
||||
string _filepath;
|
||||
bool _active = true;
|
||||
string _define;
|
||||
string _define = "NO_DEFINE";
|
||||
string _entry = "START";
|
||||
bool _isInternal;
|
||||
Type _defineType;
|
||||
standardDefine def = new standardDefine();
|
||||
MethodInfo _defineMethod;
|
||||
@ -34,6 +35,25 @@ namespace parseManagerCS
|
||||
Dictionary<string, bool> _flags = new Dictionary<string, bool>();
|
||||
Dictionary<string, chunk> _chunks = new Dictionary<string, chunk>();
|
||||
Dictionary<string, string> _methods = new Dictionary<string, string>();
|
||||
void INITENV()
|
||||
{
|
||||
_mainENV["Color_Black"] = ConsoleColor.Black;
|
||||
_mainENV["Color_Blue"] = ConsoleColor.Blue;
|
||||
_mainENV["Color_Cyan"] = ConsoleColor.Cyan;
|
||||
_mainENV["Color_DarkBlue"] = ConsoleColor.DarkBlue;
|
||||
_mainENV["Color_DarkCyan"] = ConsoleColor.DarkCyan;
|
||||
_mainENV["Color_DarkGray"] = ConsoleColor.DarkGray;
|
||||
_mainENV["Color_DarkGreen"] = ConsoleColor.DarkGreen;
|
||||
_mainENV["Color_DarkMagenta"] = ConsoleColor.DarkMagenta;
|
||||
_mainENV["Color_DarkRed"] = ConsoleColor.DarkRed;
|
||||
_mainENV["Color_DarkYellow"] = ConsoleColor.DarkYellow;
|
||||
_mainENV["Color_Gray"] = ConsoleColor.Gray;
|
||||
_mainENV["Color_Green"] = ConsoleColor.Green;
|
||||
_mainENV["Color_Magenta"] = ConsoleColor.Magenta;
|
||||
_mainENV["Color_Red"] = ConsoleColor.Red;
|
||||
_mainENV["Color_White"] = ConsoleColor.White;
|
||||
_mainENV["Color_Yellow"] = ConsoleColor.Yellow;
|
||||
}
|
||||
public void _SetDENV(ENV env)
|
||||
{
|
||||
_mainENV = env;
|
||||
@ -46,6 +66,7 @@ namespace parseManagerCS
|
||||
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
||||
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
||||
_defualtENV = _mainENV;
|
||||
INITENV();
|
||||
Parse();
|
||||
}
|
||||
public parseManager(string filepath, string define)
|
||||
@ -57,8 +78,46 @@ namespace parseManagerCS
|
||||
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
||||
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
||||
_defualtENV = _mainENV;
|
||||
INITENV();
|
||||
Parse();
|
||||
}
|
||||
public parseManager(string code, string define, bool c)
|
||||
{
|
||||
InitFlags();
|
||||
_define = define;
|
||||
_filepath = code;
|
||||
_isInternal = true;
|
||||
_defineType = Type.GetType(define);
|
||||
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
||||
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
||||
_defualtENV = _mainENV;
|
||||
INITENV();
|
||||
Parse(code, c);
|
||||
}
|
||||
public parseManager(string code, bool c)
|
||||
{
|
||||
_isInternal = true;
|
||||
InitFlags();
|
||||
_filepath = code;
|
||||
_defineType = Type.GetType("standardDefine");
|
||||
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
||||
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
||||
_defualtENV = _mainENV;
|
||||
INITENV();
|
||||
Parse(code, c);
|
||||
}
|
||||
public bool IsInternal()
|
||||
{
|
||||
return _isInternal;
|
||||
}
|
||||
public string GetFilepath()
|
||||
{
|
||||
return _filepath;
|
||||
}
|
||||
public string GetDefine()
|
||||
{
|
||||
return _define;
|
||||
}
|
||||
void InitFlags()
|
||||
{
|
||||
_flags.Add("leaking", false);
|
||||
@ -125,6 +184,10 @@ namespace parseManagerCS
|
||||
Console.WriteLine("File '" + _filepath + "' does not exist! Loading failled!");
|
||||
}
|
||||
}
|
||||
void Parse(string code, bool c)
|
||||
{
|
||||
_Parse(code);
|
||||
}
|
||||
void Parse(string filename)
|
||||
{
|
||||
try {
|
||||
@ -175,8 +238,10 @@ namespace parseManagerCS
|
||||
var argsN = c.GetArgs();
|
||||
var fEnv = new ENV();
|
||||
fEnv.SetParent(_defualtENV);
|
||||
for (int i = 0; i < argsN.Length; i++) {
|
||||
fEnv[argsN[i]] = argsV[i];
|
||||
if (!(argsN.Length == 1 && argsN[0] == "")) {
|
||||
for (int i = 0; i < argsN.Length; i++) {
|
||||
fEnv[argsN[i]] = argsV[i];
|
||||
}
|
||||
}
|
||||
var tempEnv = new ENV();
|
||||
tempEnv[0] = ccN;
|
||||
@ -187,7 +252,7 @@ namespace parseManagerCS
|
||||
PushError("Stack Overflow!");
|
||||
}
|
||||
_defualtENV = fEnv;
|
||||
def.JUMP(this,method);
|
||||
def.JUMP(this, method);
|
||||
return fEnv; // TODO Handle returns
|
||||
}
|
||||
public object InvokeR(string method, object[] args)
|
||||
@ -199,8 +264,8 @@ namespace parseManagerCS
|
||||
try {
|
||||
_defineMethod = _defineType.GetMethod(method);
|
||||
return _defineMethod.Invoke(_defineClassObject, tackBArgs(this, args));
|
||||
} catch {
|
||||
PushError("Invalid method: " + method);
|
||||
} catch (Exception e) {
|
||||
PushError("Invalid method: " + method + "\n\n" + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -215,18 +280,19 @@ namespace parseManagerCS
|
||||
_defineMethod = _defineType.GetMethod(method);
|
||||
_defineMethod.Invoke(_defineClassObject, tackBArgs(this, args));
|
||||
return 0;
|
||||
} catch {
|
||||
PushError("Invalid method: " + method);
|
||||
} catch (Exception e) {
|
||||
PushError("Invalid method: " + method + "\n\n" + e);
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public object[] tackBArgs(object o,object[] args){
|
||||
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];
|
||||
var newargs = new object[len + 1];
|
||||
for (int i = 0; i < len; i++) {
|
||||
newargs[i + 1] = args[i];
|
||||
}
|
||||
newargs[0]=o;
|
||||
newargs[0] = o;
|
||||
return newargs;
|
||||
}
|
||||
public void SetBlock(string BLOCK)
|
||||
@ -1140,6 +1206,39 @@ namespace parseManagerCS
|
||||
}
|
||||
public class standardDefine
|
||||
{
|
||||
Random rnd = new Random();
|
||||
public void newThread(parseManager PM, string Block)
|
||||
{
|
||||
var thread = new Thread(() => _THREAD(Block, PM));
|
||||
thread.Start();
|
||||
}
|
||||
public void _THREAD(string block, parseManager _PM)
|
||||
{
|
||||
var define = _PM.GetDefine();
|
||||
var path = _PM.GetFilepath();
|
||||
parseManager PM;
|
||||
if (_PM.IsInternal()) {
|
||||
if (define == "NO_DEFINE") {
|
||||
PM = new parseManager(path, true);
|
||||
} else {
|
||||
PM = new parseManager(path, define, true);
|
||||
}
|
||||
} else {
|
||||
if (define == "NO_DEFINE") {
|
||||
PM = new parseManager(path);
|
||||
} else {
|
||||
PM = new parseManager(path, define);
|
||||
}
|
||||
}
|
||||
PM._SetDENV(_PM.GetDENV());
|
||||
PM.SetENV(_PM.GetENV());
|
||||
nextType next = PM.Next(block);
|
||||
string type;
|
||||
while (next.GetCMDType() != "EOF") {
|
||||
type = next.GetCMDType();
|
||||
next = PM.Next();
|
||||
}
|
||||
}
|
||||
public void SAVE(parseManager PM)
|
||||
{
|
||||
var env = PM.GetDENV();
|
||||
@ -1149,6 +1248,10 @@ public class standardDefine
|
||||
env["__DefualtENV"] = PM.GetENV();
|
||||
GLOBALS.WriteToBinaryFile("savedata.dat", env);
|
||||
}
|
||||
public void save(parseManager PM)
|
||||
{
|
||||
SAVE(PM);
|
||||
}
|
||||
public bool LOAD(parseManager PM)
|
||||
{
|
||||
try {
|
||||
@ -1165,18 +1268,26 @@ public class standardDefine
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void load(parseManager PM)
|
||||
{
|
||||
LOAD(PM);
|
||||
}
|
||||
public void TRACEBACK(parseManager PM)
|
||||
{
|
||||
ENV env = PM.Pop();
|
||||
PM.SetBlock((string)env[0]);
|
||||
var c = PM.GetCurrentChunk();
|
||||
c.SetPos((int)env[1]);
|
||||
SetENV(PM,(ENV)env[3]);
|
||||
SetENV(PM, (ENV)env[3]);
|
||||
}
|
||||
public void EXIT(parseManager PM)
|
||||
{
|
||||
PM.Deactivate();
|
||||
}
|
||||
public void exit(parseManager PM)
|
||||
{
|
||||
EXIT(PM);
|
||||
}
|
||||
public void QUIT(parseManager PM)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
@ -1203,6 +1314,28 @@ public class standardDefine
|
||||
{
|
||||
return Console.ReadLine();
|
||||
}
|
||||
public void setCC(parseManager PM)
|
||||
{
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
}
|
||||
public void whiteOut(parseManager PM)
|
||||
{
|
||||
for (int i = 0; i < Console.BufferWidth; i++) {
|
||||
Console.Write(" ");
|
||||
}
|
||||
}
|
||||
public void SetBG(parseManager PM, ConsoleColor BG)
|
||||
{
|
||||
Console.BackgroundColor = BG;
|
||||
}
|
||||
public void SetFG(parseManager PM, ConsoleColor FG)
|
||||
{
|
||||
Console.ForegroundColor = FG;
|
||||
}
|
||||
public void ResetColor(parseManager PM)
|
||||
{
|
||||
Console.ResetColor();
|
||||
}
|
||||
public int GOTO(parseManager PM, string label)
|
||||
{
|
||||
var c = PM.GetCurrentChunk();
|
||||
@ -1234,18 +1367,30 @@ public class standardDefine
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public double len(parseManager PM, object o)
|
||||
{
|
||||
return LEN(PM, o);
|
||||
}
|
||||
public void JUMP(parseManager PM, string block)
|
||||
{
|
||||
var c = PM.GetCurrentChunk();
|
||||
c.ResetPos();
|
||||
PM.SetBlock(block);
|
||||
}
|
||||
public void jump(parseManager PM, string block)
|
||||
{
|
||||
JUMP(PM, block);
|
||||
}
|
||||
public void SKIP(parseManager PM, double n)
|
||||
{
|
||||
var c = PM.GetCurrentChunk();
|
||||
var pos = c.GetPos();
|
||||
c.SetPos(pos + (int)n);
|
||||
}
|
||||
public void skip(parseManager PM, double n)
|
||||
{
|
||||
SKIP(PM, n);
|
||||
}
|
||||
public double tonumber(parseManager PM, string strn)
|
||||
{
|
||||
double d;
|
||||
@ -1255,9 +1400,9 @@ public class standardDefine
|
||||
PM.debug("Cannot convert to a number!");
|
||||
return double.NaN;
|
||||
}
|
||||
public void SLEEP(parseManager PM, double n)
|
||||
public void sleep(parseManager PM, double n)
|
||||
{
|
||||
int i = int.Parse(n.ToString()) * 1000;
|
||||
int i = (int)n * 1000;
|
||||
Thread.Sleep(i);
|
||||
}
|
||||
public double ADD(parseManager PM, double a, double b)
|
||||
@ -1284,10 +1429,26 @@ public class standardDefine
|
||||
{
|
||||
return evaluater.Evaluate(ex);
|
||||
}
|
||||
public void pause(parseManager PM)
|
||||
{
|
||||
Console.ReadLine();
|
||||
}
|
||||
public void print(parseManager PM, object o)
|
||||
{
|
||||
Console.WriteLine(o);
|
||||
}
|
||||
public double random(parseManager PM, double s, double e)
|
||||
{
|
||||
return (double)rnd.Next((int)s, (int)e);
|
||||
}
|
||||
public double rand(parseManager PM)
|
||||
{
|
||||
return rnd.NextDouble();
|
||||
}
|
||||
public double round(parseManager PM, double num, double n)
|
||||
{
|
||||
return Math.Round(num, (int)n);
|
||||
}
|
||||
public void write(parseManager PM, object o)
|
||||
{
|
||||
Console.Write(o);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user