Vadalog Grammar Reference
This document provides a comprehensive reference for the Vadalog grammar, covering all syntax rules, operators, and language constructs.Program Structure
A Vadalog program consists of a sequence of clauses:Clause Types
A clause can be one of three types:- Annotation: Configuration directives (e.g.,
@bind,@output) - Fact: Ground truth statements (e.g.,
person("john", 25).) - Rule: Logical inference rules (e.g.,
adult(X) <- person(X, Age), Age >= 18.)
Facts
Facts are ground statements that establish base knowledge:Rules
Rules define logical inference patterns:Rule Head
The head can be:- Regular atom:
result(X, Y) - EGD (Equality Generating Dependency):
X = Y - False head:
#F(for constraints)
Rule Body
The body consists of literals, conditions, and functions:Literals
Literals can be positive, negative, or domain predicates:Conditions
Conditions define constraints and comparisons:Comparison Operators
Set Membership
Expressions
Expressions support arithmetic, logical, and functional operations:Arithmetic Expressions
Logical Expressions
Set Operations
Comparison Expressions
Aggregation Functions
Vadalog supports both monotonic and non-monotonic aggregations:Monotonic Aggregations
Standard Aggregations
Group-by variables appear in both the head and the body. The aggregation function takes only the expression to aggregate.
String Operations
Logical Operations
Interval Operations
Data Type Conversions
Null Handling
Terms and Constants
Variable Terms
- Variables: Start with uppercase (
Name,Age,X) - Anonymous variables: Start with underscore (
_,_1,_temp)
Constant Terms
- Strings: Double-quoted (
"hello","john doe") - Integers: Numeric (
42,-10) - Doubles: Decimal (
3.14,-2.5) - Booleans:
#T(true),#F(false) - Dates:
2024-01-15or2024-01-15 14:30:00
Collection Terms
- Lists:
[1, 2, 3]or["a", "b", "c"] - Sets:
{1, 2, 3}or{"a", "b", "c"} - Empty collections:
[](list),{}(set)
External Functions
Call external functions using namespace syntax:Parameter Operations
Dynamic parameter substitution:Comments
Line comments start with%:
Operator Precedence
From highest to lowest precedence:- Parentheses:
() - Unary minus:
- - Multiplication/Division:
*,/ - Addition/Subtraction:
+,- - Comparison:
<,<=,>,>=,==,!= - Logical NOT:
! - Logical AND:
&& - Logical OR:
|| - Set operations:
|,&
Best Practices
- Use meaningful predicate names:
customer_analysisnotca - Follow naming conventions: Variables uppercase, constants lowercase
- Group related rules: Keep similar logic together
- Comment complex logic: Explain non-obvious rules
- Use proper aggregations:
mavg()for averages,msum()for sums - Handle edge cases: Consider null values and empty results

