More stuff

Added function returns
Added assignments(Simple)
TODO:
Assignments and lists
Assignments and Dicts
This commit is contained in:
Ryan 2017-08-20 00:04:08 -04:00
parent 81c9ae229b
commit fb35acbf45
2 changed files with 54 additions and 41 deletions

View File

@ -1,11 +1,9 @@
ENTRY START ENTRY START
ENABLE debugging
[START]{ [START]{
"Hello!" "Test 1:"
"NO!" num=ADD(5,5)
TEST() "num = $num$"
TEST2("food is $test$") c=5
TEST3(12345,test) a,b="sdf",true
num=TEST4(15) "a,b,c = $a$ $b$ $c$"
TEST2(num)
} }

View File

@ -179,13 +179,11 @@ namespace parseManager
public nextType Next() public nextType Next()
{ {
GLOBALS.SetPM(this); GLOBALS.SetPM(this);
nextType tempReturn = new nextType(); var tempReturn = new nextType();
if (_currentChunk == null) { if (_currentChunk == null) {
SetBlock(); SetBlock();
} }
// TODO Add commands lol var cCMD = _currentChunk.GetCLine();
//Console.WriteLine(_currentChunk.GetPos());
CMD cCMD = _currentChunk.GetCLine();
object[] stuff; object[] stuff;
if (cCMD == null) { if (cCMD == null) {
if (_flags["leaking"]) { if (_flags["leaking"]) {
@ -196,13 +194,11 @@ namespace parseManager
tempReturn.SetText("Reached the end of the file!"); tempReturn.SetText("Reached the end of the file!");
return tempReturn; return tempReturn;
} }
string type = cCMD.GetCMDType(); var type = cCMD.GetCMDType();
stuff = cCMD.GetArgs(); stuff = cCMD.GetArgs();
//Console.WriteLine(type);
if (type == "FUNC") { if (type == "FUNC") {
string func = (string)stuff[0]; var func = (string)stuff[0];
string[] args = (string[])stuff[1]; var args = (string[])stuff[1];
//debug(args.Length);
if (args.Length == 1 && args[0] == "") { // assume no args inserted! if (args.Length == 1 && args[0] == "") { // assume no args inserted!
InvokeNR(func, new object[]{ }); InvokeNR(func, new object[]{ });
} else { } else {
@ -211,9 +207,29 @@ namespace parseManager
tempReturn.SetCMDType("method"); tempReturn.SetCMDType("method");
tempReturn.SetText("INVOKED METHOD: " + func); tempReturn.SetText("INVOKED METHOD: " + func);
} else if (type == "LINE") { } else if (type == "LINE") {
//Console.WriteLine(stuff[0]);
tempReturn.SetCMDType("line"); tempReturn.SetCMDType("line");
tempReturn.SetText(parseHeader((string)stuff[0])); tempReturn.SetText(parseHeader((string)stuff[0]));
} else if (type == "FUNC_R") {
var retargs = (string[])stuff[0];
var func = (string)stuff[1];
var args = (string[])stuff[2];
object data;
if (args.Length == 1 && args[0] == "") { // assume no args inserted!
data = InvokeR(func, new object[]{ });
} else {
data = InvokeR(func, ResolveVar(args));
}
// For Now handle 1 var name to 1 value
var env = GetENV();
env[retargs[0]] = data;
} else if(type=="ASSIGN"){
var vars=(string[])stuff[0];
var vals=(string[])stuff[1];
var env = GetENV();
var types=ResolveVar(vals);
for(int i=0;i<types.Length;i++){
env[vars[i]]=types[i];
}
} }
return tempReturn; return tempReturn;
} }
@ -236,8 +252,8 @@ namespace parseManager
public object[] ResolveVar(string[] v) public object[] ResolveVar(string[] v)
{ {
//_defualtENV //_defualtENV
int len = v.Length; var len = v.Length;
object[] args = new object[len]; var args = new object[len];
object val; object val;
double num; double num;
bool boo; bool boo;
@ -285,7 +301,7 @@ namespace parseManager
{ {
var m = Regex.Match(_type, @"([a-zA-Z0-9_]+)"); var m = Regex.Match(_type, @"([a-zA-Z0-9_]+)");
_pureType = m.Groups[1].ToString(); _pureType = m.Groups[1].ToString();
string tCont = Regex.Replace(cont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline); var tCont = Regex.Replace(cont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline);
tCont = Regex.Replace(tCont, @"\-\-.+\r\n", "", RegexOptions.Multiline); tCont = Regex.Replace(tCont, @"\-\-.+\r\n", "", RegexOptions.Multiline);
tCont = Regex.Replace(tCont, @"\-\-.+\n", "", RegexOptions.Multiline); tCont = Regex.Replace(tCont, @"\-\-.+\n", "", RegexOptions.Multiline);
tCont = Regex.Replace(tCont, @"\t", "", RegexOptions.Multiline); tCont = Regex.Replace(tCont, @"\t", "", RegexOptions.Multiline);
@ -304,30 +320,27 @@ namespace parseManager
var FuncWReturn = Regex.Match(temp, "([\\[\\]\"a-zA-Z0-9_,]+)\\s?=\\s?([a-zA-Z0-9_]+)\\s?\\((.*)\\)"); var FuncWReturn = Regex.Match(temp, "([\\[\\]\"a-zA-Z0-9_,]+)\\s?=\\s?([a-zA-Z0-9_]+)\\s?\\((.*)\\)");
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_\",\\[\\]]+)");
if (FuncWReturn.ToString() != "") { if (FuncWReturn.ToString() != "") {
string var1 = (FuncWReturn.Groups[1]).ToString(); var var1 = (FuncWReturn.Groups[1]).ToString();
string func = (FuncWReturn.Groups[2]).ToString(); var func = (FuncWReturn.Groups[2]).ToString();
string args = (FuncWReturn.Groups[3]).ToString(); var args = (FuncWReturn.Groups[3]).ToString();
string[] retargs = var1.Split(','); var retargs = var1.Split(',');
string[] result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)"); var result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
_compiledlines.Add(new CMD("FUNC_R", new object[] { _compiledlines.Add(new CMD("FUNC_R", new object[] { retargs, func, result }));
retargs,
func,
result
}));
//Console.WriteLine("FUNV_R: "+i);
} else if (FuncWOReturn.ToString() != "") { } else if (FuncWOReturn.ToString() != "") {
string func = (FuncWOReturn.Groups[1]).ToString(); var func = (FuncWOReturn.Groups[1]).ToString();
string args = (FuncWOReturn.Groups[2]).ToString(); var args = (FuncWOReturn.Groups[2]).ToString();
string[] result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)"); var result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
_compiledlines.Add(new CMD("FUNC", new object[]{ func, result })); _compiledlines.Add(new CMD("FUNC", new object[]{ func, result }));
//Console.WriteLine("FUNC: "+i);
} 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() }));
//Console.WriteLine("LINE: "+i); } else if (assignment.ToString() != "") {
var vars = Regex.Split(assignment.Groups[1].ToString(), ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
var vals = Regex.Split(assignment.Groups[2].ToString(), ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
_compiledlines.Add(new CMD("ASSIGN", new object[]{ vars, vals }));
} else { } else {
_compiledlines.Add(new CMD("UNKNOWN", new object[]{ })); _compiledlines.Add(new CMD("UNKNOWN", new object[]{ }));
//Console.WriteLine("UNKNOWN: "+i);
} }
//Console.WriteLine(_compiledlines[i].GetCMDType()); //Console.WriteLine(_compiledlines[i].GetCMDType());
} }
@ -502,10 +515,12 @@ namespace parseManager
{ {
env[ind] = data; env[ind] = data;
} }
public static void SetPM(parseManager o){ public static void SetPM(parseManager o)
{
current = o; current = o;
} }
public static parseManager GetPM(){ public static parseManager GetPM()
{
return current; return current;
} }
} }