목차

  1. AST가 무엇?
  2. AST 추출 과정
  3. JSON과 tokenizing & lexing

AST(Abstract Syntax Tree)

function add(a, b) {
	return a + b
}

위 함수를 AST explorer(https://astexplorer.net/) 에서 분석하면, 다음의 구조를 가져올 수 있다.

{
	type: "FunctionDeclaration"
	id: {
		type: "Identifier"
		name: "add"
	},
	params: [
		{
			type: "Identifier"
			name: "a"
		},
		{
			type: "Identifier"
			name: "b"
		},
	],
	body: {
		type: "BlockStatement"
		body: [
			{
				type: "ReturnStatement"
				argument: {
					type: "BinaryExpression"
					left: {
						type: "Identifier"
						name: "a"
					}
					operator: "+"
					right: {
						type: "Identifier"
						name: "b"
					}
				}
			}
		]
	}
}