How teobacher/interpreteur-c works
Project type and purpose
• This is a small command-line interpreter written in C. It reads source (either interactively or from a file), lexes it into tokens, parses those tokens into an abstract syntax tree (AST), and then evaluates (executes) that tree.
File structure
• Top-level: README.md, LICENSE, .gitignore, sujet.md
• src/: contains three pairs of modules—input, lexer, parser—and a tests/ subdirectory.
• input.c/h: handles reading from stdin or file
• lexer.c/h: converts raw characters to tokens
• parser.c/h: builds the AST and performs evaluation
• src/tests/: sample input programs for regression testing
README for additional insights
• Execution modes: interactive vs file mode
• Debug mode toggle in lexer.h to trace the lex/parse/AST steps
• Feature list: arithmetic, variables, precedence, conditions, loops, typing, comments, strings
Main components
a. CLI Driver (main)
• Entry point that parses command-line flags (mode, debug) and invokes the pipeline.
b. Input Module
• Reads raw text from stdin or file
• Passes a character buffer to the lexer
c. Lexer Module
• Tokenizes the character stream into a token stream
• Honors DEBUG flag to emit tokenization steps
d. Parser Module
• Consumes tokens, constructs an AST
• Performs syntax validation, type checking
e. AST / Symbol Table
• In-memory representation of program structure
• Symbol table to store variable names/values
f. Evaluator / Interpreter
• Walks the AST, executes statements and expressions
• Updates symbol table, handles control flow (if, while, for)
g. Output
• Prints results or error messages to stdout
h. Test Suite
• src/tests/*.txt supplies sample programs; CLI driver can load them in file mode for regression tests
Relationships and data flow
• CLI → Input Module → Lexer → Parser → AST/Symbol Table → Evaluator → Output
• The DEBUG flag branches inside the Lexer and Parser to emit logs.
Architectural patterns and principles
• Modular pipeline (lexer → parser → evaluator) follows classic compiler design
• Clear separation of concerns: each module has a single responsibility
• In-memory AST and symbol table support incremental evaluation
Technologies and languages
• C99 (gcc)
• No external dependencies
• Build script is a simple gcc command in README