Skip to content

Instantly share code, notes, and snippets.

@gigaherz
Last active July 8, 2017 15:52
Show Gist options
  • Save gigaherz/9fb7469dbb2b35ab90699d634781dd2b to your computer and use it in GitHub Desktop.
Save gigaherz/9fb7469dbb2b35ab90699d634781dd2b to your computer and use it in GitHub Desktop.
A concept for a JSON-encoded Java AST
{
"PROGRAM": "Name here",
"VERSION": "1.0",
"Program": {
"TYPE": "class",
"SUPER": "Application",
"ATTRIBUTES": [ "public", "static"],
"FORMAT": 1,
"MEMBERS": {
"main": {
"TYPE": "method",
"ATTRIBUTES": [ "public", "static"],
"ARGUMENTS": { "args": "String[]" },
"RETURNS": "int",
"LOCALS": {
"ret": "int"
},
"BODY": [
{
"TYPE": "assignation",
"TARGET": { "TYPE": "var_ref", "SYMBOL": "ret" },
"VALUE": {
"TYPE": "static_call",
"TARGET": "java.lang.Integer.parseInt",
"ARGUMENTS": [
{
"TYPE": "array_subscript",
"TARGET": { "TYPE": "var_ref", "SYMBOL": "args"},
"INDEX": { "TYPE": "literal", "VALUE": 0 }
}
]
}
},
{
"TYPE": "static_call",
"TARGET": "java.lang.System.out.print",
"ARGUMENTS": [
{ "TYPE": "literal", "VALUE": "The number is: " }
]
},
{
"TYPE": "static_call",
"TARGET": "java.lang.System.out.println",
"ARGUMENTS": [
{ "TYPE": "var_ref", "SYMBOL": "ret" }
]
},
{
"TYPE": "return",
"VALUE": { "TYPE": "var_ref", "SYMBOL": "ret" }
}
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment