My Really "dumb" Programming Language

There are many tools to help define and execute new programming languages. (None used here.) Hopefully the following gives you a feel for the programming language creation process.

Example of My Program Language

# my first program set, x, 12 set, a, 4 set, b, 5 set, c, a + b loop abc print, " c is ", c , " x is ", x if c > x: exit set, c, c + 1 goto, abc

Language Definition

Basic rules

Reserved Words

Math Operators

Comparisons Operators (True or False)

Click HERE for a formal (Backus Naur Form) description of my language.

Create a Lexical Analyzer?

The results of the example shown above might be:

program = [ ["set", "x", 12], ["set", "a", 10], ["set", "b", 5], ["set", "c", "a","+","b"], ["loop", "abc"], ["print", '" c is ", c," x is ",x'] ["if", "c", "<", "x", ":", "exit"] ["set", "c", "c", "+", "1"] ["goto", abc] ]

To eliminates testing for both upper and lower case convert each statement to uppercase for processing?

Replace commas with spaces and split a statement (on spaces) before processing it into tokens?

For if statements, split on colon (":") then process each part separately?

Create an Execution "Engine"?

Process each statement one at a time and perform the action.

Create a dictionary to hold variable names and their values?

Create a dictionary to hold goto locations in the program's list of statement?

FYI

The string startswith() method returns True if a string starts with a specific value, otherwise it returns False.

Common methods used to remove characters from a string.

Tools

Flex (Fast Lexical Analyzer Generator)

Flex (lexical analyser generator) (Wikipedia)

GNU Bison

GNU Bison (Wikipedia)

Compiler Construction using Flex and Bison

Win flex-bison