Custom Programming Language

A custom programming language built from scratch, includes full tokenizer, parser, interpeter in Python, variables and more


Overview

This custom programming language is a small, interpreted language built from scratch using Python. (took me 50+ hours)

The language uses core compiler/interpreter concepts including lexical analysis, parsing, and interpretation.

Language Processing Pipeline

Source Code
Lexer
Parser
Interpreter
Output

Language Syntax

Basic Syntax Rules

Element Syntax Description
Comments # This is a comment Single line comments using the # symbol
Integer Declaration age = int(15) Declare and initialize an integer variable
String Declaration name = string("Jim") Declare and initialize a string variable
Output Statement say("Hello World") Print text or variable values to output
Variable Output say(variableName) Print the value of a variable

Code Examples

Hello World Program

# My first program in the custom language
say("Hello, World!")

Variable Declaration and Usage

# Declare variables
age = int(16)
name = string("Alice")

# Output variables
say(name)
say(age)

Technical Architecture

Lexer (Tokenizer)

Reads the code and splits it into pieces called tokens, like words and symbols.

Parser

Uses these tokens to build a tree that shows the program’s structure.

Interpreter

Walks through the tree and runs the program step-by-step.

Symbol Table

Keeps track of variables, their types, and current values while the program runs.

Token Types

The lexer recognizes the following token types:

  • Keywords: int, string
  • Identifiers: Variable names
  • Literals: String literals, integer literals
  • Operators: Assignment (=)
  • Delimiters: Parentheses, quotes
  • Functions: say
  • Comments: Lines starting with #

Getting Started

Requirements

This project requires NO pip imports!

To run programs in this custom language, you need:

  • Python 3.6 or higher installed on your system
  • The github repository cloned
  • A text editor to write your programs

Running Your First Program

Follow these steps to create and run your first program:

# 1. Create a new file with .txt extension (e.g., hello.txt)
# 2. Write your program:
say("Hello from my custom language!")
# 3. Run using the python file:
# python run.py hello.txt

Debug Mode

Enable debug mode to see how your program is processed:

Mady with love by Jim