Skip to content

Instantly share code, notes, and snippets.

@dwaite
Created October 12, 2010 22:51
Show Gist options
  • Save dwaite/623074 to your computer and use it in GitHub Desktop.
Save dwaite/623074 to your computer and use it in GitHub Desktop.
{
"type": "Program",
"elements": [
{
"type": "VariableStatement",
"declarations": [
{
"type": "VariableDeclaration",
"name": "a",
"value": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "NumericLiteral",
"value": 1
},
"right": {
"type": "NumericLiteral",
"value": 2
}
}
}
]
}
]
}
util = require('util'),
fs = require('fs'),
peg = require('./peg')
file = fs.readFileSync('ecmascript.pegjs','utf-8')
parser = peg.buildParser(file)
ast = parser.parse('var a = 1+2')
json = JSON.stringify(ast, null, ' ')
util.puts(json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment