changes
This commit is contained in:
parent
df57e96033
commit
1589340f36
@ -13,7 +13,7 @@ public class define
|
|||||||
{
|
{
|
||||||
public void testM(string arg1)
|
public void testM(string arg1)
|
||||||
{
|
{
|
||||||
Console.WriteLine(arg1 + " it works!");
|
Console.WriteLine(arg1);
|
||||||
}
|
}
|
||||||
public void testM2(string arg1)
|
public void testM2(string arg1)
|
||||||
{
|
{
|
||||||
@ -27,8 +27,8 @@ namespace parseManager
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Hello World!");
|
Console.WriteLine("Hello World!");
|
||||||
parseManager test = new parseManager("path","define");
|
parseManager test = new parseManager("parsetest2.txt","define");
|
||||||
test.invokeA("testM",new object[]{""});
|
test.invokeA("testM",new object[]{"This is invoked!"});
|
||||||
Console.Write("Press any key to continue . . . ");
|
Console.Write("Press any key to continue . . . ");
|
||||||
Console.ReadKey(true);
|
Console.ReadKey(true);
|
||||||
}
|
}
|
||||||
|
|||||||
66
parseManager/bin/Debug/parsetest2.txt
Normal file
66
parseManager/bin/Debug/parsetest2.txt
Normal 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"
|
||||||
|
}
|
||||||
@ -18,57 +18,57 @@ namespace parseManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class parseManager
|
public class parseManager
|
||||||
{
|
{
|
||||||
string filepath;
|
string _filepath;
|
||||||
bool hasDefine;
|
bool _hasDefine;
|
||||||
string define;
|
string _define;
|
||||||
string entry="START";
|
string _entry="START";
|
||||||
Type defineType;
|
Type _defineType;
|
||||||
MethodInfo defineMethod;
|
MethodInfo _defineMethod;
|
||||||
object defineClassObject;
|
object _defineClassObject;
|
||||||
Dictionary<string, string> chunks = new Dictionary<string, string>();
|
Dictionary<string, string> _chunks = new Dictionary<string, string>();
|
||||||
private void parse(){
|
private void parse(){
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StreamReader sr = File.OpenText (filepath);
|
StreamReader sr = File.OpenText (_filepath);
|
||||||
string CDFDATA = sr.ReadToEnd ();
|
string CDFDATA = sr.ReadToEnd ();
|
||||||
string pattern = @"\[(.+)\][\r\n]*?\{([^\0]+?)\}";
|
string pattern = @"\[(.+)\][\r\n]*?\{([^\0]+?)\}";
|
||||||
var match = Regex.Matches( CDFDATA, pattern );
|
var match = Regex.Matches( CDFDATA, pattern );
|
||||||
foreach (Match m in match)
|
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)
|
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)
|
public parseManager(string filepath)
|
||||||
{
|
{
|
||||||
this.filepath=filepath;
|
_filepath=filepath;
|
||||||
hasDefine=false;
|
_hasDefine=false;
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
public parseManager(string filepath,string define){
|
public parseManager(string filepath,string define){
|
||||||
this.define=define;
|
_define=define;
|
||||||
hasDefine=true;
|
_hasDefine=true;
|
||||||
this.filepath=filepath;
|
_filepath=filepath;
|
||||||
defineType = Type.GetType(define);
|
_defineType = Type.GetType(define);
|
||||||
ConstructorInfo defineConstructor = defineType.GetConstructor(Type.EmptyTypes);
|
ConstructorInfo defineConstructor = _defineType.GetConstructor(Type.EmptyTypes);
|
||||||
defineClassObject = defineConstructor.Invoke(new object[]{});
|
_defineClassObject = defineConstructor.Invoke(new object[]{});
|
||||||
parse();
|
parse();
|
||||||
}
|
}
|
||||||
public int invokeA(string method, object[] args){ // TODO collect the returned arguments if any
|
public int invokeA(string method, object[] args){ // TODO collect the returned arguments if any
|
||||||
if (!hasDefine)
|
if (!_hasDefine)
|
||||||
return -1;
|
return -1;
|
||||||
defineMethod = defineType.GetMethod(method);
|
_defineMethod = _defineType.GetMethod(method);
|
||||||
defineMethod.Invoke(defineClassObject, args);
|
_defineMethod.Invoke(_defineClassObject, args);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public int invokeNA(string method, object[] args){ // Simple Invoking!
|
public int invokeNA(string method, object[] args){ // Simple Invoking!
|
||||||
if (!hasDefine)
|
if (!_hasDefine)
|
||||||
return -1;
|
return -1;
|
||||||
defineMethod = defineType.GetMethod(method);
|
_defineMethod = _defineType.GetMethod(method);
|
||||||
defineMethod.Invoke(defineClassObject, args);
|
_defineMethod.Invoke(_defineClassObject, args);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public nextType next(){
|
public nextType next(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user