Beispiel #1
0
 public PropertyObject(string pName, bool pIsPublic)
 {
     isPublic    = pIsPublic;
     name        = pName;
     parseState  = eParseShate.Start;
     getFunction = null;
     setFunction = null;
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }