Skip to content

About

Hi, this is my first project, i made after learning python, have fun :)

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Python Scripting Language Interpreter named V#

This project is a custom programming language interpreter built entirely from scratch in Python. It parses and executes a unique syntax, supporting global variables, mathematical operations, conditional logic, and control flow through a live terminal shell or a dedicated text file.

How It's Made:

Tech used: Python

I built this interpreter to gain a deeper understanding of how programming languages ​​parse text and execute logic under the hood. The core engine works by reading a script file ("code_file.txt"), stripping the text, and splitting the lines into commands and parameter tuples. These are then fed into a central execution function.

To handle data dynamically, I built a custom type-caster function that evaluates inputs and classifies them as integers, strings, or globally scoped variables (denoted by bracket syntax like ). The state of the program is maintained using a global dictionary for memory allocation and a program index variable that acts as a program counter.

By manipulating this index, I was able to build functional control flow mechanisms like JUM (jump) to specific named locations and IF conditionals.

Optimizations:

To avoid writing a massive, inefficient chain of conditional if/else statements to evaluate every possible command, I utilized a dictionary dispatch pattern. I mapped the string commands (like "MOV", "ADD", "PRINT") directly to their corresponding Python functions in a dictionary called syntax_commands.

Additionally, instead of hardcoding comparison logic for the IF statements, I imported Python's built-in operator module (lt, le, gt, ge, eq, ne) and mapped these to a dictionary. This made the execution engine significantly faster, highly modular, and much easier to extend with new language features.

Lessons Learned:

Building this project taught me a massive amount about state management, tokenization, and execution loops. The biggest breakthrough was getting the JUM (jump) and LOC (location) commands to work together as well as the built in degugger. It was a big realization that standard loops (like while or for loops in higher-level languages) are essentially just conditional jumps manipulating a program counter under the hood. I also learned the strict importance of error handling and type checking; When building a custom syntax, you have to anticipate edge cases where a user might try to add a string to an integer and handle those exceptions gracefully.

Getting Started

Prerequisites:

  • Python 3.x

Installation:

  1. Clone this repository
  2. Navigate to the code/main/ directory
  3. You're ready to go!

Usage:

Option 1: Interactive Shell Run main.py with an empty code_file.txt to use the interactive shell:

python main.py

Then type V# commands directly:

>>> MOV <x> 5
>>> MOV <y> 3
>>> ADD <x> <y>
>>> PRINT <x>

Option 2: Execute a Script Create a code_file.txt file with your V# program, then run main.py. Example code_file.txt: It has to be code_file.txt or else it will NOT work

MOV <counter> 0
LOC LOOP
ADD <counter> 1
PRINT <counter>
IF <counter> < 5 JUMP LOOP
END

For detailed syntax documentation, see syntax_readme.md.

About

Hi, this is my first project, i made after learning python, have fun :)

Resources

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages