This commit is contained in:
Ryan 2017-08-17 17:36:30 -04:00
parent df57e96033
commit 1589340f36
3 changed files with 94 additions and 28 deletions

View File

@ -13,7 +13,7 @@ public class define
{
public void testM(string arg1)
{
Console.WriteLine(arg1 + " it works!");
Console.WriteLine(arg1);
}
public void testM2(string arg1)
{
@ -27,8 +27,8 @@ namespace parseManager
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
parseManager test = new parseManager("path","define");
test.invokeA("testM",new object[]{""});
parseManager test = new parseManager("parsetest2.txt","define");
test.invokeA("testM",new object[]{"This is invoked!"});
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}

View File

@ -0,0 +1,66 @@
ENTRY START
[START]{
a=10>1
b=10<1
"test: $a$ $b$"
test["name"]="Ryan"
name=test["name"]
"Hi $test[name]$! $name$"
testfunc("hello",(5!),15@1)
test("hello",sqrt(5!),(15@1)/2)
}
[@:construct]{ -- get % out of 100
ret=l/(r/100)
return(ret)
}
[>:construct]{ -- get % out of 100
ret=rshift(l,r)
return(ret)
}
[<:construct]{ -- get % out of 100
ret=lshift(l,r)
return(ret)
}
[~:construct]{ -- negate variable
if r~=NONE then GOTO(sub)|GOTO(neg)
::sub::
ret=l-r
return(ret)
GOTO(end)
::neg::
ret=0-r
return(ret)
::end::
}
[test:function(a,b,c)]{
"$a$ $b$ $c$"
}
-- You dont have too many symbols left to use though. For now a symbol is only 1 char long so you are limited
[fact:function(n)]{
count=1
stop=n
::loop:: -- for loop kinda, can become a stateloop as well
n=n*count
count=count+1
if count==stop then GOTO(end)|GOTO(loop)
::end::
ret=n
}
[neg:function(n)]{
ret=n*(0-1)
}
--Bind the fact function to the symbol '!'
[!:construct]{
env=fact(l)
ret=env["ret"]
return(ret)
}
[NOVAR]{
::go::
"I AM HERE!!!"
NOVAR="TEST"
JUMP(START)
}
[TEST]{
"We are now here"
}

View File

@ -18,57 +18,57 @@ namespace parseManager
/// </summary>
public class parseManager
{
string filepath;
bool hasDefine;
string define;
string entry="START";
Type defineType;
MethodInfo defineMethod;
object defineClassObject;
Dictionary<string, string> chunks = new Dictionary<string, string>();
string _filepath;
bool _hasDefine;
string _define;
string _entry="START";
Type _defineType;
MethodInfo _defineMethod;
object _defineClassObject;
Dictionary<string, string> _chunks = new Dictionary<string, string>();
private void parse(){
try
{
StreamReader sr = File.OpenText (filepath);
StreamReader sr = File.OpenText (_filepath);
string CDFDATA = sr.ReadToEnd ();
string pattern = @"\[(.+)\][\r\n]*?\{([^\0]+?)\}";
var match = Regex.Matches( CDFDATA, pattern );
foreach (Match m in match)
chunks.Add (m.Groups [1].ToString (), m.Groups [2].ToString ());
_chunks.Add (m.Groups [1].ToString (), m.Groups [2].ToString ());
}
catch (FileNotFoundException ex)
{
Console.WriteLine("File '"+filepath+"' does not exist!\n"+ex);
Console.WriteLine("File '"+_filepath+"' does not exist!\n"+ex);
}
}
public parseManager(string filepath)
{
this.filepath=filepath;
hasDefine=false;
_filepath=filepath;
_hasDefine=false;
parse();
}
public parseManager(string filepath,string define){
this.define=define;
hasDefine=true;
this.filepath=filepath;
defineType = Type.GetType(define);
ConstructorInfo defineConstructor = defineType.GetConstructor(Type.EmptyTypes);
defineClassObject = defineConstructor.Invoke(new object[]{});
_define=define;
_hasDefine=true;
_filepath=filepath;
_defineType = Type.GetType(define);
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
_defineClassObject = defineConstructor.Invoke(new object[]{});
parse();
}
public int invokeA(string method, object[] args){ // TODO collect the returned arguments if any
if (!hasDefine)
if (!_hasDefine)
return -1;
defineMethod = defineType.GetMethod(method);
defineMethod.Invoke(defineClassObject, args);
_defineMethod = _defineType.GetMethod(method);
_defineMethod.Invoke(_defineClassObject, args);
return 0;
}
public int invokeNA(string method, object[] args){ // Simple Invoking!
if (!hasDefine)
if (!_hasDefine)
return -1;
defineMethod = defineType.GetMethod(method);
defineMethod.Invoke(defineClassObject, args);
_defineMethod = _defineType.GetMethod(method);
_defineMethod.Invoke(_defineClassObject, args);
return 0;
}
public nextType next(){