SimpleScript is a simple programming language interpreter that supports variables, conditional statements, loops, functions, and string operations.
- README.md (this file) - Complete project overview, installation, and usage
- examples/ - Working code examples demonstrating all features
- CONTRIBUTING.md - Development guidelines and architecture
- CHANGELOG.md - Version history and changes
- docs/ - Sphinx documentation (build with
sphinx-build) - grammar.txt - Formal language grammar specification
git clone https://github.com/Ammar-Raneez/Simple_Script.git
cd Simple_Script
./setup.shThis creates a virtual environment and installs everything automatically.
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install SimpleScript
pip install -e .
# Install dev dependencies (optional - for Sphinx docs, linting)
pip install -e ".[dev]"simplescript --version
python -m unittest discover tests -v# Activate virtual environment first
source venv/bin/activate
# Start REPL
simplescript
# or
python -m simplescriptTry these in the REPL:
simplescript > VAR x = 10 + 5
15
simplescript > FUNC square(n) -> n * n
<function SQUARE>
simplescript > square(7)
49
# Run example scripts
simplescript examples/arithmetic.simc
simplescript examples/functions.simc
simplescript examples/comprehensive_demo.simcimport simplescript
# Run code
result, error = simplescript.run('<stdin>', 'VAR x = 10 + 5')
if error:
print(error.as_string())
else:
print(result) # 15
# Run multi-line code
code = """
FUNC add(a, b) -> a + b
add(10, 20)
"""
result, error = simplescript.run('<script>', code)
print(result) # 30- Variables with
VARassignment andSHOWaccess - Arithmetic expressions with operator precedence
- String type with single/double quotes and escape sequences
- Named and anonymous function definitions
- Conditional expressions (IF/ELIF/ELSE)
- For and While loops
- Comparison and logical operators
- Error tracebacks with source location highlighting
VAR identifier = expression
SHOW identifier
Named function (preferred):
FUNC function_name(param1, param2, ...) -> expression
Anonymous function:
VAR function_name = FUNC(param1, param2, ...) -> expression
function_name(arg1, arg2, ...)
IF condition THEN expression ELIF condition THEN expression ELSE expression
FOR identifier = start TO end STEP increment THEN expression
WHILE condition THEN expression
simplescript > VAR A = 10
10
simplescript > SHOW A
10
simplescript > VAR B = 10*(5+2)
70
simplescript > FUNC add(a, b) -> a + b
<function ADD>
simplescript > add(5, 3)
8
simplescript > FUNC square(x) -> x * x
<function SQUARE>
simplescript > square(7)
49
simplescript > VAR abs_val = FUNC(x) -> IF x < 0 THEN -x ELSE x
<function <anonymous>>
simplescript > abs_val(-15)
15
simplescript > "Hello, " + "World!"
"Hello, World!"
simplescript > "ha" * 3
"hahaha"
simplescript > FUNC greet(name) -> "Hello, " + name
<function GREET>
simplescript > greet("Alice")
"Hello, Alice"
simplescript > VAR A = 1
1
simplescript > FOR i=1 TO 6 THEN VAR A = A*i
simplescript > SHOW A
120
simplescript > VAR A = 10/0
Traceback (most recent call last):
File <stdin>, line 1, in <simplescript>
Runtime Error: Division by zero
simplescript > SHOW undefined
Traceback (most recent call last):
File <stdin>, line 1, in <simplescript>
Runtime Error: 'UNDEFINED' is not defined
simplescript/
├── core/ # Lexer, parser, interpreter, constants
├── types/ # Runtime value types (Number, String, Function)
├── ast/ # AST node definitions
├── tokens/ # Token and Position classes
├── errors/ # Error class hierarchy
├── utils/ # Symbol table, result trackers, utilities
├── runtime.py # Main run() entry point
└── cli.py # Command-line interface
tests/ # Test suite
docs/ # Sphinx documentation
See the examples/ directory for ready-to-run scripts:
arithmetic.simc- Basic math operationsstrings.simc- String handlingfunctions.simc- Function definitionsloops.simc- FOR and WHILE loopscomprehensive_demo.simc- All features combined
Run with: simplescript examples/<filename>.simc
# Run setup script (creates venv, installs dependencies)
./setup.sh
# Or manually
source venv/bin/activate
pip install -e ".[dev]"# All tests
python -m unittest discover tests -v
# Specific test class
python -m unittest tests.test_integration.TestFunctionsNamed -v# Requires dev dependencies
cd docs
sphinx-build -b html . _build/html
open _build/html/index.html # macOS
# or: xdg-open _build/html/index.html # Linux# Lint code
flake8 simplescript --count --max-line-length=127 --statistics
# Check for syntax errors
flake8 simplescript --count --select=E9,F63,F7,F82 --show-source- Examples: See
examples/directory - API Docs: Build with Sphinx (see Development section)
- Grammar: See
grammar.txtfor formal specification - Contributing: See
CONTRIBUTING.md - Changelog: See
CHANGELOG.md
Make sure virtual environment is activated:
source venv/bin/activateOr use: python -m simplescript
Try recreating the virtual environment:
rm -rf venv
python3 -m venv venv
source venv/bin/activate
pip install -e .