Happy with current progress...
This commit is contained in:
parent
f07975965b
commit
81c9ae229b
@ -7,9 +7,10 @@
|
|||||||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using parseManager; // IMPORTANT
|
||||||
public class define : standardParseDefine // If you want the standard methods you must include this
|
public class define : standardParseDefine // If you want the standard methods you must include this
|
||||||
{
|
{
|
||||||
public void testM(string arg1)
|
public void testM(object arg1)
|
||||||
{
|
{
|
||||||
Console.WriteLine(arg1);
|
Console.WriteLine(arg1);
|
||||||
}
|
}
|
||||||
@ -17,6 +18,23 @@ public class define : standardParseDefine // If you want the standard methods yo
|
|||||||
{
|
{
|
||||||
Console.WriteLine(arg1 + " it works!!!");
|
Console.WriteLine(arg1 + " it works!!!");
|
||||||
}
|
}
|
||||||
|
public void TEST()
|
||||||
|
{
|
||||||
|
var test=GLOBALS.GetPM();
|
||||||
|
var env=test.GetENV();
|
||||||
|
Console.WriteLine(env["test"]);
|
||||||
|
}
|
||||||
|
public void TEST2(object msg)
|
||||||
|
{
|
||||||
|
Console.WriteLine(msg);
|
||||||
|
}
|
||||||
|
public void TEST3(double msg, string msg2)
|
||||||
|
{
|
||||||
|
Console.WriteLine(msg + "|" + msg2);
|
||||||
|
}
|
||||||
|
public double TEST4(double num){
|
||||||
|
return num+1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
namespace parseManager
|
namespace parseManager
|
||||||
{
|
{
|
||||||
@ -25,9 +43,17 @@ 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"); // define is where your methods will be held
|
||||||
|
var env = test.GetENV();
|
||||||
|
env["test"]="TEST!";
|
||||||
|
env["test2"]=12345;
|
||||||
nextType next = test.Next(); // TODO implement the next method
|
nextType next = test.Next(); // TODO implement the next method
|
||||||
|
string type;
|
||||||
while(next.GetCMDType()!="EOF"){
|
while(next.GetCMDType()!="EOF"){
|
||||||
Console.Write(next.GetText());
|
type = next.GetCMDType();
|
||||||
|
if(type=="line"){
|
||||||
|
Console.Write(next.GetText());
|
||||||
|
Console.ReadLine();
|
||||||
|
}
|
||||||
next = test.Next();
|
next = test.Next();
|
||||||
}
|
}
|
||||||
//var temp=test.InvokeR("TEST",new object[]{});
|
//var temp=test.InvokeR("TEST",new object[]{});
|
||||||
|
|||||||
@ -1,68 +1,11 @@
|
|||||||
ENTRY START
|
ENTRY START
|
||||||
LOAD test.dat
|
ENABLE debugging
|
||||||
[START]{
|
[START]{
|
||||||
a=10>1
|
"Hello!"
|
||||||
b=10<1
|
"NO!"
|
||||||
"test: $a$ $b$"
|
TEST()
|
||||||
test["name"]="Ryan"
|
TEST2("food is $test$")
|
||||||
name=test["name"]
|
TEST3(12345,test)
|
||||||
-- test
|
num=TEST4(15)
|
||||||
"Hi $test[name]$! $name$"
|
TEST2(num)
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
@ -11,6 +11,7 @@ using System.IO;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using parseManager;
|
||||||
namespace parseManager
|
namespace parseManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -26,17 +27,23 @@ namespace parseManager
|
|||||||
MethodInfo _defineMethod;
|
MethodInfo _defineMethod;
|
||||||
object _defineClassObject;
|
object _defineClassObject;
|
||||||
chunk _currentChunk;
|
chunk _currentChunk;
|
||||||
chunk _lastChunk=null;
|
chunk _lastChunk = null;
|
||||||
readonly ENV _mainENV = new ENV();
|
readonly ENV _mainENV = new ENV();
|
||||||
ENV _defualtENV = _mainENV;
|
public ENV _defualtENV;
|
||||||
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>();
|
||||||
void InitFlags(){
|
void InitFlags()
|
||||||
_flags.Add("leaking",false);
|
{
|
||||||
_flags.Add("forseelabels",true);
|
_flags.Add("leaking", false);
|
||||||
_flags.Add("debugging",false);
|
_flags.Add("forseelabels", true);
|
||||||
_flags.Add("topdown",true);
|
_flags.Add("debugging", false);
|
||||||
|
_flags.Add("topdown", true);
|
||||||
|
}
|
||||||
|
void debug(object msg)
|
||||||
|
{
|
||||||
|
if (_flags["debugging"])
|
||||||
|
Console.WriteLine(msg);
|
||||||
}
|
}
|
||||||
void _Parse(string data)
|
void _Parse(string data)
|
||||||
{
|
{
|
||||||
@ -57,14 +64,14 @@ namespace parseManager
|
|||||||
int loc = Blck.IndexOf(":");
|
int loc = Blck.IndexOf(":");
|
||||||
if (loc != -1) {
|
if (loc != -1) {
|
||||||
_chunks[Blck.Substring(0, loc)] = new chunk(Blck.Substring(0, loc), Cont, Blck.Substring(loc + 1));
|
_chunks[Blck.Substring(0, loc)] = new chunk(Blck.Substring(0, loc), Cont, Blck.Substring(loc + 1));
|
||||||
Blck=Blck.Substring(0, loc);
|
Blck = Blck.Substring(0, loc);
|
||||||
} else {
|
} else {
|
||||||
_chunks[Blck] = new chunk(Blck, Cont);
|
_chunks[Blck] = new chunk(Blck, Cont);
|
||||||
}
|
}
|
||||||
if(_lastChunk!=null){
|
if (_lastChunk != null) {
|
||||||
_lastChunk.SetNextChunk(_chunks[Blck]);
|
_lastChunk.SetNextChunk(_chunks[Blck]);
|
||||||
}
|
}
|
||||||
_lastChunk=_chunks[Blck];
|
_lastChunk = _chunks[Blck];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Parse()
|
void Parse()
|
||||||
@ -94,6 +101,7 @@ namespace parseManager
|
|||||||
InitFlags();
|
InitFlags();
|
||||||
_filepath = filepath;
|
_filepath = filepath;
|
||||||
_hasDefine = false;
|
_hasDefine = false;
|
||||||
|
_defualtENV = _mainENV;
|
||||||
Parse();
|
Parse();
|
||||||
}
|
}
|
||||||
public parseManager(string filepath, string define)
|
public parseManager(string filepath, string define)
|
||||||
@ -105,6 +113,7 @@ namespace parseManager
|
|||||||
_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[]{ });
|
||||||
|
_defualtENV = _mainENV;
|
||||||
Parse();
|
Parse();
|
||||||
}
|
}
|
||||||
public object InvokeR(string method, object[] args)
|
public object InvokeR(string method, object[] args)
|
||||||
@ -131,14 +140,17 @@ namespace parseManager
|
|||||||
PushError("Attempt to JUMP to a non existing block!");
|
PushError("Attempt to JUMP to a non existing block!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public ENV GetENV(){
|
public ENV GetENV()
|
||||||
|
{
|
||||||
return _defualtENV;
|
return _defualtENV;
|
||||||
}
|
}
|
||||||
public void SetENV(){
|
public void SetENV()
|
||||||
_defualtENV=_mainENV;
|
{
|
||||||
|
_defualtENV = _mainENV;
|
||||||
}
|
}
|
||||||
public void SetENV(ENV o){
|
public void SetENV(ENV o)
|
||||||
_defualtENV=o;
|
{
|
||||||
|
_defualtENV = o;
|
||||||
}
|
}
|
||||||
public void SetBlock(chunk BLOCK)
|
public void SetBlock(chunk BLOCK)
|
||||||
{
|
{
|
||||||
@ -164,36 +176,260 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
return Next();
|
return Next();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* THE NEXT METHOD
|
|
||||||
*/
|
|
||||||
public nextType Next()
|
public nextType Next()
|
||||||
{
|
{
|
||||||
|
GLOBALS.SetPM(this);
|
||||||
nextType tempReturn = new nextType();
|
nextType tempReturn = new nextType();
|
||||||
if (_currentChunk == null) {
|
if (_currentChunk == null) {
|
||||||
SetBlock();
|
SetBlock();
|
||||||
}
|
}
|
||||||
// TODO Add commands lol
|
// TODO Add commands lol
|
||||||
string currentline = _currentChunk.GetLine();
|
//Console.WriteLine(_currentChunk.GetPos());
|
||||||
if (currentline == null) {
|
CMD cCMD = _currentChunk.GetCLine();
|
||||||
|
object[] stuff;
|
||||||
|
if (cCMD == null) {
|
||||||
if (_flags["leaking"]) {
|
if (_flags["leaking"]) {
|
||||||
SetBlock(_currentChunk.GetNextChunk());
|
SetBlock(_currentChunk.GetNextChunk());
|
||||||
return Next();
|
return Next();
|
||||||
|
}
|
||||||
|
tempReturn.SetCMDType("EOF");
|
||||||
|
tempReturn.SetText("Reached the end of the file!");
|
||||||
|
return tempReturn;
|
||||||
|
}
|
||||||
|
string type = cCMD.GetCMDType();
|
||||||
|
stuff = cCMD.GetArgs();
|
||||||
|
//Console.WriteLine(type);
|
||||||
|
if (type == "FUNC") {
|
||||||
|
string func = (string)stuff[0];
|
||||||
|
string[] args = (string[])stuff[1];
|
||||||
|
//debug(args.Length);
|
||||||
|
if (args.Length == 1 && args[0] == "") { // assume no args inserted!
|
||||||
|
InvokeNR(func, new object[]{ });
|
||||||
} else {
|
} else {
|
||||||
tempReturn.SetCMDType("EOF");
|
InvokeNR(func, ResolveVar(args));
|
||||||
tempReturn.SetText("Reached the end of the file!");
|
}
|
||||||
return tempReturn;
|
tempReturn.SetCMDType("method");
|
||||||
|
tempReturn.SetText("INVOKED METHOD: " + func);
|
||||||
|
} else if (type == "LINE") {
|
||||||
|
//Console.WriteLine(stuff[0]);
|
||||||
|
tempReturn.SetCMDType("line");
|
||||||
|
tempReturn.SetText(parseHeader((string)stuff[0]));
|
||||||
|
}
|
||||||
|
return tempReturn;
|
||||||
|
}
|
||||||
|
public string parseHeader(string header)
|
||||||
|
{
|
||||||
|
var results = Regex.Matches(header, @"(\$.*?\$)");
|
||||||
|
int len = results.Count;
|
||||||
|
string str;
|
||||||
|
object temp;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
str = results[i].ToString();
|
||||||
|
if (isVar(str.Substring(1, str.Length - 2), out temp)) {
|
||||||
|
header = header.Replace(results[i].ToString(), temp.ToString());
|
||||||
|
} else {
|
||||||
|
header = header.Replace(results[i].ToString(), "null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var FuncWReturn = Regex.Match(currentline, "([\\[\\]\"a-zA-Z0-9_,]+)\\s?=\\s?([a-zA-Z0-9_]+)\\s?\\((.+)\\)");
|
return header;
|
||||||
var FuncWOReturn = Regex.Match(currentline, @"^([a-zA-Z0-9_]+)\s?\((.+)\)");
|
}
|
||||||
// FuncWOReturn. // TODO Fix This stuff
|
public object[] ResolveVar(string[] v)
|
||||||
return tempReturn;
|
{
|
||||||
|
//_defualtENV
|
||||||
|
int len = v.Length;
|
||||||
|
object[] args = new object[len];
|
||||||
|
object val;
|
||||||
|
double num;
|
||||||
|
bool boo;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (isVar(v[i], out val)) {
|
||||||
|
args[i] = val;
|
||||||
|
} else if (double.TryParse(v[i], out num)) {
|
||||||
|
args[i] = num;
|
||||||
|
debug("NUMBER: " + num);
|
||||||
|
} else if (v[i][0] == '"' && v[i][v[i].Length - 1] == '"') {
|
||||||
|
args[i] = parseHeader(v[i].Substring(1, v[i].Length - 2));
|
||||||
|
debug("STRING: " + args[i]);
|
||||||
|
} else if (bool.TryParse(v[i], out boo)) {
|
||||||
|
args[i] = boo;
|
||||||
|
debug("BOOL: " + boo);
|
||||||
|
} else {
|
||||||
|
args[i] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
public bool isVar(string val, out object v)
|
||||||
|
{
|
||||||
|
if (_defualtENV[val] != null) {
|
||||||
|
v = _defualtENV[val];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
v = null;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Helper Classes
|
* Helper Classes
|
||||||
*/
|
*/
|
||||||
|
public class chunk
|
||||||
|
{
|
||||||
|
string _BLOCK;
|
||||||
|
string _type;
|
||||||
|
string _pureType;
|
||||||
|
string[] _lines;
|
||||||
|
List<CMD> _compiledlines = new List<CMD>();
|
||||||
|
int _pos = 0;
|
||||||
|
chunk _next = null;
|
||||||
|
void _clean(string cont)
|
||||||
|
{
|
||||||
|
var m = Regex.Match(_type, @"([a-zA-Z0-9_]+)");
|
||||||
|
_pureType = m.Groups[1].ToString();
|
||||||
|
string tCont = Regex.Replace(cont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline);
|
||||||
|
tCont = Regex.Replace(tCont, @"\-\-.+\r\n", "", RegexOptions.Multiline);
|
||||||
|
tCont = Regex.Replace(tCont, @"\-\-.+\n", "", RegexOptions.Multiline);
|
||||||
|
tCont = Regex.Replace(tCont, @"\t", "", RegexOptions.Multiline);
|
||||||
|
tCont = Regex.Replace(tCont, @"\n\n", "", RegexOptions.Multiline);
|
||||||
|
tCont = Regex.Replace(tCont, @"\r\n\r\n", "", RegexOptions.Multiline);
|
||||||
|
tCont = Regex.Replace(tCont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline);
|
||||||
|
tCont = Regex.Replace(tCont, @"^\s+$[\r\n]*", "", RegexOptions.Multiline);
|
||||||
|
_lines = tCont.Split(new [] { "\r\n", "\n" }, StringSplitOptions.None);
|
||||||
|
compile(); // compiles the code into something that can beused quickly
|
||||||
|
}
|
||||||
|
void compile()
|
||||||
|
{
|
||||||
|
string temp;
|
||||||
|
for (int i = 0; i < _lines.Length - 1; i++) {
|
||||||
|
temp = _lines[i];
|
||||||
|
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 pureLine = Regex.Match(temp, "^\"(.+)\"");
|
||||||
|
if (FuncWReturn.ToString() != "") {
|
||||||
|
string var1 = (FuncWReturn.Groups[1]).ToString();
|
||||||
|
string func = (FuncWReturn.Groups[2]).ToString();
|
||||||
|
string args = (FuncWReturn.Groups[3]).ToString();
|
||||||
|
string[] retargs = var1.Split(',');
|
||||||
|
string[] result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
||||||
|
_compiledlines.Add(new CMD("FUNC_R", new object[] {
|
||||||
|
retargs,
|
||||||
|
func,
|
||||||
|
result
|
||||||
|
}));
|
||||||
|
//Console.WriteLine("FUNV_R: "+i);
|
||||||
|
} else if (FuncWOReturn.ToString() != "") {
|
||||||
|
string func = (FuncWOReturn.Groups[1]).ToString();
|
||||||
|
string args = (FuncWOReturn.Groups[2]).ToString();
|
||||||
|
string[] result = Regex.Split(args, ",(?=(?:[^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
||||||
|
_compiledlines.Add(new CMD("FUNC", new object[]{ func, result }));
|
||||||
|
//Console.WriteLine("FUNC: "+i);
|
||||||
|
} else if (pureLine.ToString() != "") {
|
||||||
|
_compiledlines.Add(new CMD("LINE", new object[]{ pureLine.ToString() }));
|
||||||
|
//Console.WriteLine("LINE: "+i);
|
||||||
|
} else {
|
||||||
|
_compiledlines.Add(new CMD("UNKNOWN", new object[]{ }));
|
||||||
|
//Console.WriteLine("UNKNOWN: "+i);
|
||||||
|
}
|
||||||
|
//Console.WriteLine(_compiledlines[i].GetCMDType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public chunk(string name, string cont, string type)
|
||||||
|
{
|
||||||
|
_BLOCK = name;
|
||||||
|
_type = type;
|
||||||
|
_clean(cont);
|
||||||
|
}
|
||||||
|
public chunk(string name, string cont)
|
||||||
|
{
|
||||||
|
_BLOCK = name;
|
||||||
|
_type = "CODEBLOCK";
|
||||||
|
_clean(cont);
|
||||||
|
}
|
||||||
|
public void SetNextChunk(chunk next)
|
||||||
|
{
|
||||||
|
_next = next;
|
||||||
|
}
|
||||||
|
public chunk GetNextChunk()
|
||||||
|
{
|
||||||
|
return _next;
|
||||||
|
}
|
||||||
|
public chunk SetNextChunk()
|
||||||
|
{
|
||||||
|
return _next;
|
||||||
|
}
|
||||||
|
public string[] GetLines()
|
||||||
|
{
|
||||||
|
return _lines;
|
||||||
|
}
|
||||||
|
public string GetLine()
|
||||||
|
{
|
||||||
|
string temp = _lines[_pos];
|
||||||
|
if (_pos == _lines.Length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
public CMD GetCLine()
|
||||||
|
{
|
||||||
|
if (_pos < _compiledlines.Count) {
|
||||||
|
return _compiledlines[_pos++];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public int GetPos()
|
||||||
|
{
|
||||||
|
return _pos;
|
||||||
|
}
|
||||||
|
public void SetPos(int n)
|
||||||
|
{
|
||||||
|
_pos = n;
|
||||||
|
}
|
||||||
|
public void ResetPos()
|
||||||
|
{
|
||||||
|
_pos = 0;
|
||||||
|
}
|
||||||
|
public string GetChunkPType()
|
||||||
|
{
|
||||||
|
return _pureType;
|
||||||
|
}
|
||||||
|
public string GetChunkType()
|
||||||
|
{
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class ENV
|
||||||
|
{
|
||||||
|
ENV _Parent;
|
||||||
|
Dictionary<string, object> _vars = new Dictionary<string, object>();
|
||||||
|
void SetParent(ENV other)
|
||||||
|
{
|
||||||
|
_Parent = other;
|
||||||
|
}
|
||||||
|
public bool TryGetValue(string ind, out object obj)
|
||||||
|
{
|
||||||
|
if (this[ind] != null) {
|
||||||
|
obj = this[ind];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
obj = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public object this[string ind] {
|
||||||
|
get {
|
||||||
|
object obj;
|
||||||
|
if (_vars.TryGetValue(ind, out obj)) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (_Parent != null) {
|
||||||
|
return _Parent[ind];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
_vars[ind] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public class nextType
|
public class nextType
|
||||||
{
|
{
|
||||||
string _type;
|
string _type;
|
||||||
@ -232,123 +468,48 @@ namespace parseManager
|
|||||||
_other[varname] = data;
|
_other[varname] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CMD
|
public class CMD
|
||||||
{
|
{
|
||||||
string _line;
|
|
||||||
parseManager _parse;
|
|
||||||
public CMD(string line,parseManager parse){
|
|
||||||
_line=line;
|
|
||||||
_parse=parse;
|
|
||||||
}
|
|
||||||
public void Run(){
|
|
||||||
// TODO Finish this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class chunk
|
|
||||||
{
|
|
||||||
string _BLOCK;
|
|
||||||
string _type;
|
string _type;
|
||||||
string _pureType;
|
object[] _args;
|
||||||
string[] lines;
|
public CMD(string type, object[] args)
|
||||||
int _pos = 0;
|
|
||||||
chunk _next=null;
|
|
||||||
void _clean(string cont)
|
|
||||||
{
|
{
|
||||||
var m = Regex.Match(_type, @"([a-zA-Z0-9_]+)");
|
|
||||||
_pureType = m.Groups[1].ToString();
|
|
||||||
string tCont = Regex.Replace(cont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline);
|
|
||||||
tCont = Regex.Replace(tCont, @"\-\-.+\r\n", "", RegexOptions.Multiline);
|
|
||||||
tCont = Regex.Replace(tCont, @"\-\-.+\n", "", RegexOptions.Multiline);
|
|
||||||
tCont = Regex.Replace(tCont, @"\t", "", RegexOptions.Multiline);
|
|
||||||
tCont = Regex.Replace(tCont, @"\n\n", "", RegexOptions.Multiline);
|
|
||||||
tCont = Regex.Replace(tCont, @"\r\n\r\n", "", RegexOptions.Multiline);
|
|
||||||
tCont = Regex.Replace(tCont, @"\-\-\[\[[\S\s]+\]\]", "", RegexOptions.Multiline);
|
|
||||||
tCont = Regex.Replace(tCont, @"^\s+$[\r\n]*", "", RegexOptions.Multiline);
|
|
||||||
lines = tCont.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
|
|
||||||
}
|
|
||||||
public chunk(string name, string cont, string type)
|
|
||||||
{
|
|
||||||
_BLOCK = name;
|
|
||||||
_type = type;
|
_type = type;
|
||||||
_clean(cont);
|
_args = args;
|
||||||
}
|
}
|
||||||
public chunk(string name, string cont)
|
public string GetCMDType()
|
||||||
{
|
|
||||||
_BLOCK = name;
|
|
||||||
_type = "CODEBLOCK";
|
|
||||||
_clean(cont);
|
|
||||||
}
|
|
||||||
public void SetNextChunk(chunk next){
|
|
||||||
_next=next;
|
|
||||||
}
|
|
||||||
public chunk GetNextChunk(){
|
|
||||||
return _next;
|
|
||||||
}
|
|
||||||
public chunk SetNextChunk(){
|
|
||||||
return _next;
|
|
||||||
}
|
|
||||||
public string[] GetLines()
|
|
||||||
{
|
|
||||||
return lines;
|
|
||||||
}
|
|
||||||
public string GetLine()
|
|
||||||
{
|
|
||||||
string temp = lines[_pos++];
|
|
||||||
if (_pos == lines.Length) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
public int GetPos()
|
|
||||||
{
|
|
||||||
return _pos;
|
|
||||||
}
|
|
||||||
public void SetPos(int n)
|
|
||||||
{
|
|
||||||
_pos = n;
|
|
||||||
}
|
|
||||||
public void ResetPos()
|
|
||||||
{
|
|
||||||
_pos = 0;
|
|
||||||
}
|
|
||||||
public string GetChunkPType()
|
|
||||||
{
|
|
||||||
return _pureType;
|
|
||||||
}
|
|
||||||
public string GetChunkType()
|
|
||||||
{
|
{
|
||||||
return _type;
|
return _type;
|
||||||
}
|
}
|
||||||
}
|
public object[] GetArgs()
|
||||||
public class ENV
|
{
|
||||||
{
|
return _args;
|
||||||
ENV _Parent;
|
|
||||||
Dictionary<string, object> _vars = new Dictionary<string, object>();
|
|
||||||
public void SetParent(ENV other){
|
|
||||||
_Parent=other;
|
|
||||||
}
|
}
|
||||||
object this[string ind]{
|
}
|
||||||
get{
|
/*
|
||||||
object obj;
|
* The Standard Methods!
|
||||||
if(_vars.TryGetValue(ind, out obj)){
|
*/
|
||||||
return obj;
|
static class GLOBALS
|
||||||
} else {
|
{
|
||||||
if(_Parent!=null){
|
static parseManager current;
|
||||||
return _Parent[ind];
|
static readonly ENV env = new ENV();
|
||||||
} else {
|
public static object GetData(string ind)
|
||||||
return null;
|
{
|
||||||
}
|
return env[ind];
|
||||||
}
|
}
|
||||||
}
|
public static void AddData(string ind, object data)
|
||||||
set{
|
{
|
||||||
_vars[ind] = value;
|
env[ind] = data;
|
||||||
}
|
}
|
||||||
|
public static void SetPM(parseManager o){
|
||||||
|
current=o;
|
||||||
|
}
|
||||||
|
public static parseManager GetPM(){
|
||||||
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* The Standard Methods!
|
|
||||||
*/
|
|
||||||
public class standardParseDefine
|
public class standardParseDefine
|
||||||
{
|
{
|
||||||
public void EXIT()
|
public void EXIT()
|
||||||
@ -391,7 +552,4 @@ public class standardParseDefine
|
|||||||
{
|
{
|
||||||
return a % b;
|
return a % b;
|
||||||
}
|
}
|
||||||
public int[] TEST(){
|
|
||||||
return new int[]{1,2,3};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user