private bool processCode() { currentObject = null; while (oWordEngine.NextLine()) { while (oWordEngine.NextWord != null) { #region Main Processor switch (oWordEngine.Current.ToLower()) { case "class": if (validateName(oWordEngine.NextNonWhitespace)) { currentObject = new ClassObject(oWordEngine.Current); } else { errors.Add(oWordEngine.FormatedPosition + "The name " + oWordEngine.Current + " is not a valid name for a class.\r\n" + oWordEngine.GetLineWithPositionMarker); return(false); } break; default: if (currentObject == null) { errors.Add(oWordEngine.FormatedPosition + "Expecting class definition, found " + oWordEngine.Current + "." + oWordEngine.GetLineWithPositionMarker); return(false); } if (!currentObject.Parse(oWordEngine)) { if (currentObject.HasParseError || !currentObject.IsParseComplete) { if (currentObject.HasParseError) { errors.Add(oWordEngine.FormatedPosition + currentObject.ParseError + "\r\n" + oWordEngine.GetLineWithPositionMarker); } else { errors.Add(oWordEngine.FormatedPosition + "Compiler error! ClassObject parser returned false, but is not complete." + oWordEngine.GetLineWithPositionMarker); } return(false); } else { KOSObjects.Add(currentObject); } } break; } #endregion } } if (oWordEngine.HasError) { errors.Add(oWordEngine.FormatedPosition + oWordEngine.Error + "\r\n" + oWordEngine.GetLineWithPositionMarker); return(false); } return(true); }
public bool Parse(WordEngine oWordEngine) { done = false; error = null; name = ""; value = ""; isSet = false; if (oWordEngine.Current == "set") { name = oWordEngine.NextNonWhitespace; IKOSppObject nameObject = KOSObjects.SingleOrDefault(x => x.Name == name); if (nameObject != null && nameObject.GetType() == typeof(PropertyObject)) { isSet = true; } else { name = Phase2Compiler.changeVariable(name, KOSObjects); } if (name != null) { if (oWordEngine.NextNonWhitespace == "to") { while (oWordEngine.NextNonWhitespace != ".") { if (oWordEngine.Current == null) { error = "Expecting ., found end of file insted."; return(false); } else { value += Phase2Compiler.changeVariable(oWordEngine.Current, KOSObjects); } } done = true; if (isSet) { name = string.Format(nameObject.CallString(false), value); } return(true); } else { error = "Expecting to, found " + oWordEngine.Current + " insted."; } } else { error = "Expecting to, end of file insted."; } } else { error = "Expecting set, found " + oWordEngine.Current + " insted."; } return(false); }
private eParseShate addObject(IKOSppObject obj) { if (KOSObjects.Any(x => x.Name == obj.Name)) { parseError = "The object " + obj.Name + " has the same name a another object in this class."; return(eParseShate.Error); } else { KOSObjects.Add(obj); currentObject = null; } return(eParseShate.MainLoop); }
public static string changeVariable(string word, List <IKOSppObject> ObjectList) { IKOSppObject KOSObject = ObjectList.SingleOrDefault(x => x.Name == word); if (KOSObject != null) { if (KOSObject.GetType() == typeof(VariableObject)) { return(KOSObject.CallString()); } else if (KOSObject.GetType() == typeof(PropertyObject)) { return(KOSObject.CallString()); } } return(word); }
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); }