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, and write.
  • 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

  1. Clone or download this repository to your local machine.
  2. Navigate to the project directory in your terminal.

#Running the Interpreter

To run a script using the interpreter, follow these steps:

  1. Create a text file (e.g., script.txt) containing your custom scripting language code. Follow the syntax rules described in the Syntax Guide section.
  2. Run the interpreter with your script file as an argument:
Terminal
python math_language.py script.txt

#Syntax Guide

#Comments

  • Start a line with # to create a comment.

#Variable Declarations

  • Declare variables using the syntax var variableName is value. For example:
var x is 10

#Variable Assignment

  • Assign a new value to a variable using the syntax variableName is newValue. For example:
x is 20
  • Print a variable's value using print, log, or write followed by the variable name. For example:
print x
log x
write x

#Example Usage

Consider the following script (example.txt):

example.txt
# Defining variables.
var test is 69
var defined_value is 0

# Redefining variables.
defined_value is 1

# Printing variables.
print defined_value
print test

Running this script through the interpreter (python math_language.py example.txt) will output:

1
69

#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.