public VariableObject(String pName, bool pIsPublic) { isPublic = pIsPublic; name = pName; initValue = ""; parseState = eParseShate.Start; }
public ClassObject(string pName) { name = pName; KOSObjects = new List <IKOSppObject>(); parseState = eParseShate.Start; parseError = ""; }
public PropertyObject(string pName, bool pIsPublic) { isPublic = pIsPublic; name = pName; parseState = eParseShate.Start; getFunction = null; setFunction = null; }
public bool Parse(WordEngine oWordEngine) { switch (parseState) { case eParseShate.MainLoop: String word = oWordEngine.CurrentNonWhitespace; if (oWordEngine.IsBlockStart) { oWordEngine.RegisterBlockTest(this); } else { parseError = "Function " + name + " expecting a block."; parseState = eParseShate.Error; return(false); } string StartOfFunctionMarker = oWordEngine.GetLineWithPositionMarker; do { while (oWordEngine.NextWord != null && parseState == eParseShate.MainLoop) { if (oWordEngine.Current.Equals(".")) { code = code.TrimEnd(' ') + oWordEngine.Current + "\r\n"; } else { code += oWordEngine.Current; } } } while (parseState == eParseShate.MainLoop && oWordEngine.NextLine()); if (oWordEngine.Current == null) { parseState = eParseShate.Error; parseError = "Function " + name + " reached the end of file before finding the clock end.\r\n" + StartOfFunctionMarker; } return(false); case eParseShate.Done: return(false); case eParseShate.Error: if (!HasParseError) { parseError = "Compiler error! The parser " + name + " was put in Error state, but had no error."; } return(false); default: parseError = "Compiner error! Unhandled state in FunctionObject " + name + " : " + parseState.ToString(); parseState = eParseShate.Error; return(false); } }
public string BlockEnd() { if (parseState == eParseShate.MainLoop) { parseState = eParseShate.Done; return(null); } else { return("A block in function " + name + " ended outside of the main loop."); } }
public bool Parse(WordEngine oWordEngine) { //TODO: in the futuer I might want to check that this is a leagal init value for a parameter. while (oWordEngine.Current != null) { initValue += oWordEngine.Current; if (oWordEngine.NextNonWhitespace.Equals(".")) { parseState = eParseShate.Done; return(false); } } parseError = "Expecting . found end of file."; return(true); }
public FunctionObject(string pName, bool pIsPublic, string pInrernalName = null) { parameters = new List <string>(); name = pName; if (pInrernalName == null) { internalName = pName; } else { internalName = pInrernalName; } isPublic = pIsPublic; parseState = eParseShate.MainLoop; code = ""; }
public bool Parse(WordEngine oWordEngine) { switch (parseState) { case eParseShate.Start: if (!oWordEngine.RegisterBlockTest(this)) { parseState = eParseShate.Error; return(false); } parseState = eParseShate.MainLoop; break; case eParseShate.MainLoop: switch (oWordEngine.CurrentNonWhitespace) { case "private": currentIsPublic = false; parseState = eParseShate.FuncVar; break; case "public": currentIsPublic = true; parseState = eParseShate.FuncVar; break; case "property": currentIsPublic = true; parseState = eParseShate.Property; break; case WordEngine.BlockEndChar: parseState = eParseShate.Done; return(false); default: if (oWordEngine.HasError) { parseError = oWordEngine.Error; } else { parseError = "Expecting private public or property, found " + oWordEngine.Current; } parseState = eParseShate.Error; return(false); } break; case eParseShate.SendWordsEngineToObject: if (currentObject == null) { parseError = "Compiler error! trying to send the word " + oWordEngine.Current + " to an null KOSObject."; return(false); } if (!currentObject.Parse(oWordEngine)) { if (currentObject.HasParseError || !currentObject.IsParseComplete) { if (currentObject.HasParseError) { parseError = currentObject.ParseError; } else { parseError = "Compiler error! Parser " + currentObject.Name + " returned false, but is not complete and has no errors."; } return(false); } else { parseState = addObject(currentObject); } } break; case eParseShate.Property: if (validateName(oWordEngine.NextNonWhitespace)) { currentObject = new PropertyObject(oWordEngine.Current, currentIsPublic); parseState = eParseShate.SendWordsEngineToObject; } else { parseError = "The name " + oWordEngine.Current + " is not a valid name for a property."; parseState = eParseShate.Error; return(false); } break; case eParseShate.FuncVar: string funcVarName = oWordEngine.CurrentNonWhitespace; if (oWordEngine.NextNonWhitespace.Equals("(")) //function { if (validateName(funcVarName)) { currentObject = new FunctionObject(funcVarName, currentIsPublic); parseState = eParseShate.GetFuncPrams; canGetParameter = true; } else { parseError = "The name " + oWordEngine.Current + " is not a valid name for a function."; parseState = eParseShate.Error; return(false); } } else if (oWordEngine.Current.Equals("=") || oWordEngine.Current.Equals(".")) { if (validateName(oWordEngine.Current)) { currentObject = new VariableObject(funcVarName, currentIsPublic); if (oWordEngine.Current.Equals("=")) { parseState = eParseShate.SendWordsEngineToObject; } else { parseState = addObject(currentObject); } } else { parseError = "The name " + funcVarName + " is not a valid name for a variable."; parseState = eParseShate.Error; return(false); } } else { parseState = eParseShate.Error; parseError = "Expecting ( = or ., found " + oWordEngine.Current; return(false); } break; case eParseShate.GetFuncPrams: if (oWordEngine.CurrentNonWhitespace.Equals(")")) { parseState = eParseShate.SendWordsEngineToObject; } else if (oWordEngine.Current.Equals(",")) { if (canGetParameter) { parseError = "Expecting to find a paramter and found a , insted."; parseState = eParseShate.Error; return(false); } else { canGetParameter = true; } } else if (canGetParameter) { if (validateName(oWordEngine.Current)) { FunctionObject func = currentObject as FunctionObject; if (func != null) { if (!func.AddParameter(oWordEngine.Current)) { parseError = "The function " + func.Name + " has two parameters withe the same name (" + oWordEngine.Current + ")."; parseState = eParseShate.Error; return(false); } else { canGetParameter = false; } } else { parseError = "Compiler error! Expecting a type of function object in currentObject(IKOSppObject)."; parseState = eParseShate.Error; return(false); } } else { parseError = "The name " + oWordEngine.Current + " is not a valid name for a function parameter."; parseState = eParseShate.Error; return(false); } } else { parseError = "Expecting to find a , or ) but found " + oWordEngine.Current + " insted"; parseState = eParseShate.Error; return(false); } break; case eParseShate.Error: if (!HasParseError) { parseError = "Compiler error! The parser " + name + " was put in Error state, but had no error."; } return(false); case eParseShate.Done: return(false); default: parseError = "Compiner error! Unhandled state in ClassObject: " + name + "" + parseState.ToString(); parseState = eParseShate.Error; return(false); } return(true); }
public bool Parse(WordEngine oWordEngine) { switch (parseState) { case eParseShate.Start: if (!oWordEngine.RegisterBlockTest(this)) { parseState = eParseShate.Error; return(false); } parseState = eParseShate.MainLoop; break; case eParseShate.MainLoop: switch (oWordEngine.CurrentNonWhitespace) { case "get": if (getFunction == null) { getFunction = new FunctionObject("get", false, "_get" + name); currentObject = getFunction; } else { parseError = "The can only be one get in a propety."; parseState = eParseShate.Error; return(false); } break; case "set": if (setFunction == null) { setFunction = new FunctionObject("set", false, "_set" + name); setFunction.AddParameter("value"); currentObject = setFunction; } else { parseError = "The can only be one set in a propety."; parseState = eParseShate.Error; return(false); } break; case WordEngine.BlockEndChar: parseState = eParseShate.Done; return(false); default: if (oWordEngine.HasError) { parseError = oWordEngine.Error; } else { parseError = "Expecting get or set, found " + oWordEngine.Current; } parseState = eParseShate.Error; return(false); } parseState = eParseShate.SendWordsEngineToObject; break; case eParseShate.SendWordsEngineToObject: if (currentObject == null) { parseError = "Compiler error! trying to send the word " + oWordEngine.Current + " to an null KOSObject."; return(false); } if (!currentObject.Parse(oWordEngine)) { if (currentObject.HasParseError || !currentObject.IsParseComplete) { if (currentObject.HasParseError) { parseError = currentObject.ParseError; } else { parseError = "Compiler error! Parser " + currentObject.Name + " returned false, but is not complete and has no errors."; } return(false); } else { parseState = eParseShate.MainLoop; } } break; case eParseShate.Done: return(false); case eParseShate.Error: if (!HasParseError) { parseError = "Compiler error! The parser " + name + " was put in Error state, but had no error."; } return(false); default: parseError = "Compiner error! Unhandled state in PropertyObject: " + name + "" + parseState.ToString(); parseState = eParseShate.Error; return(false); } return(true); }