Exemplo n.º 1
0
        public static Node ToNode(string rhs)
        {
            Game g = Game.GetInstance();

            rhs = rhs.Trim();
            int result;

            if (Int32.TryParse(rhs, out result))
            {
                return(new Constant(result));
            }
            else if (rhs.ToUpper() == "TRUE")
            {
                return(new Constant(1));
            }
            else if (rhs.ToUpper() == "FALSE")
            {
                return(new Constant(0));
            }
            else if (rhs.IndexOf('"') == 0)
            {
                rhs = rhs.Replace("\"", string.Empty);
                return(new Constant(g.GetStringId(rhs)));
            }
            else if (rhs.IndexOf('.') != -1)
            {
                string left  = rhs.Substring(0, rhs.IndexOf('.'));
                string right = rhs.Substring(rhs.IndexOf('.') + 1, rhs.Length - rhs.IndexOf('.') - 1);
                return(new Attr(left, right));
            }
            else if (g.GetObjectId(rhs) != -1)
            {
                return(new Constant(g.GetObjectId(rhs)));
            }
            else if (g.IsVariable(rhs))
            {
                return(new GameVar(rhs));
            }
            else
            {
                throw new Exception("Don't know what to do with " + rhs);
            }
        }