A lightweight, browser-based programming playground that lets users write and run expressions in a custom mini-language powered by a Python interpreter.
Functional Programming Playground is an educational web application designed to demonstrate how a language runtime works end-to-end:
- Lexing turns source text into tokens.
- Parsing transforms tokens into an Abstract Syntax Tree (AST).
- Evaluation executes AST nodes inside a scoped environment.
- Web delivery provides an interactive editor and instant feedback loop in the browser.
The project is intentionally compact, making it ideal for students, bootcamp learners, and engineers who want a clear, practical reference for interpreter architecture.
- In-browser code editor with syntax-highlighted input via CodeMirror.
- Support for numeric expressions and arithmetic operators:
+,-,*,/. - Variable assignment and lookup (for example,
x = 10 * 2). - Conditional expressions using
if { ... } else { ... }syntax. - Structured runtime error feedback (syntax errors, undefined variables, division by zero, invalid characters).
- Flask application serves the UI and exposes a
/runexecution endpoint. - The front-end submits code to the backend and renders either the computed result or an error message.
tokens.pydefines lexical rules with PLY lex.parser.pydefines grammar and AST node types with PLY yacc.evaluator.pywalks the AST and executes expressions using an environment model.
Together, these modules provide a concise but complete language pipeline.
- Backend: Python, Flask
- Language tooling: PLY (Python Lex-Yacc)
- Frontend editor: CodeMirror
- Styling/UI: HTML + CSS
- Python 3.9+
pip
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtpython -m web.appThen open http://127.0.0.1:5000 in your browser.
x = 10 * 2
x + 5You can also evaluate conditionals in the supported grammar form:
if 1 { 42 } else { 0 }- Learners studying interpreters and compilers.
- Instructors looking for a compact teaching artifact.
- Developers prototyping language ideas before scaling into a full compiler/runtime.
- Multi-statement program support.
- First-class functions and function calls.
- Better static diagnostics and source-positioned error messages.
- Save/share playground snippets.
This repository currently has no explicit license file. Add a license before public distribution if you plan to share or commercialize it.