Skip to content

Meeting Summary: CS 631-01 Systems Foundations

Date: February 10, 2026 — 08:12 AM Pacific
Meeting ID: 870 0988 0761

Quick Recap

The session focused on data structures and parsing techniques in C and Rust for building parse trees.

  • Greg explained how C uses structs and unions to create parse nodes, stressing careful memory allocation and avoiding leaks.
  • He contrasted this with Rust’s ownership model and enums, showing how to build similar parse trees using heap allocation with Box and transferring ownership between scopes.
  • He demonstrated how to use Claude Code to visualize scanning, parsing, and tree construction.
  • The discussion concluded with guidance for extending the parser for Lab 2, including support for binary literals and unary minus.

Next Steps

  • Greg:
  • Add the “visualizer” version of the C parser to the in-class repository.
  • On Thursday, demonstrate and verify modifying nested nodes in a Rust parse tree using mutable references.
  • Students:
  • Extend the scanner and parser for Lab 2 according to the updated grammar and requirements.
  • Implement support for binary literals, unary minus, and parentheses in the parser as specified in the lab notes.
  • Design a non-redundant approach to handle multiple operator types in the C parser (e.g., a helper function or mapping table instead of repeated if/else chains).

Summary

Comparing C and Rust Parse Trees

  • The meeting compared C and Rust data structures for parse trees and highlighted how Rust’s ownership model differs from C’s memory layout.
  • The scanner’s role in converting characters into tokens was reviewed. Rust implementations use enums to represent token kinds.
  • The process of turning tokens into a tree was outlined, along with how that tree can be evaluated.
  • Enums for token representation in C were introduced as an approach to be expanded for the final project.

Rust Memory Management Techniques

  • The Rust implementation avoids explicit malloc/free; tokens and nodes can be stored in stack-allocated arrays, while tree structure is formed with heap-allocated nodes via Box.
  • Rust uses enums (with variants such as value and operator node types) to express node kinds rather than C-style unions; the active variant is known at compile time through the enum tag.
  • Tree construction uses references to child nodes through Box pointers, mapping closely to the grammar (EBNF). The relationship between EBNF and recursive descent search (e.g., for integer values) was emphasized.

NTLANG Parser Structure Overview

  • The parser design for the NTLANG language mirrors the grammar through parsing functions for productions such as program, expression, and operand.
  • The parser tracks acceptable next tokens and constructs a tree from the token sequence.
  • An example from the Lab 2 starter code showed manual tree construction using struct definitions and connecting nodes via pointers.

C Structs and Union Basics

  • C structs define composite data; unions allow a value to be one of several types. The compiler allocates enough space for the largest union member.
  • Visual aids generated with Claude Code illustrated program processing and memory layout over time.

Parse Table Structure and Functionality

  • The parse system pre-allocates nodes in an array (up to 1,024 nodes) and accesses them via pointers.
  • The scanner consumes tokens and maintains indices for current and previous tokens.
  • This served as a preview of a straightforward parsing approach; a specific example will be confirmed later.

Understanding Parsing Mechanisms

  • The role of an accept function in recognizing tokens was explained.
  • Parsing functions are derived directly from EBNF production rules, highlighting the symmetry between EBNF and implementation.
  • Core parsing principles were emphasized as foundational skills transferable to building compilers for other languages.

Expression Parsing Code Review

  • The discussion covered parsing expressions, handling operands and operators, and creating nodes in the parse table.
  • A potential issue was identified: allocation for the right-hand side node of an expression should occur after parsing the left-hand side.
  • The actual parser code was referenced to clarify control flow and memory allocation order.

Parsing and Memory Management Techniques

  • C parsing techniques used recursive descent and explicit parse-tree construction.
  • Visualization of the parsing process with Claude Code helped identify redundancy and flow issues.
  • Rust techniques used enums and Box to create heap-allocated tree structures with methods, leveraging ownership transfers to ensure safe deallocation.
  • The session closed with a preview of Thursday’s topics: debugging strategies for both C and Rust, and techniques for modifying parse trees.