Loading the code workspace…
Design and implement AST node structures for a C-like language.
Define an ASTNodeType enum covering:
NODE_BINARY, NODE_UNARY, NODE_LITERAL, NODE_IDENTIFIER, NODE_CALLNODE_RETURN, NODE_IF, NODE_WHILE, NODE_BLOCK, NODE_EXPR_STMTNODE_VAR_DECL, NODE_FUNC_DECL, NODE_PARAMNODE_PROGRAM (root node)Create a flexible ASTNode struct:
Implement constructor functions:
ast_create_literal(value, type)ast_create_binary(operator, left, right)ast_create_unary(operator, operand)ast_create_if(condition, then_branch, else_branch)ast_create_node(type)Implement ast_destroy() that recursively frees the tree
int x = 2 + 3;if (x > 0) return x; else return -x;The AST you design mirrors Clang's Expr/Stmt hierarchy and the estree format that every JavaScript tool — Babel, ESLint, Prettier — agrees on. AST shape decides what analyses are cheap: Prettier can reprint your code and Babel can transform JSX only because their node structures preserve enough source fidelity.
Sample case for Run. Submit grades this sample plus all hidden tests.