AbcDatalog parses a dialect of Datalog whose surface syntax is designed to be compact and readable. This page is a complete reference for every syntactic element you will encounter when writing programs for AbcDatalog: how clauses are structured, how identifiers are lexed into constants and variables, what operators are available in rule bodies, and how queries are written.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/HarvardPL/AbcDatalog/llms.txt
Use this file to discover all available pages before exploring further.
Program structure
A Datalog program is an unordered set of clauses. AbcDatalog reads all clauses before evaluation begins, so the order in which you write them in a file does not matter. Each clause is terminated by a period (.).
Clause format
Every clause has a head — a single positive atom — and an optional body — a comma-separated list of premises.| Form | Meaning |
|---|---|
a0. | A fact: a0 is unconditionally true. |
a0 :- a1, ..., an. | A rule: a0 holds if every a1 through an holds. |
:- token is read as “if”. The head atom must be a positive atom (predicate symbol with zero or more term arguments). Body premises may be positive atoms, negated atoms, binary unifiers, or binary disunifiers — each detailed further below.
Atoms
An atom has the formp or p(t1, ..., tk) where p is a predicate symbol and each ti is a term. The arity of a predicate symbol is fixed throughout a program: a predicate used as edge(a,b) always takes exactly two arguments everywhere it appears.
Terms
A term is either a constant or a variable.- Constants begin with a lowercase letter. They denote fixed values in the domain. Examples:
a,b,node1,start. - Variables begin with an uppercase letter or an underscore. They range over constants during evaluation. Examples:
X,Y,Node,_Tmp. - Wildcards: a bare
_(a single underscore) is parsed as a fresh anonymous variable — it is guaranteed to be distinct from every other occurrence of_in the same clause. Use it when a position’s value is irrelevant.
Identifiers
Identifiers can contain letters, digits, and underscores only. The first character determines the syntactic role:| First character | Role |
|---|---|
Lowercase letter (a–z) | Constant or predicate symbol |
Uppercase letter (A–Z) | Variable |
Underscore _ (followed by more chars) | Variable |
Bare _ (alone) | Anonymous wildcard variable |
Identifiers are case-sensitive.
node and Node are different tokens: node is parsed as a predicate symbol or constant, while Node is parsed as a variable.Comments
A% character begins a line comment. Everything from % to the end of the line is ignored by the tokenizer. AbcDatalog has no block comment syntax.
Queries
A query is an atom terminated by? instead of .. When submitted interactively or via DatalogParser.parseQuery, it asks the engine to return all ground substitutions of the query atom that are entailed by the program.
Syntactic elements reference
| Element | Syntax | Example |
|---|---|---|
| Fact | head. | edge(a,b). |
| Rule | head :- body. | tc(X,Y) :- edge(X,Y). |
| Body separator | , | edge(X,Z), tc(Z,Y) |
| Atom | pred or pred(t1,...,tk) | tc(X,Y) |
| Constant | lowercase-start identifier | a, node1 |
| Variable | uppercase-start or _-start identifier | X, _Tmp |
| Wildcard | bare _ | edge(X,_) |
| Line comment | % ... | % a comment |
| Query terminator | ? | tc(X,Y)? |
| Unification | t1 = t2 | X=Y |
| Disunification | t1 != t2 | X!=Y |
| Negation | not atom | not tc(X,Y) |