Skip to content

Instantly share code, notes, and snippets.

@vaidehijoshi
Last active December 5, 2017 03:39
Show Gist options
  • Save vaidehijoshi/8080ab913f4a1e8a1a3b9e0387bf5c3a to your computer and use it in GitHub Desktop.
Save vaidehijoshi/8080ab913f4a1e8a1a3b9e0387bf5c3a to your computer and use it in GitHub Desktop.
// Using Esprima, a ECMAScript parser written in ECMAScript
// var esprima = require('esprima');
// var program = 'const answer = 42';
// Syntax
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "result"
},
"init": {
"type": "BinaryExpression",
"operator": "+",
"left": {
"type": "Literal",
"value": 5,
"raw": "5"
},
"right": {
"type": "BinaryExpression",
"operator": "*",
"left": {
"type": "Literal",
"value": 1,
"raw": "1"
},
"right": {
"type": "Literal",
"value": 12,
"raw": "12"
}
}
}
}
],
"kind": "var"
}
],
"sourceType": "script"
}
// Token List
[
{
"type": "Keyword",
"value": "var"
},
{
"type": "Identifier",
"value": "result"
},
{
"type": "Punctuator",
"value": "="
},
{
"type": "Numeric",
"value": "5"
},
{
"type": "Punctuator",
"value": "+"
},
{
"type": "Punctuator",
"value": "("
},
{
"type": "Numeric",
"value": "1"
},
{
"type": "Punctuator",
"value": "*"
},
{
"type": "Numeric",
"value": "12"
},
{
"type": "Punctuator",
"value": ")"
},
{
"type": "Punctuator",
"value": ";"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment