Package aima.core.logic.common

Examples of aima.core.logic.common.Token


    StringBuffer sbuf = new StringBuffer();
    while (Character.isLetterOrDigit(lookAhead(1))) {
      sbuf.append(lookAhead(1));
      consume();
    }
    return new Token(LogicTokenTypes.CONNECTOR, sbuf.toString());
  }
View Full Code Here


    StringBuffer sbuf = new StringBuffer();
    while (Character.isWhitespace(lookAhead(1))) {
      sbuf.append(lookAhead(1));
      consume();
    }
    return new Token(LogicTokenTypes.WHITESPACE, sbuf.toString());

  }
View Full Code Here

  @Override
  public Token nextToken() {
    if (lookAhead(1) == '(') {
      consume();
      return new Token(LogicTokenTypes.LPAREN, "(");

    } else if (lookAhead(1) == ')') {
      consume();
      return new Token(LogicTokenTypes.RPAREN, ")");

    } else if (lookAhead(1) == ',') {
      consume();
      return new Token(LogicTokenTypes.COMMA, ",");

    } else if (identifierDetected()) {
      // System.out.println("identifier detected");
      return identifier();
    } else if (Character.isWhitespace(lookAhead(1))) {
      consume();
      return nextToken();
    } else if (lookAhead(1) == (char) -1) {
      return new Token(LogicTokenTypes.EOI, "EOI");
    } else {
      throw new RuntimeException("Lexing error on character "
          + lookAhead(1));
    }
  }
View Full Code Here

      consume();
    }
    String readString = new String(sbuf);
    // System.out.println(readString);
    if (connectors.contains(readString)) {
      return new Token(LogicTokenTypes.CONNECTOR, readString);
    } else if (quantifiers.contains(readString)) {
      return new Token(LogicTokenTypes.QUANTIFIER, readString);
    } else if (domain.getPredicates().contains(readString)) {
      return new Token(LogicTokenTypes.PREDICATE, readString);
    } else if (domain.getFunctions().contains(readString)) {
      return new Token(LogicTokenTypes.FUNCTION, readString);
    } else if (domain.getConstants().contains(readString)) {
      return new Token(LogicTokenTypes.CONSTANT, readString);
    } else if (isVariable(readString)) {
      return new Token(LogicTokenTypes.VARIABLE, readString);
    } else if (readString.equals("=")) {
      return new Token(LogicTokenTypes.EQUALS, readString);
    } else {
      throw new RuntimeException("Lexing error on character "
          + lookAhead(1));
    }
View Full Code Here

    fillLookAheadBuffer();

  }

  private Term parseTerm() {
    Token t = lookAhead(1);
    int tokenType = t.getType();
    if (tokenType == LogicTokenTypes.CONSTANT) {
      return parseConstant();
    } else if (tokenType == LogicTokenTypes.VARIABLE) {
      return parseVariable();
    } else if (tokenType == LogicTokenTypes.FUNCTION) {
View Full Code Here

      return null;
    }
  }

  public Term parseVariable() {
    Token t = lookAhead(1);
    String value = t.getText();
    consume();
    return new Variable(value);
  }
View Full Code Here

    consume();
    return new Variable(value);
  }

  public Term parseConstant() {
    Token t = lookAhead(1);
    String value = t.getText();
    consume();
    return new Constant(value);
  }
View Full Code Here

    consume();
    return new Constant(value);
  }

  public Term parseFunction() {
    Token t = lookAhead(1);
    String functionName = t.getText();
    List<Term> terms = processTerms();
    return new Function(functionName, terms);
  }
View Full Code Here

    List<Term> terms = processTerms();
    return new Function(functionName, terms);
  }

  public Sentence parsePredicate() {
    Token t = lookAhead(1);
    String predicateName = t.getText();
    List<Term> terms = processTerms();
    return new Predicate(predicateName, terms);
  }
View Full Code Here

  //
  // PRIVATE METHODS
  //

  private Sentence parseSentence() {
    Token t = lookAhead(1);
    if (lParen(t)) {
      return parseParanthizedSentence();
    } else if ((lookAhead(1).getType() == LogicTokenTypes.QUANTIFIER)) {

      return parseQuantifiedSentence();
    } else if (notToken(t)) {
      return parseNotSentence();
    } else if (predicate(t)) {
      return parsePredicate();
    } else if (term(t)) {
      return parseTermEquality();
    }

    throw new RuntimeException("parse failed with Token " + t.getText());
  }
View Full Code Here

TOP

Related Classes of aima.core.logic.common.Token

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.