Beispiel #1
0
        public void TestSymExp(String symExp)
        {
            Console.WriteLine("Testing '{0}'", symExp);

            SNode node = SymExp.Read(symExp);

            StringBuilder builder = new StringBuilder();

            node.ToSymExp(builder);

            Assert.AreEqual(symExp, builder.ToString());
        }
Beispiel #2
0
        public static Int32 Read(String symExp, Int32 offset, out SNode node)
        {
            //
            // Skip whitespace
            //
            Char c = symExp[offset];

            while (Char.IsWhiteSpace(c))
            {
                offset++;
                if (offset >= symExp.Length)
                {
                    throw new InvalidOperationException("Expected symbolic expression but was empty");
                }
                c = symExp[offset];
            }

            //
            // Check first character
            //
            if (c == '(')
            {
                SList list;
                offset = ReadList(symExp, offset, out list);
                node   = list;
                return(offset);
            }
            else if (c >= '0' && c <= '9')
            {
                SNumber number;
                offset = ReadNumber(symExp, offset, out number);
                node   = number;
                return(offset);
            }
            else if (IsSymbolCharacter(c))
            {
                SSymbol symbol;
                offset = ReadSSymbol(symExp, offset, out symbol);
                node   = symbol;
                return(offset);
            }
            else
            {
                throw new FormatException(String.Format("Unhandled character '{0}' (charcode={1})",
                                                        c, (Int32)c));
            }
        }