A simple, experimental programming language designed to mimic the sequential and conditional logic of flowcharts.
Flowchart-Lang (FCL) is a simple, experimental programming language designed to mimic the sequential and conditional logic of flowcharts. It's interpreted by a Python script and is intended for learning basic programming concepts.
To run FCL programs, you'll need the FCL interpreter and a simple batch file wrapper (for Windows).
Save the interpreter code (typically named `flowchart.py`) to a directory, for example: `C:\FlowchartLang\flowchart.py`
In the same directory as `flowchart.py`, create a new file named `flowchart.bat`. Open it with a text editor and add the following content:
@echo off python "%~dp0flowchart.py" %*
This batch file allows you to run your FCL programs directly using the `flowchart` command.
FCL programs are plain text files with the `.fcl` extension. Each command typically occupies its own line.
Every FCL program must begin with START
and end with END
:
START
-- Your FCL commands go here --
END
Lines starting with --
are treated as comments and ignored by the interpreter.
START
Purpose: Marks the beginning of your program.
Usage: START
END
Purpose: Marks the end of your program.
Usage: END
PRINT
Purpose: Displays text or the value of a variable to the console.
Usage: PRINT "Your text"
or PRINT variableName
Example:
START PRINT "Hello, World!" SET myVariable = "FCL" PRINT myVariable END
SET
Purpose: Assigns a value to a variable.
Usage: SET variableName = value
Example:
SET message = "Welcome!" SET age = 30 SET userAge = age
INPUT
Purpose: Reads a line of text entered by the user and stores it in the specified variable.
Usage: INPUT variableName
Example:
PRINT "What is your favorite color?" INPUT favoriteColor PRINT "You like " + favoriteColor + "!"
IF / ELSE / ENDIF
Purpose: Implements conditional logic. Supported Operators: `==` (equals), `!=` (not equals)
Usage:
IF variable == value -- Code to execute if condition is true -- ELSE -- Code to execute if condition is false (optional) -- ENDIF
WHILE / ENDWHILE
Purpose: Implements a loop that repeats as long as the condition is true. Supported Operators: `==`, `!=`
Usage:
WHILE variable != value -- Code to execute in the loop -- ENDWHILE
INCREMENT
Purpose: Increases the value of a numeric variable by 1.
Usage: INCREMENT variableName
Example: INCREMENT count
FCL supports custom commands via Python libraries in the `libs/` folder. Libraries are loaded automatically when the interpreter starts. You can use the IMPORT libraryName
command for clarity, but it is optional.
Example: Math Library
The included `math.py` library adds an `ADD` command:
ADD result = a + b
Once you have `flowchart.py` and `flowchart.bat` set up, and an `.fcl` program file (e.g., `myprogram.fcl`), you can run it from your Command Prompt.
cd C:\Path\To\Your\FCL\Files
flowchart -r myprogram.fcl
flowchart -s myprogram.fcl
START PRINT "Welcome to your first FCL application!" PRINT "Please enter your name:" INPUT userName PRINT "Hello, " + userName + "!" IF userName == "Alice" PRINT "What a lovely name, Alice!" ELSE PRINT "That's a nice name too!" ENDIF SET favoriteNumber = 42 PRINT "Your favorite number is: " + favoriteNumber IF favoriteNumber != 100 PRINT "That's not 100!" ELSE PRINT "Wow, 100 is a great number!" ENDIF PRINT "This is a simple application with conditional logic." END
This example uses the ADD
command from the math library.
START -- This program calculates and prints the Fibonacci sequence. SET a = 0 SET b = 1 SET n = 10 SET counter = 0 IMPORT math PRINT "Starting Fibonacci sequence generation..." WHILE counter != n PRINT a ADD next_fib = a + b SET a = b SET b = next_fib INCREMENT counter ENDWHILE PRINT "Fibonacci sequence finished!" END
ENDIF
or ENDWHILE
).To add new commands, create a Python file in the `libs/` folder. See `libs/template.py` for a starting point. Each library must define a `commands` dictionary mapping FCL command names to Python functions.