Package aterm

Examples of aterm.ParseError


    }

    public ATerm readFromBinaryFile(boolean headerAlreadyRead) throws ParseError, IOException {

        if(!headerAlreadyRead && !isBinaryATerm(reader))
            throw new ParseError("Input is not a BAF file");

        int val = reader.readInt();

        if (val != BAF_VERSION)
            throw new ParseError("Wrong BAF version (wanted " + BAF_VERSION + ", got " + val + "), giving up");

        nrUniqueSymbols = reader.readInt();
        int nrUniqueTerms = reader.readInt();

        if(isDebugging()) {
View Full Code Here


                    debug(" [" + i+  "] - recurse");
                argSym.terms[val] = readTerm(argSym);
            }

            if (argSym.terms[val] == null)
                throw new ParseError("Cannot be null");

            args[i] = argSym.terms[val];
        }

        final String name = e.fun.getName();
View Full Code Here

        && reader.getLastChar() != 'L') {
      int val;
      try {
        val = Integer.parseInt(str.toString());
      } catch (NumberFormatException e) {
        throw new ParseError("malformed int");
      }
      result = makeInt(val);
    } else if (reader.getLastChar() == 'l' || reader.getLastChar() == 'L') {
      reader.read();
      long val;
      try {
        val = Long.parseLong(str.toString());
      } catch (NumberFormatException e) {
        throw new ParseError("malformed long");
      }
      result = makeLong(val);
    } else {
      if (reader.getLastChar() == '.') {
        str.append('.');
        reader.read();
        if (!Character.isDigit(reader.getLastChar()))
          throw new ParseError("digit expected");
        do {
          str.append((char) reader.getLastChar());
        } while (Character.isDigit(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 (!Character.isDigit(reader.getLastChar()))
          throw new ParseError("digit expected!");
        do {
          str.append((char) reader.getLastChar());
        } while (Character.isDigit(reader.read()));
      }
      double val;
      try {
        val = Double.valueOf(str.toString()).doubleValue();
      } catch (NumberFormatException e) {
        throw new ParseError("malformed real");
      }
      result = makeReal(val);
    }
    return result;
  }
View Full Code Here

        reader.read();
        escaped = true;
      }
     
      int lastChar = reader.getLastChar();
      if(lastChar == -1) throw new ParseError("Unterminated quoted function symbol: " + str);
     
      if (escaped) {
        switch (lastChar) {
          case 'n':
            str.append('\n');
View Full Code Here

    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 = 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();
        } 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 '" + (char)reader.getLastChar() + "'");
          }
          result = makeAppl(makeAFun("", list.length, false), list);
        }
        c = reader.readSkippingWS();

        break;

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

      default:
        c = reader.getLastChar();
        if (Character.isLetter(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 '" + (char) 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: '" + (char) reader.getLastChar() + "'");
        }
    }

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

      ATermReader reader = new ATermReader(new StringReader(trm), trm.length());
      reader.readSkippingWS();
      ATerm result = parseFromReader(reader);
      return result;
    } catch (IOException e) {
      throw new ParseError("premature end of string");
    }
  }
View Full Code Here

  public int readOct() throws IOException {
    int val = Character.digit(last_char, 8);
    val += Character.digit(read(), 8);

    if (val < 0) {
      throw new ParseError("octal must have 3 octdigits.");
    }

    val += Character.digit(read(), 8);

    if (val < 0) {
      throw new ParseError("octal must have 3 octdigits");
    }

    return val;
  }
View Full Code Here

TOP

Related Classes of aterm.ParseError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.