Javascript+java8 nashorn contains a javascript AST parser. See // http://stackoverflow.com/questions/29154309/nashorn-parser-api-on-jdk-8
function x(n) {var a=[];for(var i=0;i< n;i++) { a.push(i); }} x(1000);
#run
$ jjs test.js | python -m json.tool
#output:
{
"body": [
{
"body": {
"body": [
{
"declarations": [
{
"id": {
"name": "a",
"type": "Identifier"
},
"init": {
"elements": [],
"type": "ArrayExpression"
},
"type": "VariableDeclarator"
}
],
"type": "VariableDeclaration"
},
{
"declarations": [
{
"id": {
"name": "i",
"type": "Identifier"
},
"init": {
"type": "Literal",
"value": 0
},
"type": "VariableDeclarator"
}
],
"type": "VariableDeclaration"
},
{
"body": {
"body": [
{
"expression": {
"arguments": [
{
"name": "i",
"type": "Identifier"
}
],
"callee": {
"computed": false,
"object": {
"name": "a",
"type": "Identifier"
},
"property": "push",
"type": "MemberExpression"
},
"type": "CallExpression"
},
"type": "ExpressionStatement"
}
],
"type": "BlockStatement"
},
"init": null,
"test": {
"left": {
"name": "i",
"type": "Identifier"
},
"operator": "<",
"right": {
"name": "n",
"type": "Identifier"
},
"type": "BinaryExpression"
},
"type": "ForStatement",
"update": {
"argument": {
"name": "i",
"type": "Identifier"
},
"operator": "++",
"prefix": false,
"type": "UpdateExpression"
}
}
],
"type": "BlockStatement"
},
"defaults": [],
"expression": false,
"generator": false,
"id": {
"name": "x",
"type": "Identifier"
},
"params": [
{
"name": "n",
"type": "Identifier"
}
],
"rest": null,
"type": "FunctionDeclaration"
},
{
"expression": {
"arguments": [
{
"type": "Literal",
"value": 1000
}
],
"callee": {
"name": "x",
"type": "Identifier"
},
"type": "CallExpression"
},
"type": "ExpressionStatement"
}
],
"type": "Program"
}