still a WIP but much progress has been made
This commit is contained in:
parent
9fa39ada57
commit
f07975965b
@ -25,7 +25,12 @@ 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
|
||||||
test.Next(); // TODO implement the next method
|
nextType next = test.Next(); // TODO implement the next method
|
||||||
|
while(next.GetCMDType()!="EOF"){
|
||||||
|
Console.Write(next.GetText());
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,10 @@ LOAD test.dat
|
|||||||
[START]{
|
[START]{
|
||||||
a=10>1
|
a=10>1
|
||||||
b=10<1
|
b=10<1
|
||||||
--[[
|
|
||||||
Fat Comment Sigh...
|
|
||||||
]]
|
|
||||||
"test: $a$ $b$"
|
"test: $a$ $b$"
|
||||||
test["name"]="Ryan"
|
test["name"]="Ryan"
|
||||||
name=test["name"]
|
name=test["name"]
|
||||||
|
-- test
|
||||||
"Hi $test[name]$! $name$"
|
"Hi $test[name]$! $name$"
|
||||||
testfunc("hello",(5!),15@1)
|
testfunc("hello",(5!),15@1)
|
||||||
test("hello",sqrt(5!),(15@1)/2)
|
test("hello",sqrt(5!),(15@1)/2)
|
||||||
|
|||||||
@ -26,9 +26,18 @@ namespace parseManager
|
|||||||
MethodInfo _defineMethod;
|
MethodInfo _defineMethod;
|
||||||
object _defineClassObject;
|
object _defineClassObject;
|
||||||
chunk _currentChunk;
|
chunk _currentChunk;
|
||||||
|
chunk _lastChunk=null;
|
||||||
|
readonly ENV _mainENV = new ENV();
|
||||||
|
ENV _defualtENV = _mainENV;
|
||||||
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(){
|
||||||
|
_flags.Add("leaking",false);
|
||||||
|
_flags.Add("forseelabels",true);
|
||||||
|
_flags.Add("debugging",false);
|
||||||
|
_flags.Add("topdown",true);
|
||||||
|
}
|
||||||
void _Parse(string data)
|
void _Parse(string data)
|
||||||
{
|
{
|
||||||
string pattern = @"\[(.+)\][\r\n]*?\{([^\0]+?)\}";
|
string pattern = @"\[(.+)\][\r\n]*?\{([^\0]+?)\}";
|
||||||
@ -48,9 +57,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);
|
||||||
} else {
|
} else {
|
||||||
_chunks[Blck] = new chunk(Blck, Cont);
|
_chunks[Blck] = new chunk(Blck, Cont);
|
||||||
}
|
}
|
||||||
|
if(_lastChunk!=null){
|
||||||
|
_lastChunk.SetNextChunk(_chunks[Blck]);
|
||||||
|
}
|
||||||
|
_lastChunk=_chunks[Blck];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Parse()
|
void Parse()
|
||||||
@ -77,12 +91,14 @@ namespace parseManager
|
|||||||
}
|
}
|
||||||
public parseManager(string filepath)
|
public parseManager(string filepath)
|
||||||
{
|
{
|
||||||
|
InitFlags();
|
||||||
_filepath = filepath;
|
_filepath = filepath;
|
||||||
_hasDefine = false;
|
_hasDefine = false;
|
||||||
Parse();
|
Parse();
|
||||||
}
|
}
|
||||||
public parseManager(string filepath, string define)
|
public parseManager(string filepath, string define)
|
||||||
{
|
{
|
||||||
|
InitFlags();
|
||||||
_define = define;
|
_define = define;
|
||||||
_hasDefine = true;
|
_hasDefine = true;
|
||||||
_filepath = filepath;
|
_filepath = filepath;
|
||||||
@ -91,16 +107,14 @@ namespace parseManager
|
|||||||
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
_defineClassObject = defineConstructor.Invoke(new object[]{ });
|
||||||
Parse();
|
Parse();
|
||||||
}
|
}
|
||||||
public int InvokeR(string method, object[] args)
|
public object InvokeR(string method, object[] args)
|
||||||
{ // TODO collect the returned arguments if any
|
{ // TODO collect the returned arguments if any
|
||||||
if (!_hasDefine)
|
if (!_hasDefine)
|
||||||
return -1;
|
return null;
|
||||||
_defineMethod = _defineType.GetMethod(method);
|
_defineMethod = _defineType.GetMethod(method);
|
||||||
object rets = _defineMethod.Invoke(_defineClassObject, args);
|
return _defineMethod.Invoke(_defineClassObject, args);
|
||||||
Console.WriteLine(rets);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
public long InvokeNR(string method, object[] args)
|
public int InvokeNR(string method, object[] args)
|
||||||
{ // Simple Invoking!
|
{ // Simple Invoking!
|
||||||
if (!_hasDefine)
|
if (!_hasDefine)
|
||||||
return -1;
|
return -1;
|
||||||
@ -108,41 +122,71 @@ namespace parseManager
|
|||||||
_defineMethod.Invoke(_defineClassObject, args);
|
_defineMethod.Invoke(_defineClassObject, args);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public void SetBlock(string BLOCK){
|
public void SetBlock(string BLOCK)
|
||||||
|
{
|
||||||
chunk cchunk;
|
chunk cchunk;
|
||||||
if(_chunks.TryGetValue(BLOCK, out cchunk)){
|
if (_chunks.TryGetValue(BLOCK, out cchunk)) {
|
||||||
_currentChunk=cchunk;
|
_currentChunk = cchunk;
|
||||||
} else {
|
} else {
|
||||||
PushError("Attempt to JUMP to a non existing block!");
|
PushError("Attempt to JUMP to a non existing block!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void SetBlock(){
|
public ENV GetENV(){
|
||||||
|
return _defualtENV;
|
||||||
|
}
|
||||||
|
public void SetENV(){
|
||||||
|
_defualtENV=_mainENV;
|
||||||
|
}
|
||||||
|
public void SetENV(ENV o){
|
||||||
|
_defualtENV=o;
|
||||||
|
}
|
||||||
|
public void SetBlock(chunk BLOCK)
|
||||||
|
{
|
||||||
|
_currentChunk = BLOCK;
|
||||||
|
}
|
||||||
|
public void SetBlock()
|
||||||
|
{
|
||||||
chunk cchunk;
|
chunk cchunk;
|
||||||
if(_chunks.TryGetValue(_entry, out cchunk)){
|
if (_chunks.TryGetValue(_entry, out cchunk)) {
|
||||||
_currentChunk=cchunk;
|
_currentChunk = cchunk;
|
||||||
} else {
|
} else {
|
||||||
PushError("Entrypoint is Invalid!");
|
PushError("Entrypoint is Invalid!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void PushError(string err){
|
public void PushError(string err)
|
||||||
|
{
|
||||||
Console.WriteLine(err);
|
Console.WriteLine(err);
|
||||||
}
|
}
|
||||||
public nextType Next(string BLOCK)
|
public nextType Next(string BLOCK)
|
||||||
{
|
{
|
||||||
if(_currentChunk==null){
|
if (_currentChunk == null) {
|
||||||
SetBlock(BLOCK);
|
SetBlock(BLOCK);
|
||||||
}
|
}
|
||||||
return Next();
|
return Next();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* THE NEXT METHOD
|
||||||
|
*/
|
||||||
public nextType Next()
|
public nextType Next()
|
||||||
{
|
{
|
||||||
nextType tempReturn = new nextType("method");
|
nextType tempReturn = new nextType();
|
||||||
if(_currentChunk==null){
|
if (_currentChunk == null) {
|
||||||
SetBlock();
|
SetBlock();
|
||||||
}
|
}
|
||||||
// TODO Add commands lol
|
// TODO Add commands lol
|
||||||
var FuncWReturn = Regex.Match(_currentChunk.GetLine(), "([\\[\\]\"a-zA-Z0-9_,]+)\\s?=\\s?([a-zA-Z0-9_]+)\\s?\\((.+)\\)");
|
string currentline = _currentChunk.GetLine();
|
||||||
var FuncWOReturn = Regex.Match(_currentChunk.GetLine(), @"^([a-zA-Z0-9_]+)\s?\((.+)\)");
|
if (currentline == null) {
|
||||||
|
if (_flags["leaking"]) {
|
||||||
|
SetBlock(_currentChunk.GetNextChunk());
|
||||||
|
return Next();
|
||||||
|
} else {
|
||||||
|
tempReturn.SetCMDType("EOF");
|
||||||
|
tempReturn.SetText("Reached the end of the file!");
|
||||||
|
return tempReturn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var FuncWReturn = Regex.Match(currentline, "([\\[\\]\"a-zA-Z0-9_,]+)\\s?=\\s?([a-zA-Z0-9_]+)\\s?\\((.+)\\)");
|
||||||
|
var FuncWOReturn = Regex.Match(currentline, @"^([a-zA-Z0-9_]+)\s?\((.+)\)");
|
||||||
// FuncWOReturn. // TODO Fix This stuff
|
// FuncWOReturn. // TODO Fix This stuff
|
||||||
return tempReturn;
|
return tempReturn;
|
||||||
}
|
}
|
||||||
@ -155,11 +199,15 @@ namespace parseManager
|
|||||||
string _type;
|
string _type;
|
||||||
string _text;
|
string _text;
|
||||||
Dictionary<string, object> _other = new Dictionary<string, object>();
|
Dictionary<string, object> _other = new Dictionary<string, object>();
|
||||||
|
public nextType()
|
||||||
|
{
|
||||||
|
_type = "UNSET";
|
||||||
|
}
|
||||||
public nextType(string type)
|
public nextType(string type)
|
||||||
{
|
{
|
||||||
_type = type;
|
_type = type;
|
||||||
}
|
}
|
||||||
public string GetNextType()
|
public string GetCMDType()
|
||||||
{
|
{
|
||||||
return _type;
|
return _type;
|
||||||
}
|
}
|
||||||
@ -167,6 +215,10 @@ namespace parseManager
|
|||||||
{
|
{
|
||||||
_text = text;
|
_text = text;
|
||||||
}
|
}
|
||||||
|
public void SetCMDType(string type)
|
||||||
|
{
|
||||||
|
_type = type;
|
||||||
|
}
|
||||||
public string GetText()
|
public string GetText()
|
||||||
{
|
{
|
||||||
return _text;
|
return _text;
|
||||||
@ -180,6 +232,18 @@ namespace parseManager
|
|||||||
_other[varname] = data;
|
_other[varname] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
public class chunk
|
||||||
{
|
{
|
||||||
string _BLOCK;
|
string _BLOCK;
|
||||||
@ -187,6 +251,7 @@ namespace parseManager
|
|||||||
string _pureType;
|
string _pureType;
|
||||||
string[] lines;
|
string[] lines;
|
||||||
int _pos = 0;
|
int _pos = 0;
|
||||||
|
chunk _next=null;
|
||||||
void _clean(string cont)
|
void _clean(string cont)
|
||||||
{
|
{
|
||||||
var m = Regex.Match(_type, @"([a-zA-Z0-9_]+)");
|
var m = Regex.Match(_type, @"([a-zA-Z0-9_]+)");
|
||||||
@ -213,13 +278,26 @@ namespace parseManager
|
|||||||
_type = "CODEBLOCK";
|
_type = "CODEBLOCK";
|
||||||
_clean(cont);
|
_clean(cont);
|
||||||
}
|
}
|
||||||
|
public void SetNextChunk(chunk next){
|
||||||
|
_next=next;
|
||||||
|
}
|
||||||
|
public chunk GetNextChunk(){
|
||||||
|
return _next;
|
||||||
|
}
|
||||||
|
public chunk SetNextChunk(){
|
||||||
|
return _next;
|
||||||
|
}
|
||||||
public string[] GetLines()
|
public string[] GetLines()
|
||||||
{
|
{
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
public string GetLine()
|
public string GetLine()
|
||||||
{
|
{
|
||||||
return lines[_pos++];
|
string temp = lines[_pos++];
|
||||||
|
if (_pos == lines.Length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
public int GetPos()
|
public int GetPos()
|
||||||
{
|
{
|
||||||
@ -242,12 +320,45 @@ namespace parseManager
|
|||||||
return _type;
|
return _type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class ENV
|
||||||
|
{
|
||||||
|
ENV _Parent;
|
||||||
|
Dictionary<string, object> _vars = new Dictionary<string, object>();
|
||||||
|
public void SetParent(ENV other){
|
||||||
|
_Parent=other;
|
||||||
|
}
|
||||||
|
object this[string ind]{
|
||||||
|
get{
|
||||||
|
object obj;
|
||||||
|
if(_vars.TryGetValue(ind, out obj)){
|
||||||
|
return obj;
|
||||||
|
} else {
|
||||||
|
if(_Parent!=null){
|
||||||
|
return _Parent[ind];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set{
|
||||||
|
_vars[ind] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* The Standard Methods!
|
* The Standard Methods!
|
||||||
*/
|
*/
|
||||||
public class standardParseDefine
|
public class standardParseDefine
|
||||||
{
|
{
|
||||||
|
public void EXIT()
|
||||||
|
{
|
||||||
|
// TODO Exit the script
|
||||||
|
}
|
||||||
|
public void QUIT()
|
||||||
|
{
|
||||||
|
// TODO Quit the script
|
||||||
|
}
|
||||||
public void GOTO(string label)
|
public void GOTO(string label)
|
||||||
{
|
{
|
||||||
// TODO goto a label in the script
|
// TODO goto a label in the script
|
||||||
@ -280,4 +391,7 @@ 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