Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Created October 31, 2020 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRayCode/8c8cc2cbefa2108f86f9f6833aa1bcf5 to your computer and use it in GitHub Desktop.
Save AndrewRayCode/8c8cc2cbefa2108f86f9f6833aa1bcf5 to your computer and use it in GitHub Desktop.
// Input
if (a) {1;} else if(b) {2;} else {3;}
// AST
{
"name": "if",
"condition": [
{ "name": "(" },
{ "name": "identifier", "children": [ "a" ] },
{ "name": ")", "children": [ " " ] }
],
// Body of if
"children": [
{ "name": "{" },
{ "name": "int_constant", "children": [ "1" ] },
{ "name": ";" },
{ "name": "}", "children": [ " " ] }
],
"else": [
{ "name": "else", "children": [ " " ] },
{
// else if
"name": "if",
"children": [
{ "name": "{" },
{ "name": "int_constant", "children": [ "2" ] },
{ "name": ";" },
{ "name": "}", "children": [ " " ] }
],
// else
"else": [
{ "name": "else", "children": [ " " ] },
{ "name": "{" },
{ "name": "int_constant", "children": [ "3" ] },
{ "name": ";" },
{ "name": "}" }
],
"condition": [
{ "name": "(" },
{ "name": "identifier", "children": [ "b" ] },
{ "name": ")", "children": [ " " ] }
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment