How anthay/eliza works
Project type and purpose
• This is an open-source recreation in C++ of Joseph Weizenbaum’s 1966 ELIZA chatbot.
• It’s delivered primarily as a console application (with an optional serial‐I/O mode) that reads “script” files (S-expression pattern rules) and responds to user input.
• There is also an alternate JavaScript/HTML version for a web demo.
File structure
• src/
– eliza.cpp : the complete ELIZA engine (parser, pattern matcher, response generator)
– serial_io.h + posix_serial_io.cpp / win_serial_io.cpp : platform-specific I/O abstraction
– ymatch.cpp : helper for pattern matching
– eliza.html : standalone JS/HTML port
• scripts/ : various ELIZA script files (DOCTOR, Turing-machine variants, etc.)
• doc/ : design notes, transcriptions, serial-I/O documentation, historical commentary
• scripts.md : index of available sample scripts
• Top-level build instructions in README.md
README for additional insights
• No external services or databases—everything is local and file-based.
• Build targets:
– POSIX: clang++ -std=c++20 -pedantic
– Windows: cl /EHsc /W4 /std:c++20
• Extensibility point: swap in any “.txt” script with S-expressions to change bot behavior.
Main components and their interactions
a. User Interface Layer
– Console I/O or serial-port interface (via serial_io abstraction)
– Web UI (eliza.html + JS engine)
b. Core ELIZA Engine
– Script Loader / S-expression Parser
– Pattern Matcher (ymatch.cpp)
– Response Generator / Substitution Logic
c. Script Repository
– DOCTOR and other “.txt” files under scripts/
d. Build Toolchain
– C++20 compiler (clang++ or cl.exe)
e. Optional External Dependency
– Serial device (ASR-33 teletype) for the serial I/O mode
Architectural patterns and design principles
• Layered architecture: UI → Engine → Data (script files)
• Abstraction of I/O so core logic is platform-agnostic
• Plugin-style extensibility: new scripts simply drop into scripts/
• Single-responsibility modules (parser vs. matcher vs. serial driver)