Started to implement expressions
This commit is contained in:
parent
5a990e4313
commit
74324b86c3
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using parseManager; // IMPORTANT
|
using parseManager; // IMPORTANT
|
||||||
|
using NCalc;
|
||||||
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)
|
public void testM(object arg1)
|
||||||
@ -42,7 +43,8 @@ namespace parseManager
|
|||||||
{
|
{
|
||||||
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
|
|
||||||
|
parseManager test = new parseManager("parsetest2.txt"); // define is where your methods will be held
|
||||||
var env = test.GetENV();
|
var env = test.GetENV();
|
||||||
env["test"]="TEST!";
|
env["test"]="TEST!";
|
||||||
env["test2"]=12345;
|
env["test2"]=12345;
|
||||||
@ -56,7 +58,6 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
next = test.Next();
|
next = test.Next();
|
||||||
}
|
}
|
||||||
//var temp=test.InvokeR("TEST",new object[]{});
|
|
||||||
Console.Write("Press any key to continue . . . ");
|
Console.Write("Press any key to continue . . . ");
|
||||||
Console.ReadKey(true);
|
Console.ReadKey(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,9 @@ ENABLE leaking
|
|||||||
}
|
}
|
||||||
[START]{
|
[START]{
|
||||||
"Test 1:"
|
"Test 1:"
|
||||||
num=ADD(5,5)
|
t=15
|
||||||
|
test=2+t
|
||||||
|
"test = $test$"
|
||||||
"num = $num$"
|
"num = $num$"
|
||||||
c=5
|
c=5
|
||||||
::HERE::
|
::HERE::
|
||||||
|
|||||||
@ -12,6 +12,7 @@ using System.Collections.Generic;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using parseManager;
|
using parseManager;
|
||||||
|
using NCalc;
|
||||||
namespace parseManager
|
namespace parseManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -19,8 +20,8 @@ namespace parseManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class parseManager
|
public class parseManager
|
||||||
{
|
{
|
||||||
|
standardDefine _invoke = new standardDefine();
|
||||||
string _filepath;
|
string _filepath;
|
||||||
bool _hasDefine;
|
|
||||||
bool _active = true;
|
bool _active = true;
|
||||||
string _define;
|
string _define;
|
||||||
string _entry = "START";
|
string _entry = "START";
|
||||||
@ -34,6 +35,27 @@ namespace parseManager
|
|||||||
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 parseManager(string filepath)
|
||||||
|
{
|
||||||
|
InitFlags();
|
||||||
|
_filepath = filepath;
|
||||||
|
_defineType = Type.GetType("standardDefine");
|
||||||
|
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
||||||
|
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
||||||
|
_defualtENV = _mainENV;
|
||||||
|
Parse();
|
||||||
|
}
|
||||||
|
public parseManager(string filepath, string define)
|
||||||
|
{
|
||||||
|
InitFlags();
|
||||||
|
_define = define;
|
||||||
|
_filepath = filepath;
|
||||||
|
_defineType = Type.GetType(define);
|
||||||
|
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
||||||
|
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
||||||
|
_defualtENV = _mainENV;
|
||||||
|
Parse();
|
||||||
|
}
|
||||||
void InitFlags()
|
void InitFlags()
|
||||||
{
|
{
|
||||||
_flags.Add("leaking", false);
|
_flags.Add("leaking", false);
|
||||||
@ -41,9 +63,10 @@ namespace parseManager
|
|||||||
_flags.Add("debugging", false);
|
_flags.Add("debugging", false);
|
||||||
_flags.Add("topdown", true);
|
_flags.Add("topdown", true);
|
||||||
}
|
}
|
||||||
public bool GetFlag(string flag){
|
public bool GetFlag(string flag)
|
||||||
|
{
|
||||||
bool f;
|
bool f;
|
||||||
if(_flags.TryGetValue(flag,out f)){
|
if (_flags.TryGetValue(flag, out f)) {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -65,7 +88,7 @@ namespace parseManager
|
|||||||
_entry = m.Groups[1].ToString();
|
_entry = 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) {
|
||||||
string Blck = m.Groups[1].ToString();
|
string Blck = m.Groups[1].ToString();
|
||||||
string Cont = m.Groups[2].ToString();
|
string Cont = m.Groups[2].ToString();
|
||||||
@ -104,13 +127,13 @@ namespace parseManager
|
|||||||
{
|
{
|
||||||
_Parse(code);
|
_Parse(code);
|
||||||
}
|
}
|
||||||
public chunk[] GetChunks(){
|
public chunk[] GetChunks()
|
||||||
|
{
|
||||||
var chunks = _chunks.Values;
|
var chunks = _chunks.Values;
|
||||||
var temp = new chunk[_chunks.Count];
|
var temp = new chunk[_chunks.Count];
|
||||||
var i=0;
|
var i = 0;
|
||||||
foreach(var item in _chunks)
|
foreach (var item in _chunks) {
|
||||||
{
|
temp[i] = item.Value;
|
||||||
temp[i]=item.Value;
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
@ -123,40 +146,26 @@ namespace parseManager
|
|||||||
{
|
{
|
||||||
_active = false;
|
_active = false;
|
||||||
}
|
}
|
||||||
public parseManager(string filepath)
|
|
||||||
{
|
|
||||||
InitFlags();
|
|
||||||
_filepath = filepath;
|
|
||||||
_hasDefine = false;
|
|
||||||
_defualtENV = _mainENV;
|
|
||||||
Parse();
|
|
||||||
}
|
|
||||||
public parseManager(string filepath, string define)
|
|
||||||
{
|
|
||||||
InitFlags();
|
|
||||||
_define = define;
|
|
||||||
_hasDefine = true;
|
|
||||||
_filepath = filepath;
|
|
||||||
_defineType = Type.GetType(define);
|
|
||||||
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
|
||||||
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
|
||||||
_defualtENV = _mainENV;
|
|
||||||
Parse();
|
|
||||||
}
|
|
||||||
public object InvokeR(string method, object[] args)
|
public object InvokeR(string method, object[] args)
|
||||||
{ // TODO collect the returned arguments if any
|
{
|
||||||
if (!_hasDefine)
|
//try{
|
||||||
return null;
|
|
||||||
_defineMethod = _defineType.GetMethod(method);
|
_defineMethod = _defineType.GetMethod(method);
|
||||||
return _defineMethod.Invoke(_defineClassObject, args);
|
return _defineMethod.Invoke(_defineClassObject, args);
|
||||||
|
// } catch {
|
||||||
|
// PushError("Invalid method: "+method);
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
public int InvokeNR(string method, object[] args)
|
public int InvokeNR(string method, object[] args)
|
||||||
{ // Simple Invoking!
|
{
|
||||||
if (!_hasDefine)
|
try {
|
||||||
return -1;
|
_defineMethod = _defineType.GetMethod(method);
|
||||||
_defineMethod = _defineType.GetMethod(method);
|
_defineMethod.Invoke(_defineClassObject, args);
|
||||||
_defineMethod.Invoke(_defineClassObject, args);
|
return 0;
|
||||||
return 0;
|
} catch {
|
||||||
|
PushError("Invalid method: " + method);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
public void SetBlock(string BLOCK)
|
public void SetBlock(string BLOCK)
|
||||||
{
|
{
|
||||||
@ -217,8 +226,8 @@ namespace parseManager
|
|||||||
object[] stuff;
|
object[] stuff;
|
||||||
if (cCMD == null) {
|
if (cCMD == null) {
|
||||||
if (_flags["leaking"] && _active) {
|
if (_flags["leaking"] && _active) {
|
||||||
var test=_currentChunk.GetNextChunk();
|
var test = _currentChunk.GetNextChunk();
|
||||||
if(test!=null){
|
if (test != null) {
|
||||||
SetBlock(_currentChunk.GetNextChunk());
|
SetBlock(_currentChunk.GetNextChunk());
|
||||||
return Next();
|
return Next();
|
||||||
}
|
}
|
||||||
@ -229,64 +238,62 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
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}
|
||||||
var conds=(string[])stuff[0];
|
var conds = (string[])stuff[0];
|
||||||
var andors=(string[])stuff[1];
|
var andors = (string[])stuff[1];
|
||||||
var funcif=(string)stuff[2];
|
var funcif = (string)stuff[2];
|
||||||
var argsif=(string[])stuff[3];
|
var argsif = (string[])stuff[3];
|
||||||
var funcelse=(string)stuff[4];
|
var funcelse = (string)stuff[4];
|
||||||
var argselse=(string[])stuff[5];
|
var argselse = (string[])stuff[5];
|
||||||
var objs=new object[conds.Length]; // contain the actual values of what is in the env
|
var objs = new object[conds.Length]; // contain the actual values of what is in the env
|
||||||
var truths= new bool[conds.Length/3];
|
var truths = new bool[conds.Length / 3];
|
||||||
var c=0;
|
var c = 0;
|
||||||
//Console.WriteLine(string.Join(",",conds));
|
for (int i = 0; i < conds.Length; i += 3) {
|
||||||
//Console.WriteLine(string.Join(",",andors));
|
var condA = (object)ResolveVar(new []{ conds[i] })[0];
|
||||||
for(int i=0;i<conds.Length;i+=3){
|
var e = conds[i + 1];
|
||||||
var condA=(object)ResolveVar(new []{conds[i]})[0];
|
var condB = (object)ResolveVar(new []{ conds[i + 2] })[0];
|
||||||
var e=conds[i+1];
|
if (e == "==") {
|
||||||
var condB=(object)ResolveVar(new []{conds[i+2]})[0];
|
truths[c] = condA.ToString() == condB.ToString();
|
||||||
if(e=="=="){
|
} else if (e == ">=") {
|
||||||
truths[c] = condA.ToString()==condB.ToString();
|
truths[c] = (double)condA >= (double)condB;
|
||||||
} else if(e==">="){
|
} else if (e == "<=") {
|
||||||
truths[c] = (double)condA>=(double)condB;
|
truths[c] = (double)condA <= (double)condB;
|
||||||
} else if(e=="<="){
|
} else if (e == "!=" || e == "~=") {
|
||||||
truths[c] = (double)condA<=(double)condB;
|
truths[c] = condA.ToString() != condB.ToString();
|
||||||
} else if(e=="!=" || e=="~="){
|
} else if (e == ">") {
|
||||||
truths[c] = condA.ToString()!=condB.ToString();
|
truths[c] = (double)condA > (double)condB;
|
||||||
} else if(e==">"){
|
} else if (e == "<") {
|
||||||
truths[c] = (double)condA>(double)condB;
|
truths[c] = (double)condA < (double)condB;
|
||||||
} else if(e=="<"){
|
|
||||||
truths[c] = (double)condA<(double)condB;
|
|
||||||
} else {
|
} else {
|
||||||
PushError("Invalid conditional test! "+e+" is not valid!");
|
PushError("Invalid conditional test! " + e + " is not valid!");
|
||||||
}
|
}
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
var truth=truths[0];
|
var truth = truths[0];
|
||||||
if(truths.Length==1 && truth){
|
if (truths.Length == 1 && truth) {
|
||||||
InvokeNR(funcif, ResolveVar(argsif));
|
InvokeNR(funcif, ResolveVar(argsif));
|
||||||
} else if(truths.Length==1) {
|
} else if (truths.Length == 1) {
|
||||||
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++) {
|
||||||
if(andors[i-1]=="a"){
|
if (andors[i - 1] == "a") {
|
||||||
truth=truth && truths[i];
|
truth = truth && truths[i];
|
||||||
} else if(andors[i-1]=="o"){
|
} else if (andors[i - 1] == "o") {
|
||||||
truth=truth || truths[i];
|
truth = truth || truths[i];
|
||||||
} else {
|
} else {
|
||||||
PushError("Invalid conditional test! "+andors[i-1]+" is not valid!");
|
PushError("Invalid conditional test! " + andors[i - 1] + " is not valid!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(truth){
|
if (truth) {
|
||||||
Console.WriteLine(funcif);
|
Console.WriteLine(funcif);
|
||||||
InvokeNR(funcif, ResolveVar(argsif));
|
InvokeNR(funcif, ResolveVar(argsif));
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine("|"+funcelse+"|");
|
Console.WriteLine("|" + funcelse + "|");
|
||||||
InvokeNR(funcelse, ResolveVar(argselse));
|
InvokeNR(funcelse, ResolveVar(argselse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempReturn.SetCMDType("conditional");
|
tempReturn.SetCMDType("conditional");
|
||||||
tempReturn.SetText("test turned out to be: "+truth);
|
tempReturn.SetText("test turned out to be: " + truth);
|
||||||
} else if (type == "LABEL") {
|
} else if (type == "LABEL") {
|
||||||
cCMD = _currentChunk.GetCLine();
|
cCMD = _currentChunk.GetCLine();
|
||||||
if (cCMD == null) {
|
if (cCMD == null) {
|
||||||
@ -326,15 +333,17 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
var env = GetENV();
|
var env = GetENV();
|
||||||
env[retargs[0]] = data;
|
env[retargs[0]] = data;
|
||||||
|
GLOBALS.Add_Var(retargs[0]);
|
||||||
tempReturn.SetCMDType("method");
|
tempReturn.SetCMDType("method");
|
||||||
tempReturn.SetText("INVOKED METHOD: " + func);
|
tempReturn.SetText("INVOKED METHOD: " + func);
|
||||||
} else if (type == "ASSIGN") {
|
} else if (type == "ASSIGN") { // TODO add lists/dictonaries support
|
||||||
var vars = (string[])stuff[0];
|
var vars = (string[])stuff[0];
|
||||||
var vals = (string[])stuff[1];
|
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];
|
||||||
|
GLOBALS.Add_Var(vars[i]);
|
||||||
}
|
}
|
||||||
tempReturn.SetCMDType("assignment");
|
tempReturn.SetCMDType("assignment");
|
||||||
tempReturn.SetText(_currentChunk.GetLine());
|
tempReturn.SetText(_currentChunk.GetLine());
|
||||||
@ -426,18 +435,25 @@ namespace parseManager
|
|||||||
string temp;
|
string temp;
|
||||||
for (int i = 0; i < _lines.Length - 1; i++) {
|
for (int i = 0; i < _lines.Length - 1; i++) {
|
||||||
temp = _lines[i];
|
temp = _lines[i];
|
||||||
|
var pureLine = Regex.Match(temp, "^\"(.+)\"");
|
||||||
|
var assignment = Regex.Match(temp, "^([a-zA-Z0-9_,\\[\\]\"]+)=([a-zA-Z\\|&\\^\\+\\-\\*/%0-9_\",\\[\\]]+)");
|
||||||
|
if (assignment.ToString() != "") { // TODO fix mess! or write own number calculator
|
||||||
|
var expression = new Expression(assignment.Groups[2].Value);
|
||||||
|
if (!expression.HasErrors()) {
|
||||||
|
temp=assignment.Groups[1].Value+"=CALC(\""+assignment.Groups[2]+"\")";
|
||||||
|
}
|
||||||
|
}
|
||||||
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 assignment = Regex.Match(temp, "^([a-zA-Z0-9_,\\[\\]\"]+)=([a-zA-Z0-9_\",\\[\\]]+)");
|
|
||||||
var label = Regex.Match(temp, "::(.*)::");
|
var label = Regex.Match(temp, "::(.*)::");
|
||||||
var logic = Regex.Match(temp,@"if\s*(.+)\s*then\s*(.+?\))\s*\|\s*(.+?\))");
|
var logic = Regex.Match(temp, @"if\s*(.+)\s*then\s*(.+?\))\s*\|\s*(.+?\))");
|
||||||
if(logic.ToString()!=""){
|
|
||||||
|
if (logic.ToString() != "") {
|
||||||
var condition = logic.Groups[1].ToString();
|
var condition = logic.Groups[1].ToString();
|
||||||
var tempif = logic.Groups[2].ToString();
|
var tempif = logic.Groups[2].ToString();
|
||||||
var tempelse = logic.Groups[3].ToString();
|
var tempelse = logic.Groups[3].ToString();
|
||||||
var argsif=Regex.Match(tempif, @"^([a-zA-Z0-9_]+)\s?\((.*)\)");
|
var argsif = Regex.Match(tempif, @"^([a-zA-Z0-9_]+)\s?\((.*)\)");
|
||||||
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 = Regex.Split(_argsif, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
||||||
@ -446,34 +462,41 @@ namespace parseManager
|
|||||||
var _argselse = (argselse.Groups[2]).ToString();
|
var _argselse = (argselse.Groups[2]).ToString();
|
||||||
string[] _resultelse = Regex.Split(_argselse, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
string[] _resultelse = Regex.Split(_argselse, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
||||||
//Console.WriteLine(string.Join(",",_resultelse));
|
//Console.WriteLine(string.Join(",",_resultelse));
|
||||||
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];
|
||||||
var count=0;
|
var count = 0;
|
||||||
var p=0;
|
var p = 0;
|
||||||
var p2=0;
|
var p2 = 0;
|
||||||
foreach (Match m in mm) {
|
foreach (Match m in mm) {
|
||||||
var s1 = m.Groups[1].ToString();
|
var s1 = m.Groups[1].ToString();
|
||||||
var s1p = Regex.Match(s1,"(.+?)([~!><=]+)+(.+)");
|
var s1p = Regex.Match(s1, "(.+?)([~!><=]+)+(.+)");
|
||||||
var s1a=s1p.Groups[1].ToString();
|
var s1a = s1p.Groups[1].ToString();
|
||||||
var s1b=s1p.Groups[2].ToString();
|
var s1b = s1p.Groups[2].ToString();
|
||||||
var s1c=s1p.Groups[3].ToString();
|
var s1c = s1p.Groups[3].ToString();
|
||||||
var s2 = m.Groups[2].ToString();
|
var s2 = m.Groups[2].ToString();
|
||||||
conds[p++]=s1a;
|
conds[p++] = s1a;
|
||||||
conds[p++]=s1b;
|
conds[p++] = s1b;
|
||||||
conds[p++]=s1c;
|
conds[p++] = s1c;
|
||||||
andors[p2++]=s2.Substring(1,1);
|
andors[p2++] = s2.Substring(1, 1);
|
||||||
count+=s1.Length+s2.Length;
|
count += s1.Length + s2.Length;
|
||||||
}
|
}
|
||||||
var s1p2 = Regex.Match(condition.Substring(count,condition.Length-count-1),"(.+?)([~!><=]+)+(.+)");
|
var s1p2 = Regex.Match(condition.Substring(count, condition.Length - count - 1), "(.+?)([~!><=]+)+(.+)");
|
||||||
var s1a2=s1p2.Groups[1].ToString();
|
var s1a2 = s1p2.Groups[1].ToString();
|
||||||
var s1b2=s1p2.Groups[2].ToString();
|
var s1b2 = s1p2.Groups[2].ToString();
|
||||||
var s1c2=s1p2.Groups[3].ToString();
|
var s1c2 = s1p2.Groups[3].ToString();
|
||||||
//Console.WriteLine(s1a2+"|"+s1b2+"|"+s1c2);
|
//Console.WriteLine(s1a2+"|"+s1b2+"|"+s1c2);
|
||||||
conds[p++]=s1a2;
|
conds[p++] = s1a2;
|
||||||
conds[p++]=s1b2;
|
conds[p++] = s1b2;
|
||||||
conds[p++]=s1c2;
|
conds[p++] = s1c2;
|
||||||
_compiledlines.Add(new CMD("LOGIC", new object[]{conds,andors,_funcif,_resultif,_funcelse,_resultelse}));
|
_compiledlines.Add(new CMD("LOGIC", new object[] {
|
||||||
|
conds,
|
||||||
|
andors,
|
||||||
|
_funcif,
|
||||||
|
_resultif,
|
||||||
|
_funcelse,
|
||||||
|
_resultelse
|
||||||
|
}));
|
||||||
} else if (label.ToString() != "") {
|
} else if (label.ToString() != "") {
|
||||||
_labels[label.Groups[1].ToString()] = i;
|
_labels[label.Groups[1].ToString()] = i;
|
||||||
_compiledlines.Add(new CMD("LABEL", new object[]{ }));
|
_compiledlines.Add(new CMD("LABEL", new object[]{ }));
|
||||||
@ -483,7 +506,11 @@ namespace parseManager
|
|||||||
var args = (FuncWReturn.Groups[3]).ToString();
|
var args = (FuncWReturn.Groups[3]).ToString();
|
||||||
var retargs = var1.Split(',');
|
var retargs = var1.Split(',');
|
||||||
var result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
var result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
||||||
_compiledlines.Add(new CMD("FUNC_R", new object[] { retargs, func, result }));
|
_compiledlines.Add(new CMD("FUNC_R", new object[] {
|
||||||
|
retargs,
|
||||||
|
func,
|
||||||
|
result
|
||||||
|
}));
|
||||||
} else if (FuncWOReturn.ToString() != "") {
|
} else if (FuncWOReturn.ToString() != "") {
|
||||||
var func = (FuncWOReturn.Groups[1]).ToString();
|
var func = (FuncWOReturn.Groups[1]).ToString();
|
||||||
var args = (FuncWOReturn.Groups[2]).ToString();
|
var args = (FuncWOReturn.Groups[2]).ToString();
|
||||||
@ -512,7 +539,8 @@ namespace parseManager
|
|||||||
_type = "CODEBLOCK";
|
_type = "CODEBLOCK";
|
||||||
_clean(cont);
|
_clean(cont);
|
||||||
}
|
}
|
||||||
public string GetName(){
|
public string GetName()
|
||||||
|
{
|
||||||
return _BLOCK;
|
return _BLOCK;
|
||||||
}
|
}
|
||||||
public int GetLabel(string lab)
|
public int GetLabel(string lab)
|
||||||
@ -522,14 +550,15 @@ namespace parseManager
|
|||||||
public bool TryGetLabel(string lab, out int pos)
|
public bool TryGetLabel(string lab, out int pos)
|
||||||
{
|
{
|
||||||
int p;
|
int p;
|
||||||
if(_labels.TryGetValue(lab, out p)){
|
if (_labels.TryGetValue(lab, out p)) {
|
||||||
pos=p;
|
pos = p;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
pos=-1;
|
pos = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public void RemoveNextChunk(){
|
public void RemoveNextChunk()
|
||||||
|
{
|
||||||
_next = null;
|
_next = null;
|
||||||
}
|
}
|
||||||
public void SetNextChunk(chunk next)
|
public void SetNextChunk(chunk next)
|
||||||
@ -705,23 +734,43 @@ namespace parseManager
|
|||||||
*/
|
*/
|
||||||
static class GLOBALS
|
static class GLOBALS
|
||||||
{
|
{
|
||||||
static parseManager current;
|
static standardDefine _define = new standardDefine();
|
||||||
static readonly ENV env = new ENV();
|
static parseManager _current;
|
||||||
|
static readonly ENV _env = new ENV();
|
||||||
|
static List<string> _numvars = new List<string>();
|
||||||
public static object GetData(string ind)
|
public static object GetData(string ind)
|
||||||
{
|
{
|
||||||
return env[ind];
|
return _env[ind];
|
||||||
|
}
|
||||||
|
public static standardDefine GetDefine()
|
||||||
|
{
|
||||||
|
return _define;
|
||||||
}
|
}
|
||||||
public static void AddData(string ind, object data)
|
public static void AddData(string ind, object data)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
}
|
||||||
|
public static void Add_Var(string var)
|
||||||
|
{
|
||||||
|
if (!_numvars.Contains(var)) {
|
||||||
|
_numvars.Add(var);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void Remove_Var(string var)
|
||||||
|
{
|
||||||
|
_numvars.Remove(var);
|
||||||
|
}
|
||||||
|
public static string[] GetVars()
|
||||||
|
{
|
||||||
|
return _numvars.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -740,20 +789,20 @@ public class standardDefine
|
|||||||
var test = GLOBALS.GetPM();
|
var test = GLOBALS.GetPM();
|
||||||
var c = test.GetCurrentChunk();
|
var c = test.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 (test.GetFlag("forseelabels")) {
|
||||||
var chunks = test.GetChunks();
|
var chunks = test.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());
|
test.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+"!");
|
test.PushError("Unable to GOTO a non existing label: " + label + "!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public void JUMP(string block)
|
public void JUMP(string block)
|
||||||
@ -790,4 +839,21 @@ public class standardDefine
|
|||||||
{
|
{
|
||||||
return a % b;
|
return a % b;
|
||||||
}
|
}
|
||||||
|
public double CALC(string ex)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Expression e = new Expression(ex);
|
||||||
|
var vars = GLOBALS.GetVars();
|
||||||
|
var PM = GLOBALS.GetPM();
|
||||||
|
var env = PM.GetENV();
|
||||||
|
for (int i = 0; i < vars.Length; i++) {
|
||||||
|
if (env[vars[i]].GetType().ToString().Contains("Double"))
|
||||||
|
e.Parameters[vars[i]] = (double)env[vars[i]];
|
||||||
|
}
|
||||||
|
return double.Parse(e.Evaluate().ToString());
|
||||||
|
} catch {
|
||||||
|
GLOBALS.GetPM().PushError("Invalid Expression: "+ex);
|
||||||
|
return double.NaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -34,6 +34,9 @@
|
|||||||
<Reference Include="Microsoft.CSharp">
|
<Reference Include="Microsoft.CSharp">
|
||||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="NCalc">
|
||||||
|
<HintPath>bin\Debug\NCalc.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user