lp.parse
Class EvolpParser

java.lang.Object
  extended by lp.parse.LpParser
      extended by lp.parse.EvolpParser
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
EvolpSolver.TransEvolpParser

public class EvolpParser
extends LpParser

Inherits the basic behaviour from LpParser and overrides some parts in order to parse the input according to this grammar:

Rule ---> (Literal | InnerRule) DOT
InnerRule ---> NormalRule | Constraint
OrdinaryRule ---> Literal RULE_ARROW (Literal (COMMA Literal)*)?
Constraint ---> RULE_ARROW Literal (COMMA Literal)*
Literal ---> 'not'? Atom
Atom ---> PredicateName Arguments?
PredicateName ---> LOWERCASE_WORD
Arguments ---> LEFT_PAREN Term (COMMA Term)* RIGHT_PAREN
Term ---> LEFT_PAREN Term RIGHT_PAREN | Constant | Variable | CompoundTerm | InnerRule
Constant ---> LOWERCASE_WORD
Variable ---> UPPERCASE_WORD
CompoundTerm ---> FunctionName Arguments
FunctionName ---> LOWERCASE_WORD
In this grammar In addition, it offers the static method parseEvolp() that parses the given input as an EVOLP input, i.e. a sequence of logic program separated from each other by "newEvents." facts. The first program in the sequence is the base program an the others are events. For example on this input:
a.
newEvents.
not a.
newEvents.
a <- not b.
it would produce an EVOLP program with this the base program
a.
and these two events:
not a.
a <- not b.

Version:
1.0.0
See Also:
LpLexer, LpParser

Field Summary
static LpRule SEP_RULE
          The fact "newEvents." for separating parts of the EVOLP input.
 
Constructor Summary
EvolpParser()
          Creates a new EvolpParser instance that uses a new LpLexer instance to tokenize the character input before parsing.
EvolpParser(LpLexer lexer)
          Creates a new EvolpParser instance that uses lexer to tokenize the character input before parsing.
 
Method Summary
 EvolpProgram parseEvolp()
          Parses the given input as an EVOLP program , i.e. a sequence of logic programs separated from each other by "newEvents." facts.
 LpTerm parseTerm()
          Corresponds to the non-terminal Term from the class description.
 
Methods inherited from class lp.parse.LpParser
close, expect, getLexer, hasMoreTokens, match, nextToken, parseAllRules, parseAllRules, parseArguments, parseAtom, parseLiteral, parseOnlyRule, parseRule, parseRuleBody, setInput, setInput, setInput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEP_RULE

public static final LpRule SEP_RULE
The fact "newEvents." for separating parts of the EVOLP input.

Constructor Detail

EvolpParser

public EvolpParser()
Creates a new EvolpParser instance that uses a new LpLexer instance to tokenize the character input before parsing.


EvolpParser

public EvolpParser(LpLexer lexer)
Creates a new EvolpParser instance that uses lexer to tokenize the character input before parsing.

Parameters:
lexer - the LpLexer instance used to tokenize the character input before parsing
Method Detail

parseEvolp

public EvolpProgram parseEvolp()
Parses the given input as an EVOLP program , i.e. a sequence of logic programs separated from each other by "newEvents." facts. The first program in the sequence is the base program an the others are events.

Throws:
IOException - (wrapped in an ExceptionAdapter) in case an I/O error occurs while tokenizing the input
LpParserException - if the input doesn't match the expression (Rule* EOF) (Rule is a non-terminal from the grammar in class description)
See Also:
LpParser.parseRule()

parseTerm

public LpTerm parseTerm()
Corresponds to the non-terminal Term from the class description. Parses the next term in the input and returns an instance of a class implementing the LpTerm interface—an object model of the parsed term.

Overrides:
parseTerm in class LpParser
Returns:
the parsed term