Jan 1, 2022
Custom Interpreter
Building a simple interpreter in Python that can execute a custom scripting language.
#Simple Interpreter Project
Welcome to the Simple Interpreter Project! This project is designed to offer a basic understanding of how interpreters work by building a simple interpreter in Python that can execute a custom scripting language. This interpreter can handle variable declarations, assignments, and print statements.
Click here to go to the github repository
#Features
- Variable declaration and assignment.
- Basic print functionality with three different keywords:
print
,log
, andwrite
. - Comments support using
#
at the beginning of the line. - Simple syntax error detection for undefined variables, invalid variable declarations, and invalid assignment statements.
#Getting Started
#Prerequisites
- Python 3.x installed on your system.
#Installation
- Clone or download this repository to your local machine.
- Navigate to the project directory in your terminal.
#Running the Interpreter
To run a script using the interpreter, follow these steps:
- Create a text file (e.g.,
script.txt
) containing your custom scripting language code. Follow the syntax rules described in the Syntax Guide section. - Run the interpreter with your script file as an argument:
#Syntax Guide
#Comments
- Start a line with
#
to create a comment.
#Variable Declarations
- Declare variables using the syntax
var variableName is value
. For example:
#Variable Assignment
- Assign a new value to a variable using the syntax
variableName is newValue
. For example:
#Print Statements
- Print a variable's value using
print
,log
, orwrite
followed by the variable name. For example:
#Example Usage
Consider the following script (example.txt
):
Running this script through the interpreter (python math_language.py example.txt
) will output:
#Contributing
Contributions are welcome! If you have suggestions for improvements or bug fixes, please feel free to fork the repository, make your changes, and submit a pull request.