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); }
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()); }
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)); }
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."); } }
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."); } }
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); }
/* 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; }
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; }
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(); }
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(); }
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; }
/* 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); }
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()); }
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); }