Class DatalogParser
java.lang.Object
edu.harvard.seas.pl.abcdatalog.parser.DatalogParser
A recursive descent parser for Datalog.
A Datalog program is a set of clauses, where each clause is in the form "a0 :- a1, ..., an." or "a0." and each ai is an atom of the form "pi" or "pi(t1, ..., tki)" for ki > 0 such that pi is a predicate symbol and each tj for 0 invalid input: '<' j invalid input: '<'= ki is a term (i.e. a constant or variable). Any variable in a0 must appear in at least one of ai, ..., an. Identifiers can contain letters, digits and underscores. Identifiers that begin with an upper case letter or an underscore are parsed as variables.
A Datalog program is a set of clauses, where each clause is in the form "a0 :- a1, ..., an." or "a0." and each ai is an atom of the form "pi" or "pi(t1, ..., tki)" for ki > 0 such that pi is a predicate symbol and each tj for 0 invalid input: '<' j invalid input: '<'= ki is a term (i.e. a constant or variable). Any variable in a0 must appear in at least one of ai, ..., an. Identifiers can contain letters, digits and underscores. Identifiers that begin with an upper case letter or an underscore are parsed as variables.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
static PositiveAtom
Extracts an atom from the token stream.static PositiveAtom
Attempts to extract an atom from the provided token stream.Generates an abstract syntax tree representation of the program described by the provided token stream.static PositiveAtom
Attempts to extract an atom representation of the query described in the token stream.
-
Method Details
-
parseProgram
Generates an abstract syntax tree representation of the program described by the provided token stream.- Parameters:
t
- the token stream representation of program- Returns:
- the AST of program
- Throws:
DatalogParseException
-
parsePositiveAtom
Attempts to extract an atom from the provided token stream.- Parameters:
t
- the token stream- Returns:
- the atom
- Throws:
DatalogParseException
-
parseQuery
Attempts to extract an atom representation of the query described in the token stream.- Parameters:
t
- the token stream- Returns:
- the atom
- Throws:
DatalogParseException
-
parseClauseAsPositiveAtom
public static PositiveAtom parseClauseAsPositiveAtom(DatalogTokenizer t) throws DatalogParseException Extracts an atom from the token stream. The atom must be followed by a period.- Parameters:
t
- the token stream- Returns:
- the atom
- Throws:
DatalogParseException
-
main
- Throws:
DatalogParseException
-