From 26e1314c7ab843987ac0eb28deb96e708b2e943f Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Mon, 5 Oct 2020 21:49:05 +0300 Subject: Add AST for simple JavaScript function --- website/content/slides/01_dragons/_index.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/website/content/slides/01_dragons/_index.md b/website/content/slides/01_dragons/_index.md index 52ecf91..7892a65 100644 --- a/website/content/slides/01_dragons/_index.md +++ b/website/content/slides/01_dragons/_index.md @@ -197,7 +197,26 @@ LR(n) and LALR(n) are family of parsing algorithms for CFG --- ###### AST -# TODO: use JavaScript AST dumper +https://esprima.org/demo/parse.html?code=function%20answer()%20%7B%0A%20%20%20%20return%206%20*%207%3B%0A%7D + + { + "type": "FunctionDeclaration", + "id": { "type": "Identifier", "name": "answer" }, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "*", + "left": { "type": "Literal", "value": 6 }, + "right": { "type": "Literal", "value": 7 } + } + } + ] + }, + } --- ### Middle -- cgit v1.3.1-23-gd82d