示例#1
0
        private ATerm[] parseATermsArray(ATermReader reader)         // throws IOException
        {
            ArrayList list = new ArrayList();
            ATerm     term;

            term = parseFromReader(reader);
            list.Add(term);
            while (reader.getLastChar() == ',')
            {
                reader.readSkippingWS();
                term = parseFromReader(reader);
                list.Add(term);
            }

            ATerm[] array = new ATerm[list.Count];
            int     index = 0;

            foreach (Object o in list)
            {
                array[index++] = (ATerm)o;
            }

/*
 *          ListIterator iter = list.listIterator();
 *                      int index = 0;
 *                      while (iter.hasNext())
 *                      {
 *                              array[index++] = (ATerm) iter.next();
 *                      }
 */
            return(array);
        }
示例#2
0
        public virtual ATerm readFromTextFile(Stream stream)          //throws IOException
        {
            ATermReader reader = new ATermReader(new
                                                 StreamReader(stream));

            reader.readSkippingWS();

            return(readFromTextFile(reader));
        }
示例#3
0
        private ATermList parseATerms(ATermReader reader)         // throws IOException
        {
            ATerm[]   terms  = parseATermsArray(reader);
            ATermList result = empty;

            for (int i = terms.Length - 1; i >= 0; i--)
            {
                result = makeList(terms[i], result);
            }
            return(result);
        }
示例#4
0
        private string parseId(ATermReader reader)         // throws IOException
        {
            int           c   = reader.getLastChar();
            StringBuilder buf = new StringBuilder(32);

            do
            {
                buf.Append((char)c);
                c = reader.read();
            }while (Char.IsLetterOrDigit((char)c) || c == '_' || c == '-');

            return(buf.ToString());
        }
示例#5
0
 public virtual ATerm parse(string trm)
 {
     try
     {
         ATermReader reader = new ATermReader(new StringReader(trm));
         reader.readSkippingWS();
         ATerm result = parseFromReader(reader);
         return(result);
     }
     catch (IOException)
     {
         throw new ParseError("premature end of string");
     }
 }
示例#6
0
        public virtual ATerm readFromSharedTextFile(Stream stream)         // throws IOException
        {
            ATermReader reader = new ATermReader(new StreamReader(stream));

            reader.readSkippingWS();

            if (reader.getLastChar() != '!')
            {
                throw new IOException("not a shared text file!");
            }

            reader.readSkippingWS();

            return(readFromSharedTextFile(reader));
        }
示例#7
0
        private ATerm parseAbbrev(ATermReader reader)         // throws IOException
        {
            ATerm result;
            int   abbrev;

            int c = reader.read();

            abbrev = 0;
            while (isBase64(c))
            {
                abbrev *= 64;
                if (c >= 'A' && c <= 'Z')
                {
                    abbrev += c - 'A';
                }
                else if (c >= 'a' && c <= 'z')
                {
                    abbrev += c - 'a' + 26;
                }
                else if (c >= '0' && c <= '9')
                {
                    abbrev += c - '0' + 52;
                }
                else if (c == '+')
                {
                    abbrev += 62;
                }
                else if (c == '/')
                {
                    abbrev += 63;
                }
                else
                {
                    throw new Exception("not a base-64 digit: " + c);
                }

                c = reader.read();
            }

            result = reader.getTerm(abbrev);

            return(result);
        }
示例#8
0
        public virtual ATerm readFromFile(Stream stream)         // throws IOException
        {
            ATermReader reader = new ATermReader(new StreamReader(stream));

            reader.readSkippingWS();

            int last_char = reader.getLastChar();

            if (last_char == '!')
            {
                reader.readSkippingWS();
                return(readFromSharedTextFile(reader));
            }
            else if (
                Char.IsLetterOrDigit((char)last_char) || last_char == '_' || last_char == '[' || last_char == '-')
            {
                return(readFromTextFile(reader));
            }
            else
            {
                throw new Exception("BAF files are not supported by this factory.");
            }
        }
示例#9
0
		public virtual ATerm readFromTextFile(Stream stream)  //throws IOException 
		{
			ATermReader reader = new ATermReader(new 
				StreamReader(stream));
			reader.readSkippingWS();

			return readFromTextFile(reader);
		}
示例#10
0
		private ATerm readFromSharedTextFile(ATermReader reader) // throws IOException 
		{
			reader.initializeSharing();
			return parseFromReader(reader);
		}
示例#11
0
		private ATerm readFromTextFile(ATermReader reader) // throws IOException 
		{
			return parseFromReader(reader);
		}
示例#12
0
		/* lock  */
		private ATerm parseFromReader(ATermReader reader) // throws IOException 
		{
			ATerm result;
			int c, start, end;
			string funname;

			start = reader.getPosition();
			switch (reader.getLastChar()) 
			{
				case -1 :
					throw new ParseError("premature EOF encountered.");
					
				case '#' :
					return parseAbbrev(reader);

				case '[' :

					c = reader.readSkippingWS();
					if (c == -1) 
					{
						throw new ParseError("premature EOF encountered.");
					}

					if (c == ']') 
					{
						c = reader.readSkippingWS();
						result = (ATerm) empty;
					}
					else 
					{
						result = parseATerms(reader);
						if (reader.getLastChar() != ']') 
						{
							throw new ParseError("expected ']' but got '" + (char) reader.getLastChar() + "'");
						}
						c = reader.readSkippingWS();
					}

					break;

				case '<' :

					c = reader.readSkippingWS();
					ATerm ph = parseFromReader(reader);

					if (reader.getLastChar() != '>') 
					{
						throw new ParseError("expected '>' but got '" + (char) reader.getLastChar() + "'");
					}

					c = reader.readSkippingWS();

					result = makePlaceholder(ph);

					break;

				case '"' :

					funname = parseString(reader);

					c = reader.readSkippingWS();
					if (reader.getLastChar() == '(') 
					{
						c = reader.readSkippingWS();
						if (c == -1) 
						{
							throw new ParseError("premature EOF encountered.");
						}
						if (reader.getLastChar() == ')') 
						{
							result = makeAppl(makeAFun(funname, 0, true));
						}
						else 
						{
							ATerm[] list = parseATermsArray(reader);

							if (reader.getLastChar() != ')') 
							{
								throw new ParseError("expected ')' but got '" + reader.getLastChar() + "'");
							}
							result = makeAppl(makeAFun(funname, list.Length, true), list);
						}
						c = reader.readSkippingWS();
						if (c == -1) 
						{
							throw new ParseError("premature EOF encountered.");
						}
					}
					else 
					{
						result = makeAppl(makeAFun(funname, 0, true));
					}

					break;

				case '(' :

					c = reader.readSkippingWS();
					if (c == -1) 
					{
						throw new ParseError("premature EOF encountered.");
					}
					if (reader.getLastChar() == ')') 
					{
						result = makeAppl(makeAFun("", 0, false));
					}
					else 
					{
						ATerm[] list = parseATermsArray(reader);

						if (reader.getLastChar() != ')') 
						{
							throw new ParseError("expected ')' but got '" + reader.getLastChar() + "'");
						}
						result = makeAppl(makeAFun("", list.Length, false), list);
					}
					c = reader.readSkippingWS();
					if (c == -1) 
					{
						throw new ParseError("premature EOF encountered.");
					}

					break;

				case '-' : goto case '9';
				case '0' : goto case '9';
				case '1' : goto case '9';
				case '2' : goto case '9';
				case '3' : goto case '9';
				case '4' : goto case '9';
				case '5' : goto case '9';
				case '6' : goto case '9';
				case '7' : goto case '9';
				case '8' : goto case '9';
				case '9' :
					result = parseNumber(reader);
					c = reader.skipWS();
					break;

				default :
					c = reader.getLastChar();
					if (Char.IsLetter((char) c)) 
					{

						funname = parseId(reader);
						c = reader.skipWS();
						if (reader.getLastChar() == '(') 
						{
							c = reader.readSkippingWS();
							if (c == -1) 
							{
								throw new ParseError("premature EOF encountered.");
							}
							if (reader.getLastChar() == ')') 
							{
								result = makeAppl(makeAFun(funname, 0, false));
							}
							else 
							{
								ATerm[] list = parseATermsArray(reader);

								if (reader.getLastChar() != ')') 
								{
									throw new ParseError("expected ')' but got '" + reader.getLastChar() + "'");
								}
								result = makeAppl(makeAFun(funname, list.Length, false), list);
							}
							c = reader.readSkippingWS();
						}
						else 
						{
							result = makeAppl(makeAFun(funname, 0, false));
						}

					}
					else 
					{
						throw new ParseError("illegal character: " + reader.getLastChar());
					}
					break;
			}

			if (reader.getLastChar() == '{') 
			{

				ATermList annos;
				if (reader.readSkippingWS() == '}') 
				{
					reader.readSkippingWS();
					annos = empty;
				}
				else 
				{
					annos = parseATerms(reader);
					if (reader.getLastChar() != '}') 
					{
						throw new ParseError("'}' expected");
					}
					reader.readSkippingWS();
				}
				result = result.setAnnotations(annos);

			}

			/* Parse some ToolBus anomalies for backwards compatibility */
			if (reader.getLastChar() == ':') 
			{
				reader.read();
				ATerm anno = parseFromReader(reader);
				result = result.setAnnotation(parse("type"), anno);
			}

			if (reader.getLastChar() == '?') 
			{
				reader.readSkippingWS();
				result = result.setAnnotation(parse("result"), parse("true"));
			}

			end = reader.getPosition();
			reader.storeNextTerm(result, end - start);

			return result;
		}
示例#13
0
		public virtual ATerm parse(string trm) 
		{
			try 
			{
				ATermReader reader = new ATermReader(new StringReader(trm));
				reader.readSkippingWS();
				ATerm result = parseFromReader(reader);
				return result;
			}
			catch (IOException) 
			{
				throw new ParseError("premature end of string");
			}
		}
示例#14
0
		private ATermList parseATerms(ATermReader reader) // throws IOException 
		{
			ATerm[] terms = parseATermsArray(reader);
			ATermList result = empty;
			for (int i = terms.Length - 1; i >= 0; i--) 
			{
				result = makeList(terms[i], result);
			}
			return result;
		}
示例#15
0
		private ATerm[] parseATermsArray(ATermReader reader) // throws IOException 
		{
			ArrayList list = new ArrayList();
			ATerm term;

			term = parseFromReader(reader);
			list.Add(term);
			while (reader.getLastChar() == ',') 
			{
				reader.readSkippingWS();
				term = parseFromReader(reader);
				list.Add(term);
			}

			ATerm[] array = new ATerm[list.Count];
			int index = 0;
			foreach(Object o in list)
			{
				array[index++] = (ATerm)o;
			}
/*
 * 			ListIterator iter = list.listIterator();
			int index = 0;
			while (iter.hasNext()) 
			{
				array[index++] = (ATerm) iter.next();
			}
*/
			return array;
		}
示例#16
0
		private string parseId(ATermReader reader) // throws IOException 
		{
			int c = reader.getLastChar();
			StringBuilder buf = new StringBuilder(32);

			do 
			{
				buf.Append((char) c);
				c = reader.read();
			}
			while (Char.IsLetterOrDigit((char) c) || c == '_' || c == '-');

			return buf.ToString();
		}
示例#17
0
		private string parseString(ATermReader reader) // throws IOException 
		{
			bool escaped;
			StringBuilder str = new StringBuilder();

			do 
			{
				escaped = false;
				if (reader.read() == '\\') 
				{
					reader.read();
					escaped = true;
				}

				if (escaped) 
				{
					switch (reader.getLastChar()) 
					{
						case 'n' :
							str.Append('\n');
							break;
						case 't' :
							str.Append('\t');
							break;
						case 'b' :
							str.Append('\b');
							break;
						case 'r' :
							str.Append('\r');
							break;
						case 'f' :
							str.Append('\f');
							break;
						case '\\' :
							str.Append('\\');
							break;
						case '\'' :
							str.Append('\'');
							break;
						case '\"' :
							str.Append('\"');
							break;
						case '0' : goto case '7';
						case '1' : goto case '7';
						case '2' : goto case '7';
						case '3' : goto case '7';
						case '4' : goto case '7';
						case '5' : goto case '7';
						case '6' : goto case '7';
						case '7' :
							str.Append(reader.readOct());
							break;
						default :
							str.Append('\\').Append((char) reader.getLastChar());
							break;
					}
				}
				else if (reader.getLastChar() != '\"')
					str.Append((char) reader.getLastChar());
			}
			while (escaped || reader.getLastChar() != '"');

			return str.ToString();
		}
示例#18
0
        private ATerm parseNumber(ATermReader reader)         // throws IOException
        {
            StringBuilder str = new StringBuilder();
            ATerm         result;

            do
            {
                str.Append((char)reader.getLastChar());
            }while (Char.IsDigit((char)reader.read()));

            if (reader.getLastChar() != '.' && reader.getLastChar() != 'e' && reader.getLastChar() != 'E')
            {
                int val;
                try
                {
                    val = int.Parse(str.ToString());
                }
                catch (FormatException)
                {
                    throw new ParseError("malformed int");
                }
                result = makeInt(val);
            }
            else
            {
                if (reader.getLastChar() == '.')
                {
                    str.Append('.');
                    reader.read();
                    if (!Char.IsDigit((char)reader.getLastChar()))
                    {
                        throw new ParseError("digit expected");
                    }
                    do
                    {
                        str.Append((char)reader.getLastChar());
                    }while (Char.IsDigit((char)reader.read()));
                }
                if (reader.getLastChar() == 'e' || reader.getLastChar() == 'E')
                {
                    str.Append((char)reader.getLastChar());
                    reader.read();
                    if (reader.getLastChar() == '-' || reader.getLastChar() == '+')
                    {
                        str.Append((char)reader.getLastChar());
                        reader.read();
                    }
                    if (!Char.IsDigit((char)reader.getLastChar()))
                    {
                        throw new ParseError("digit expected!");
                    }
                    do
                    {
                        str.Append((char)reader.getLastChar());
                    }while (Char.IsDigit((char)reader.read()));
                }
                double val;
                try
                {
                    val = double.Parse(str.ToString());
                    //					Double.valueOf(str.ToString()).doubleValue();
                }
                catch (FormatException)
                {
                    throw new ParseError("malformed real");
                }
                result = makeReal(val);
            }
            return(result);
        }
示例#19
0
		private ATerm parseNumber(ATermReader reader) // throws IOException 
		{
			StringBuilder str = new StringBuilder();
			ATerm result;

			do 
			{
				str.Append((char) reader.getLastChar());
			}
			while (Char.IsDigit((char) reader.read()));

			if (reader.getLastChar() != '.' && reader.getLastChar() != 'e' && reader.getLastChar() != 'E') 
			{
				int val;
				try 
				{
					val = int.Parse(str.ToString());
				}
				catch (FormatException) 
				{
					throw new ParseError("malformed int");
				}
				result = makeInt(val);
			}
			else 
			{
				if (reader.getLastChar() == '.') 
				{
					str.Append('.');
					reader.read();
					if (!Char.IsDigit((char) reader.getLastChar()))
						throw new ParseError("digit expected");
					do 
					{
						str.Append((char) reader.getLastChar());
					}
					while (Char.IsDigit((char) reader.read()));
				}
				if (reader.getLastChar() == 'e' || reader.getLastChar() == 'E') 
				{
					str.Append((char) reader.getLastChar());
					reader.read();
					if (reader.getLastChar() == '-' || reader.getLastChar() == '+') 
					{
						str.Append((char) reader.getLastChar());
						reader.read();
					}
					if (!Char.IsDigit((char) reader.getLastChar()))
						throw new ParseError("digit expected!");
					do 
					{
						str.Append((char) reader.getLastChar());
					}
					while (Char.IsDigit((char) reader.read()));
				}
				double val;
				try 
				{
					val = double.Parse(str.ToString());
					//					Double.valueOf(str.ToString()).doubleValue();
				}
				catch (FormatException) 
				{
					throw new ParseError("malformed real");
				}
				result = makeReal(val);
			}
			return result;
		}
示例#20
0
		public virtual ATerm readFromSharedTextFile(Stream stream) // throws IOException 
		{
			ATermReader reader = new ATermReader(new StreamReader(stream));
			reader.readSkippingWS();

			if (reader.getLastChar() != '!') 
			{
				throw new IOException("not a shared text file!");
			}

			reader.readSkippingWS();

			return readFromSharedTextFile(reader);
		}
示例#21
0
        private string parseString(ATermReader reader)         // throws IOException
        {
            bool          escaped;
            StringBuilder str = new StringBuilder();

            do
            {
                escaped = false;
                if (reader.read() == '\\')
                {
                    reader.read();
                    escaped = true;
                }

                if (escaped)
                {
                    switch (reader.getLastChar())
                    {
                    case 'n':
                        str.Append('\n');
                        break;

                    case 't':
                        str.Append('\t');
                        break;

                    case 'b':
                        str.Append('\b');
                        break;

                    case 'r':
                        str.Append('\r');
                        break;

                    case 'f':
                        str.Append('\f');
                        break;

                    case '\\':
                        str.Append('\\');
                        break;

                    case '\'':
                        str.Append('\'');
                        break;

                    case '\"':
                        str.Append('\"');
                        break;

                    case '0': goto case '7';

                    case '1': goto case '7';

                    case '2': goto case '7';

                    case '3': goto case '7';

                    case '4': goto case '7';

                    case '5': goto case '7';

                    case '6': goto case '7';

                    case '7':
                        str.Append(reader.readOct());
                        break;

                    default:
                        str.Append('\\').Append((char)reader.getLastChar());
                        break;
                    }
                }
                else if (reader.getLastChar() != '\"')
                {
                    str.Append((char)reader.getLastChar());
                }
            }while (escaped || reader.getLastChar() != '"');

            return(str.ToString());
        }
示例#22
0
        /* lock  */
        private ATerm parseFromReader(ATermReader reader)         // throws IOException
        {
            ATerm  result;
            int    c, start, end;
            string funname;

            start = reader.getPosition();
            switch (reader.getLastChar())
            {
            case -1:
                throw new ParseError("premature EOF encountered.");

            case '#':
                return(parseAbbrev(reader));

            case '[':

                c = reader.readSkippingWS();
                if (c == -1)
                {
                    throw new ParseError("premature EOF encountered.");
                }

                if (c == ']')
                {
                    c      = reader.readSkippingWS();
                    result = (ATerm)empty;
                }
                else
                {
                    result = parseATerms(reader);
                    if (reader.getLastChar() != ']')
                    {
                        throw new ParseError("expected ']' but got '" + (char)reader.getLastChar() + "'");
                    }
                    c = reader.readSkippingWS();
                }

                break;

            case '<':

                c = reader.readSkippingWS();
                ATerm ph = parseFromReader(reader);

                if (reader.getLastChar() != '>')
                {
                    throw new ParseError("expected '>' but got '" + (char)reader.getLastChar() + "'");
                }

                c = reader.readSkippingWS();

                result = makePlaceholder(ph);

                break;

            case '"':

                funname = parseString(reader);

                c = reader.readSkippingWS();
                if (reader.getLastChar() == '(')
                {
                    c = reader.readSkippingWS();
                    if (c == -1)
                    {
                        throw new ParseError("premature EOF encountered.");
                    }
                    if (reader.getLastChar() == ')')
                    {
                        result = makeAppl(makeAFun(funname, 0, true));
                    }
                    else
                    {
                        ATerm[] list = parseATermsArray(reader);

                        if (reader.getLastChar() != ')')
                        {
                            throw new ParseError("expected ')' but got '" + reader.getLastChar() + "'");
                        }
                        result = makeAppl(makeAFun(funname, list.Length, true), list);
                    }
                    c = reader.readSkippingWS();
                    if (c == -1)
                    {
                        throw new ParseError("premature EOF encountered.");
                    }
                }
                else
                {
                    result = makeAppl(makeAFun(funname, 0, true));
                }

                break;

            case '(':

                c = reader.readSkippingWS();
                if (c == -1)
                {
                    throw new ParseError("premature EOF encountered.");
                }
                if (reader.getLastChar() == ')')
                {
                    result = makeAppl(makeAFun("", 0, false));
                }
                else
                {
                    ATerm[] list = parseATermsArray(reader);

                    if (reader.getLastChar() != ')')
                    {
                        throw new ParseError("expected ')' but got '" + reader.getLastChar() + "'");
                    }
                    result = makeAppl(makeAFun("", list.Length, false), list);
                }
                c = reader.readSkippingWS();
                if (c == -1)
                {
                    throw new ParseError("premature EOF encountered.");
                }

                break;

            case '-': goto case '9';

            case '0': goto case '9';

            case '1': goto case '9';

            case '2': goto case '9';

            case '3': goto case '9';

            case '4': goto case '9';

            case '5': goto case '9';

            case '6': goto case '9';

            case '7': goto case '9';

            case '8': goto case '9';

            case '9':
                result = parseNumber(reader);
                c      = reader.skipWS();
                break;

            default:
                c = reader.getLastChar();
                if (Char.IsLetter((char)c))
                {
                    funname = parseId(reader);
                    c       = reader.skipWS();
                    if (reader.getLastChar() == '(')
                    {
                        c = reader.readSkippingWS();
                        if (c == -1)
                        {
                            throw new ParseError("premature EOF encountered.");
                        }
                        if (reader.getLastChar() == ')')
                        {
                            result = makeAppl(makeAFun(funname, 0, false));
                        }
                        else
                        {
                            ATerm[] list = parseATermsArray(reader);

                            if (reader.getLastChar() != ')')
                            {
                                throw new ParseError("expected ')' but got '" + reader.getLastChar() + "'");
                            }
                            result = makeAppl(makeAFun(funname, list.Length, false), list);
                        }
                        c = reader.readSkippingWS();
                    }
                    else
                    {
                        result = makeAppl(makeAFun(funname, 0, false));
                    }
                }
                else
                {
                    throw new ParseError("illegal character: " + reader.getLastChar());
                }
                break;
            }

            if (reader.getLastChar() == '{')
            {
                ATermList annos;
                if (reader.readSkippingWS() == '}')
                {
                    reader.readSkippingWS();
                    annos = empty;
                }
                else
                {
                    annos = parseATerms(reader);
                    if (reader.getLastChar() != '}')
                    {
                        throw new ParseError("'}' expected");
                    }
                    reader.readSkippingWS();
                }
                result = result.setAnnotations(annos);
            }

            /* Parse some ToolBus anomalies for backwards compatibility */
            if (reader.getLastChar() == ':')
            {
                reader.read();
                ATerm anno = parseFromReader(reader);
                result = result.setAnnotation(parse("type"), anno);
            }

            if (reader.getLastChar() == '?')
            {
                reader.readSkippingWS();
                result = result.setAnnotation(parse("result"), parse("true"));
            }

            end = reader.getPosition();
            reader.storeNextTerm(result, end - start);

            return(result);
        }
示例#23
0
 private ATerm readFromTextFile(ATermReader reader)         // throws IOException
 {
     return(parseFromReader(reader));
 }
示例#24
0
 private ATerm readFromSharedTextFile(ATermReader reader)         // throws IOException
 {
     reader.initializeSharing();
     return(parseFromReader(reader));
 }
示例#25
0
		public virtual ATerm readFromFile(Stream stream) // throws IOException 
		{
			ATermReader reader = new ATermReader(new StreamReader(stream));
			reader.readSkippingWS();

			int last_char = reader.getLastChar();
			if (last_char == '!') 
			{
				reader.readSkippingWS();
				return readFromSharedTextFile(reader);
			}
			else if (
				Char.IsLetterOrDigit((char) last_char) || last_char == '_' || last_char == '[' || last_char == '-') 
			{
				return readFromTextFile(reader);
			}
			else 
			{
				throw new Exception("BAF files are not supported by this factory.");
			}
		}
示例#26
0
		private ATerm parseAbbrev(ATermReader reader) // throws IOException 
		{
			ATerm result;
			int abbrev;

			int c = reader.read();

			abbrev = 0;
			while (isBase64(c)) 
			{
				abbrev *= 64;
				if (c >= 'A' && c <= 'Z') 
				{
					abbrev += c - 'A';
				}
				else if (c >= 'a' && c <= 'z') 
				{
					abbrev += c - 'a' + 26;
				}
				else if (c >= '0' && c <= '9') 
				{
					abbrev += c - '0' + 52;
				}
				else if (c == '+') 
				{
					abbrev += 62;
				}
				else if (c == '/') 
				{
					abbrev += 63;
				}
				else 
				{
					throw new Exception("not a base-64 digit: " + c);
				}

				c = reader.read();
			}

			result = reader.getTerm(abbrev);

			return result;
		}