Last active
August 29, 2015 14:14
-
-
Save primaryobjects/1d2f7ee668b62ca99095 to your computer and use it in GitHub Desktop.
Javascript parser for STRIPS PDDL grammar parser from pegjs.org. This code parses the result of the pegjs grammar produced from the file grammar.txt https://gist.github.com/primaryobjects/22363e71112d716ea183 and returns a JSON object with the action operators, conditions, and effects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
grammar.txt: saved from https://gist.github.com/primaryobjects/22363e71112d716ea183 | |
domain.txt: | |
(define (domain random-domain) | |
(:requirements :strips :typing) | |
(:action op1 | |
:parameters (?x1 ?x2 ?x3) | |
:precondition (and (S ?x1 ?x2) (R ?x3 ?x1)) | |
:effect (and (S ?x2 ?x1) (S ?x1 ?x3) (not (R ?x3 ?x1)))) | |
(:action op2 | |
:parameters (?x1 ?x2 ?x3) | |
:precondition (and (S ?x3 ?x1) (R ?x2 ?x2)) | |
:effect (and (S ?x1 ?x3) (not (S ?x3 ?x1))))) | |
*/ | |
var fs = require('fs'); | |
var PEG = require("pegjs"); | |
var util = require('util'); | |
fs.readFile('grammar.txt', 'utf8', function(err, grammar) { | |
if (err) throw err; | |
var parser = PEG.buildParser(grammar); | |
fs.readFile('domain.txt', 'utf8', function(err, domain) { | |
if (err) throw err; | |
var result = parser.parse(domain); | |
console.log(JSON.stringify(result)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment