more updates
This commit is contained in:
parent
fb35acbf45
commit
85770ebcb0
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using parseManager; // IMPORTANT
|
using parseManager; // IMPORTANT
|
||||||
public class define : standardParseDefine // If you want the standard methods you must include this
|
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)
|
public void testM(object arg1)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,9 +1,19 @@
|
|||||||
ENTRY START
|
ENABLE leaking
|
||||||
|
[TEST]{
|
||||||
|
"Jump was successful!"
|
||||||
|
GOTO("HERE")
|
||||||
|
}
|
||||||
[START]{
|
[START]{
|
||||||
"Test 1:"
|
"Test 1:"
|
||||||
num=ADD(5,5)
|
num=ADD(5,5)
|
||||||
"num = $num$"
|
"num = $num$"
|
||||||
c=5
|
c=5
|
||||||
|
::HERE::
|
||||||
a,b="sdf",true
|
a,b="sdf",true
|
||||||
"a,b,c = $a$ $b$ $c$"
|
"a,b,c = $a$ $b$ $c$"
|
||||||
|
yum="TEST"
|
||||||
|
JUMP(yum)
|
||||||
|
test=true
|
||||||
|
if count==stop and test==true then GOTO(end)|GOTO(loop)
|
||||||
}
|
}
|
||||||
|
-- (count==stop and name=="bob") ? GOTO(end) : GOTO(loop)
|
||||||
@ -21,6 +21,7 @@ namespace parseManager
|
|||||||
{
|
{
|
||||||
string _filepath;
|
string _filepath;
|
||||||
bool _hasDefine;
|
bool _hasDefine;
|
||||||
|
bool _active = true;
|
||||||
string _define;
|
string _define;
|
||||||
string _entry = "START";
|
string _entry = "START";
|
||||||
Type _defineType;
|
Type _defineType;
|
||||||
@ -40,6 +41,13 @@ namespace parseManager
|
|||||||
_flags.Add("debugging", false);
|
_flags.Add("debugging", false);
|
||||||
_flags.Add("topdown", true);
|
_flags.Add("topdown", true);
|
||||||
}
|
}
|
||||||
|
public bool GetFlag(string flag){
|
||||||
|
bool f;
|
||||||
|
if(_flags.TryGetValue(flag,out f)){
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
void debug(object msg)
|
void debug(object msg)
|
||||||
{
|
{
|
||||||
if (_flags["debugging"])
|
if (_flags["debugging"])
|
||||||
@ -96,6 +104,25 @@ namespace parseManager
|
|||||||
{
|
{
|
||||||
return 0; // TODO Add runcode stuff so constructs and functions can work!
|
return 0; // TODO Add runcode stuff so constructs and functions can work!
|
||||||
}
|
}
|
||||||
|
public chunk[] GetChunks(){
|
||||||
|
var chunks = _chunks.Values;
|
||||||
|
var temp = new chunk[_chunks.Count];
|
||||||
|
var i=0;
|
||||||
|
foreach(var item in _chunks)
|
||||||
|
{
|
||||||
|
temp[i]=item.Value;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
public chunk GetCurrentChunk()
|
||||||
|
{
|
||||||
|
return _currentChunk;
|
||||||
|
}
|
||||||
|
public void Deactivate()
|
||||||
|
{
|
||||||
|
_active = false;
|
||||||
|
}
|
||||||
public parseManager(string filepath)
|
public parseManager(string filepath)
|
||||||
{
|
{
|
||||||
InitFlags();
|
InitFlags();
|
||||||
@ -136,6 +163,7 @@ namespace parseManager
|
|||||||
chunk cchunk;
|
chunk cchunk;
|
||||||
if (_chunks.TryGetValue(BLOCK, out cchunk)) {
|
if (_chunks.TryGetValue(BLOCK, out cchunk)) {
|
||||||
_currentChunk = cchunk;
|
_currentChunk = cchunk;
|
||||||
|
_currentChunk.ResetPos();
|
||||||
} else {
|
} else {
|
||||||
PushError("Attempt to JUMP to a non existing block!");
|
PushError("Attempt to JUMP to a non existing block!");
|
||||||
}
|
}
|
||||||
@ -161,6 +189,7 @@ namespace parseManager
|
|||||||
chunk cchunk;
|
chunk cchunk;
|
||||||
if (_chunks.TryGetValue(_entry, out cchunk)) {
|
if (_chunks.TryGetValue(_entry, out cchunk)) {
|
||||||
_currentChunk = cchunk;
|
_currentChunk = cchunk;
|
||||||
|
_currentChunk.ResetPos();
|
||||||
} else {
|
} else {
|
||||||
PushError("Entrypoint is Invalid!");
|
PushError("Entrypoint is Invalid!");
|
||||||
}
|
}
|
||||||
@ -168,6 +197,7 @@ namespace parseManager
|
|||||||
public void PushError(string err)
|
public void PushError(string err)
|
||||||
{
|
{
|
||||||
Console.WriteLine(err);
|
Console.WriteLine(err);
|
||||||
|
Deactivate();
|
||||||
}
|
}
|
||||||
public nextType Next(string BLOCK)
|
public nextType Next(string BLOCK)
|
||||||
{
|
{
|
||||||
@ -186,7 +216,7 @@ namespace parseManager
|
|||||||
var cCMD = _currentChunk.GetCLine();
|
var cCMD = _currentChunk.GetCLine();
|
||||||
object[] stuff;
|
object[] stuff;
|
||||||
if (cCMD == null) {
|
if (cCMD == null) {
|
||||||
if (_flags["leaking"]) {
|
if (_flags["leaking"] && _active) {
|
||||||
SetBlock(_currentChunk.GetNextChunk());
|
SetBlock(_currentChunk.GetNextChunk());
|
||||||
return Next();
|
return Next();
|
||||||
}
|
}
|
||||||
@ -196,6 +226,20 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
var type = cCMD.GetCMDType();
|
var type = cCMD.GetCMDType();
|
||||||
stuff = cCMD.GetArgs();
|
stuff = cCMD.GetArgs();
|
||||||
|
if (type == "LABEL") {
|
||||||
|
cCMD = _currentChunk.GetCLine();
|
||||||
|
if (cCMD == null) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
if (type == "FUNC") {
|
if (type == "FUNC") {
|
||||||
var func = (string)stuff[0];
|
var func = (string)stuff[0];
|
||||||
var args = (string[])stuff[1];
|
var args = (string[])stuff[1];
|
||||||
@ -222,14 +266,18 @@ namespace parseManager
|
|||||||
// For Now handle 1 var name to 1 value
|
// For Now handle 1 var name to 1 value
|
||||||
var env = GetENV();
|
var env = GetENV();
|
||||||
env[retargs[0]] = data;
|
env[retargs[0]] = data;
|
||||||
} else if(type=="ASSIGN"){
|
tempReturn.SetCMDType("method");
|
||||||
var vars=(string[])stuff[0];
|
tempReturn.SetText("INVOKED METHOD: " + func);
|
||||||
var vals=(string[])stuff[1];
|
} else if (type == "ASSIGN") {
|
||||||
|
var vars = (string[])stuff[0];
|
||||||
|
var vals = (string[])stuff[1];
|
||||||
var env = GetENV();
|
var env = GetENV();
|
||||||
var types=ResolveVar(vals);
|
var types = ResolveVar(vals);
|
||||||
for(int i=0;i<types.Length;i++){
|
for (int i = 0; i < types.Length; i++) {
|
||||||
env[vars[i]]=types[i];
|
env[vars[i]] = types[i];
|
||||||
}
|
}
|
||||||
|
tempReturn.SetCMDType("assignment");
|
||||||
|
tempReturn.SetText(_currentChunk.GetLine());
|
||||||
}
|
}
|
||||||
return tempReturn;
|
return tempReturn;
|
||||||
}
|
}
|
||||||
@ -294,6 +342,7 @@ namespace parseManager
|
|||||||
string _type;
|
string _type;
|
||||||
string _pureType;
|
string _pureType;
|
||||||
string[] _lines;
|
string[] _lines;
|
||||||
|
Dictionary<string, int> _labels = new Dictionary<string, int>();
|
||||||
List<CMD> _compiledlines = new List<CMD>();
|
List<CMD> _compiledlines = new List<CMD>();
|
||||||
int _pos = 0;
|
int _pos = 0;
|
||||||
chunk _next = null;
|
chunk _next = null;
|
||||||
@ -310,7 +359,7 @@ namespace parseManager
|
|||||||
tCont = Regex.Replace(tCont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline);
|
tCont = Regex.Replace(tCont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline);
|
||||||
tCont = Regex.Replace(tCont, @"^\s+$[\r\n]*", "", RegexOptions.Multiline);
|
tCont = Regex.Replace(tCont, @"^\s+$[\r\n]*", "", RegexOptions.Multiline);
|
||||||
_lines = tCont.Split(new [] { "\r\n", "\n" }, StringSplitOptions.None);
|
_lines = tCont.Split(new [] { "\r\n", "\n" }, StringSplitOptions.None);
|
||||||
compile(); // compiles the code into something that can beused quickly
|
compile(); // compiles the code into something that can be used quickly
|
||||||
}
|
}
|
||||||
void compile()
|
void compile()
|
||||||
{
|
{
|
||||||
@ -321,7 +370,27 @@ namespace parseManager
|
|||||||
var FuncWOReturn = Regex.Match(temp, @"^([a-zA-Z0-9_]+)\s?\((.*)\)");
|
var FuncWOReturn = Regex.Match(temp, @"^([a-zA-Z0-9_]+)\s?\((.*)\)");
|
||||||
var pureLine = Regex.Match(temp, "^\"(.+)\"");
|
var pureLine = Regex.Match(temp, "^\"(.+)\"");
|
||||||
var assignment = Regex.Match(temp, "^([a-zA-Z0-9_,\\[\\]\"]+)=([a-zA-Z0-9_\",\\[\\]]+)");
|
var assignment = Regex.Match(temp, "^([a-zA-Z0-9_,\\[\\]\"]+)=([a-zA-Z0-9_\",\\[\\]]+)");
|
||||||
if (FuncWReturn.ToString() != "") {
|
var label = Regex.Match(temp, "::(.*)::");
|
||||||
|
var logic = Regex.Match(temp,@"if\s*(.+)\s*then\s*(.+?\))\s*\|\s*(.+?\))");
|
||||||
|
if(logic.ToString()!=""){
|
||||||
|
var condition = logic.Groups[1].ToString();
|
||||||
|
var _if = logic.Groups[2].ToString();
|
||||||
|
var _else = logic.Groups[3].ToString();
|
||||||
|
var temps = Regex.Match(condition,"(.+?)([and ]+?[or ]+)");
|
||||||
|
string[] conds;
|
||||||
|
if(temps.ToString()!=""){
|
||||||
|
var count=temps.Groups.Count;
|
||||||
|
conds= new string[count+1];
|
||||||
|
for(int b=1;b<temps.Groups.Count;b++){
|
||||||
|
conds[b]=temps.Groups[b].Value;
|
||||||
|
Console.WriteLine(conds[b]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_compiledlines.Add(new CMD("LOGIC", new object[]{"Place holder",_if,_else}));
|
||||||
|
} else if (label.ToString() != "") {
|
||||||
|
_labels[label.Groups[1].ToString()] = i;
|
||||||
|
_compiledlines.Add(new CMD("LABEL", new object[]{ }));
|
||||||
|
} else if (FuncWReturn.ToString() != "") {
|
||||||
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 args = (FuncWReturn.Groups[3]).ToString();
|
var args = (FuncWReturn.Groups[3]).ToString();
|
||||||
@ -342,7 +411,6 @@ namespace parseManager
|
|||||||
} else {
|
} else {
|
||||||
_compiledlines.Add(new CMD("UNKNOWN", new object[]{ }));
|
_compiledlines.Add(new CMD("UNKNOWN", new object[]{ }));
|
||||||
}
|
}
|
||||||
//Console.WriteLine(_compiledlines[i].GetCMDType());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public chunk(string name, string cont, string type)
|
public chunk(string name, string cont, string type)
|
||||||
@ -357,6 +425,23 @@ namespace parseManager
|
|||||||
_type = "CODEBLOCK";
|
_type = "CODEBLOCK";
|
||||||
_clean(cont);
|
_clean(cont);
|
||||||
}
|
}
|
||||||
|
public string GetName(){
|
||||||
|
return _BLOCK;
|
||||||
|
}
|
||||||
|
public int GetLabel(string lab)
|
||||||
|
{
|
||||||
|
return _labels[lab];
|
||||||
|
}
|
||||||
|
public bool TryGetLabel(string lab, out int pos)
|
||||||
|
{
|
||||||
|
int p;
|
||||||
|
if(_labels.TryGetValue(lab, out p)){
|
||||||
|
pos=p;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
pos=-1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public void SetNextChunk(chunk next)
|
public void SetNextChunk(chunk next)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
@ -443,6 +528,31 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class PList
|
||||||
|
{
|
||||||
|
readonly Dictionary<int, object> _vars = new Dictionary<int, object>();
|
||||||
|
public bool TryGetValue(int ind, out object obj)
|
||||||
|
{
|
||||||
|
if (this[ind] != null) {
|
||||||
|
obj = this[ind];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
obj = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public object this[int ind] {
|
||||||
|
get {
|
||||||
|
object obj;
|
||||||
|
if (_vars.TryGetValue(ind, out obj)) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
_vars[ind] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public class nextType
|
public class nextType
|
||||||
{
|
{
|
||||||
string _type;
|
string _type;
|
||||||
@ -525,27 +635,50 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class standardParseDefine
|
public class standardDefine
|
||||||
{
|
{
|
||||||
public void EXIT()
|
public void EXIT()
|
||||||
{
|
{
|
||||||
// TODO Exit the script
|
GLOBALS.GetPM().Deactivate();
|
||||||
}
|
}
|
||||||
public void QUIT()
|
public void QUIT()
|
||||||
{
|
{
|
||||||
// TODO Quit the script
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
public void GOTO(string label)
|
public int GOTO(string label)
|
||||||
{
|
{
|
||||||
// TODO goto a label in the script
|
var test = GLOBALS.GetPM();
|
||||||
|
var c = test.GetCurrentChunk();
|
||||||
|
int pos;
|
||||||
|
if(c.TryGetLabel(label, out pos)){
|
||||||
|
c.SetPos(pos);
|
||||||
|
return 0;
|
||||||
|
} else if(test.GetFlag("forseelabels")){
|
||||||
|
var chunks = test.GetChunks();
|
||||||
|
for(int i=0;i<chunks.Length;i++){
|
||||||
|
if(chunks[i].TryGetLabel(label, out pos)){
|
||||||
|
test.SetBlock(chunks[i].GetName());
|
||||||
|
chunks[i].SetPos(pos);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
test.PushError("Unable to GOTO a non existing label: "+label+"!");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
public void JUMP(string block)
|
public void JUMP(string block)
|
||||||
{
|
{
|
||||||
// TODO jump to a block
|
var test = GLOBALS.GetPM();
|
||||||
|
var c = test.GetCurrentChunk();
|
||||||
|
c.ResetPos();
|
||||||
|
test.SetBlock(block);
|
||||||
}
|
}
|
||||||
public void SKIP(int n)
|
public void SKIP(double n)
|
||||||
{
|
{
|
||||||
// TODO moves position of
|
var test = GLOBALS.GetPM();
|
||||||
|
var c = test.GetCurrentChunk();
|
||||||
|
var pos = c.GetPos();
|
||||||
|
c.SetPos(pos + (int)n);
|
||||||
}
|
}
|
||||||
public double ADD(double a, double b)
|
public double ADD(double a, double b)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user