Beispiel #1
0
  public static String body(String[] args) {
    LexicalAnalyzer lex = new LexicalAnalyzer();
    String str = "";

    try {
      BufferedReader in = null;
      if (args.length == 0) {
        in = new BufferedReader(new InputStreamReader(System.in));
      } else {
        in = new BufferedReader(new FileReader(args[0]));
      }

      lex.tokenize(in);
    } catch (IOException e) {
      System.out.println("IO Error");
    }

    try {
      DatalogProgram datalogProgram = new DatalogProgram(lex);
      str += "Success!\n";
      str += datalogProgram.toString();
    } catch (ParseException e) {
      str += "Failure!\n  " + e.getToken().toString();
    }

    return str;
  }
Beispiel #2
0
  public Comparator(LexicalAnalyzer lex) throws ParseException {
    TokenType[] comparatorTypes = {
      TokenType.LT, TokenType.LE, TokenType.EQ, TokenType.NE, TokenType.GE, TokenType.GT
    };
    Check.tokenType(lex, comparatorTypes);
    name = lex.currentToken().getValue();
    lex.advance();

    Check.tokenType(lex, TokenType.LEFT_PAREN);
    lex.advance();

    arg1 = new Argument(lex);

    Check.tokenType(lex, TokenType.COMMA);
    lex.advance();

    arg2 = new Argument(lex);

    Check.tokenType(lex, TokenType.RIGHT_PAREN);
    lex.advance();
  }