Flowchart-Lang (FCL)

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.

Getting Started

To run FCL programs, you'll need the FCL interpreter and a simple batch file wrapper (for Windows).

1. Prerequisites

  • Python 3: Ensure you have Python 3 installed on your system. You can download it from python.org. Make sure it's added to your system's `PATH` during installation.

2. Setup

Save the Interpreter

Save the interpreter code (typically named `flowchart.py`) to a directory, for example: `C:\FlowchartLang\flowchart.py`

Create the Launcher (Windows)

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.

How to Code in FCL

FCL programs are plain text files with the `.fcl` extension. Each command typically occupies its own line.

Basic Structure

Every FCL program must begin with START and end with END:

START
    -- Your FCL commands go here --
END
                        

Comments

Lines starting with -- are treated as comments and ignored by the interpreter.

Commands & Extending FCL

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


Extending FCL with Libraries

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
                        

Running an FCL Program

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.

Steps

  1. Open Command Prompt.
  2. Navigate to your FCL program's directory: cd C:\Path\To\Your\FCL\Files
  3. Execute your program: flowchart -r myprogram.fcl
    Or to run it step-by-step: flowchart -s myprogram.fcl

Example FCL Programs

Basic Example

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
                            

Advanced Example: Fibonacci Sequence

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
                            

Error Handling

  • The interpreter will display an error message and exit if you use an undefined variable, invalid syntax, or mismatched control blocks (e.g., missing ENDIF or ENDWHILE).
  • Custom libraries can also print errors if their commands are used incorrectly.

Creating Your Own Library

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.