How zacharyvmm/logic-expression-simplifier works
Project Type and Purpose
• This is a C-based command-line tool (not a full-stack web app) whose sole purpose is to simplify propositional logic expressions. It acts as a small “compiler-style” pipeline: it lexes the input, parses it into an AST (binary expression tree), applies simplification rules, then pretty-prints the result.
High-Level File Structure Analysis
• Top-level files:
• README.md, Report.pdf (documentation)
• src/Makefile (build automation)
• src/*.c, src/*.h (modular C code)
• Core modules:
• main.c – orchestrates the entire flow
• parser.c/h – tokenizes input and builds the AST
• node.c/h – defines and manipulates tree-node data structures
• solve.c/h – walks the AST and applies logical simplification rules
• .c/h – serializes the simplified AST back to a string and outputs it
Key Components
a. CLI Frontend
• User’s console input → main.c
b. Lexer & Parser
• lexer (embedded in parser.c) tokenizes the string into ENUM tokens
• parser builds a binary expression tree (AST)
c. AST Representation
• node.c/h structures (internal tree nodes with operator/value, left/right pointers)
d. Simplifier (Solver)
• solve.c/h applies logical laws in a greedy traversal over the AST
e. Output Formatter (Display)
• .c/h traverses the simplified AST, generates a string, and prints to stdout
f. Build & Deployment
• Makefile invokes GCC to compile modules and link the executable
Relationships and Data Flows
• main.c calls “Parser” → produces AST
• AST passed to “Solver” → returns simplified AST
• simplified AST passed to “Display” → outputs string to console
• Node utilities are used by both Parser and Solver (depicted as a shared library or component)
• Makefile sits “outside” at build time but is not part of runtime flow
Architectural Patterns & Design Principles
• Pipeline pattern: data transformation in sequential stages (Lex → Parse → Simplify → Render)
• Modular C design: each .c/.h pair encapsulates one concern
• Single responsibility: parser only builds AST, solver only applies rules, display only prints
• Extensibility point: new logical laws could be added to solve.c