we (web engine): Experimental web browser project to understand the limits of Claude

JS Parser: AST and expression/statement parsing #91

open opened by pierrelf.com

Implement a JavaScript parser that transforms a token stream into an Abstract Syntax Tree (AST).

Scope#

Build a recursive-descent parser for ECMAScript 2024. The parser should handle the full expression grammar and all major statement/declaration types.

AST Node Types#

Expressions:

  • Literals: number, string, boolean, null, undefined, array, object, regex
  • Identifier, ThisExpression
  • Unary, binary, logical, conditional (ternary) expressions
  • Assignment expressions (=, +=, -=, etc.)
  • Member access (dot and bracket)
  • Call expressions and new expressions
  • Arrow function expressions
  • Spread element
  • Template literal expressions
  • Comma expressions

Statements:

  • ExpressionStatement, BlockStatement
  • VariableDeclaration (var/let/const)
  • IfStatement, SwitchStatement
  • ForStatement, ForInStatement, ForOfStatement
  • WhileStatement, DoWhileStatement
  • ReturnStatement, ThrowStatement
  • TryStatement (try/catch/finally)
  • BreakStatement, ContinueStatement
  • LabeledStatement

Declarations:

  • FunctionDeclaration (including generator function*)
  • ClassDeclaration (constructor, methods, static methods, getters/setters)
  • Import/Export declarations (basic forms)

Features#

  • Operator precedence handling (Pratt parsing or precedence climbing)
  • Destructuring patterns in variable declarations and parameters
  • Default parameter values
  • Rest parameters (...args)
  • Computed property names ([expr]: value)
  • Shorthand property/method definitions in object literals
  • Syntax error reporting with source location

Acceptance Criteria#

  • AST type definitions for all node types
  • Parser produces correct AST for expressions with proper precedence
  • All statement types parsed correctly
  • Function and class declarations parsed
  • Destructuring patterns supported
  • Arrow functions parsed (including concise body)
  • Meaningful syntax error messages with line/column
  • Unit tests for each grammar production

Phase 10 — JavaScript Engine (issue 2 of 15). Depends on: JS Lexer/Tokenizer.

sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mhn3jtxefv2q