Using the PDDL Parser
The library has a parser of the PDDL language. The language respects the 3.1 standard. To get the exact BNF (Backus–Naur form) of the PDDL language implemented in the library you can type the command:
./gradlew jjdoc
To access to the documentation generated open the file ./build/docs/PDDL4J_BNF/lexer.html or simply by clicking on
this link
Pre-requisite Installations
- For this tutorial you need:
In the following, we will give the commands line so that the tutorial can be done independently of any IDE.
Step 1. Create a simple Java project with PDDL4J
First, open a terminal and create your development directory
mkdir PDDLParserExample
Then, create the sub-directories of your project
cd PDDLParserExample
mkdir -p src/fr/uga/pddl4j/examples
mkdir classes
mkdir lib
Finally, get the last binary of PDDL4J and save it in the lib directory
wget http://pddl4j.imag.fr/repository/pddl4j/binaries/pddl4j-4.0.0.jar
mv pddl4j-4.0.0.jar lib/pddl4j-4.0.0.jar
Step 2. Create the main class of our example
Create and edit a file called PDDLParserExample.java in the directory src/fr/uga/pddl4j/examples/. The skeleton
of this class is given bellow:
1package fr.uga.pddl4j.examples;
2
3import fr.uga.pddl4j.parser.DefaultParsedProblem;
4import fr.uga.pddl4j.parser.ErrorManager;
5import fr.uga.pddl4j.parser.Message;
6import fr.uga.pddl4j.parser.Parser;
7
8/**
9 * The class is an example class. It shows how to use the library to create a PDDL parser and use it to parse PDDL
10 * planning problem description.
11 *
12 * @author D. Pellier
13 * @version 4.0 - 06.12.2021
14 */
15public class PDDLParserExample {
16
17 /**
18 * The main method the class. The first argument must be the path to the PDDL domain description and the second
19 * argument the path to the PDDL problem description.
20 *
21 * @param args the command line arguments.
22 */
23 public static void main(final String[] args) {
24
25 // Checks the number of arguments from the command line
26 if (args.length != 2) {
27 System.out.println("Invalid command line");
28 return;
29 }
30
31 try {
32 // Creates an instance of the PDDL parser
33 final Parser parser = new Parser();
34 // Parses the domain and the problem files.
35 final DefaultParsedProblem parsedProblem = parser.parse(args[0], args[1]);
36 // Gets the error manager of the parser
37 final ErrorManager errorManager = parser.getErrorManager();
38 // Checks if the error manager contains errors
39 if (!errorManager.isEmpty()) {
40 // Prints the errors
41 for (Message m : errorManager.getMessages()) {
42 System.out.println(m.toString());
43 }
44 } else {
45 // Prints that the domain and the problem were successfully parsed
46 System.out.print("\nparsing domain file \"" + args[0] + "\" done successfully");
47 System.out.print("\nparsing problem file \"" + args[1] + "\" done successfully\n\n");
48 // Print domain and the problem parsed
49 System.out.println(parsedProblem.toString());
50 }
51 // This exception could happen if the domain or the problem does not exist
52 } catch (Throwable t) {
53 t.printStackTrace();
54 }
55 }
56}
Step 3. Compile and Run the example
To test the above code use the following command line to compile the example:
javac -d classes -cp classes:lib/pddl4j-4.0.0.jar src/fr/uga/pddl4j/examples/PDDLParserExample.java
and then the following command line to run the example:
java -cp classes:lib/pddl4j-4.0.0.jar fr.uga.pddl4j.examples.PDDLParserExample \\
src/test/resources/benchmarks/pddl/ipc2000/logistics/strips-typed/domain.pddl \\
src/test/resources/benchmarks/pddl/ipc2000/logistics/strips-typed/p01.pddl