This interpreter processes a simple plotting language and generates 2D parametric curves. It demonstrates core compiler design concepts:
- Front-End: Lexer (DFA-based scanner) → Parser (recursive-descent with operator precedence)
- Middle-End: Semantic analyzer with expression evaluator and coordinate transformation engine
- Back-End: Dual rendering systems (console debugger and Windows GDI visualizer)
- Compiler: GCC 7+, Clang 5+, or MSVC 2017+ with C++17 support
- CMake: 3.15 or higher
- Operating System:
- Windows: Full support (console + GUI)
- Linux/macOS: Console mode only
- Google Test: All dependencies are included in the repository (
lib/googletest/) for out-of-the-box building
git clone https://github.com/gzhiahia/function-plotter-interpreter.git
cd function-plotter-interpreter
# Windows (MinGW)
cmake -B build -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release
cmake --build build
# Windows (Visual Studio)
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
# Linux/macOS
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j $(nproc)Basic Usage:
# Console version
.\build\bin\interpreter_console.exe example\interpreter_test.txt
# Windows GUI version
.\build\bin\interpreter_window.exe example\interpreter_test.txtCommand-line Options:
# Show help information
.\build\bin\interpreter_console.exe -h
.\build\bin\interpreter_console.exe --help
# Enable debug mode (shows detailed execution info)
.\build\bin\interpreter_console.exe example\interpreter_test.txt -d
.\build\bin\interpreter_console.exe example\interpreter_test.txt --debugcd build
# Run all tests
ctest --output-on-failure
# Run specific test suite
ctest -R LexerTest
ctest -R ParserTest
# Verbose output
ctest -V// Comments start with double slash
-- Set coordinate system
ORIGIN IS (x, y); -- Translation
SCALE IS (sx, sy); -- Scaling factors
ROT IS angle; -- Rotation angle (radians)
-- Draw parametric curve
FOR variable FROM start TO end STEP increment DRAW (x_expr, y_expr);
// Draw a circle
ORIGIN IS (400, 300);
SCALE IS (100, 100);
ROT IS 0;
FOR T FROM 0 TO 2*PI STEP 0.01 DRAW (COS(T), SIN(T));
- Trigonometric:
SIN(x),COS(x),TAN(x) - Exponential:
EXP(x) - Logarithmic:
LN(x) - Square Root:
SQRT(x)
PI- π (3.14159...)E- Euler's number (2.71828...)
- Arithmetic:
+,-,*,/,** - Parentheses:
(,)
function-plotter-interpreter/
├── CMakeLists.txt
├── LICENSE
├── README.md
├── .gitignore
│
├── assets/
│ └── demo.jpg
│
├── include/ # Public header files
│ ├── core/
│ │ └── Interpreter.h # Main interpreter
│ ├── lexer/
│ │ ├── DFA.h # Finite automaton
│ │ ├── Scanner.h # Lexical scanner
│ │ └── Token.h # Token definitions
│ ├── parser/
│ │ ├── ExpressionNode.h # AST nodes
│ │ └── Parser.h # Recursive-descent parser
│ ├── semantic/
│ │ ├── ExpressionEvaluator.h # Expression evaluator
│ │ ├── SemanticAnalyzer.h # Semantic analyzer
│ │ └── TransformationEngine.h # Coordinate transforms
│ └── ui/
│ ├── IRenderer.h # Renderer interface
│ ├── ConsoleRenderer.h # Console renderer
│ └── WindowRenderer.h # Windows GDI renderer
│
├── src/ # Implementation files
│ ├── core/
│ │ └── Interpreter.cpp
│ ├── lexer/
│ │ ├── DFA.cpp
│ │ ├── Scanner.cpp
│ │ └── Token.cpp
│ ├── parser/
│ │ ├── ExpressionNode.cpp
│ │ └── Parser.cpp
│ ├── semantic/
│ │ ├── ExpressionEvaluator.cpp
│ │ ├── SemanticAnalyzer.cpp
│ │ └── TransformationEngine.cpp
│ ├── ui/
│ │ ├── ConsoleRenderer.cpp
│ │ └── WindowRenderer.cpp
│ └── main/
│ ├── ConsoleMain.cpp # Console entry point
│ └── WindowMain.cpp # Windows GUI entry point
│
├── test/ # Unit tests
│ ├── LexerTest.cpp
│ └── ParserTest.cpp
│
├── example/ # Example scripts
│ ├── interpreter_test.txt
│ ├── lexer_test.txt
│ └── parser_test.txt
│
└── lib/ # Third-party libraries
└── googletest/
┌───────────────────────────────────────────────────┐
│ Main Application │
│ (ConsoleMain / WindowMain) │
└───────────────────────┬───────────────────────────┘
│
▼
┌───────────────────────────────────────────────────┐
│ Interpreter │
│ (Orchestrates the compilation process) │
└────┬───────────┬─────────────┬──────────────┬─────┘
│ │ │ │
▼ ▼ ▼ ▼
┌───────┐ ┌────────┐ ┌──────────┐ ┌──────────┐
│ Lexer │ → │ Parser │ → │ Semantic │ → │ Renderer │
│ (DFA) │ │ (AST) │ │ Analyzer │ │ (UI) │
└───────┘ └────────┘ └──────────┘ └──────────┘
- Color & Line Width customization
- Cross-platform GUI (SFML/Qt/wxWidgets)
- Export to image files (PNG/SVG)
