This repository contains the implementation of a Lexical Analyzer, Recursive-Descent Parser, and Interpreter for a Mini C-Like Language (MCL). It spans three programming segments: PA1, PA2, and PA3.
This component tokenizes source code written in MCL. It classifies lexemes into:
- Keywords: PROGRAM, IF, ELSE, PRINT...
- Identifiers: Case-sensitive variable names
- Constants: Integer, Float, Boolean, String, Char
- Operators & Delimiters: +, -, *, /, =, {}, (), ;, etc.
The analyzer uses a DFA (Deterministic Finite Automaton) to recognize tokens character by character. Errors are flagged if the token is invalid.
This parser validates MCL source code against its EBNF grammar. It builds a parse tree and reports syntax errors with line numbers. Each non-terminal rule in the grammar is implemented as a C++ function.
This stage extends the parser to interpret and execute MCL code in real time.
Features:
- Variable declaration and symbol tables
- Arithmetic and logical expression evaluation
- Statement execution: assignment, if-else, print
- Type checking and casting
- Runtime error detection (e.g., using uninitialized vars)
Implements a Value class to represent values with associated types at runtime.