An interpreter for CFPL (CIT-University's First Programming Language)
CFPL is a very simple programming language that allows the programmer to achieve fluency in minutes.
It is a strongly typed programming language.
It is intended for students enrolled in programming languages.
It aims to train them on how to build a pure interpreter.
Program Structure:
1. Every line contains a single statement
2. All variable declaration is found on top of the program
3. A line that starts with asterisk(*) is considered as a comment and comment can be found in any
part of the program
4. executable code should be found inside the START and STOP block
5. all reserved words are in capital letters
6. sharp sign(#) signifies next line or carriage return
7. ampersand(&) serves as a concatenator
8. the square braces([]) are as escape code
Data Types:
INT – an ordinary number with no decimal part. It uses 32 bits. It can be positive or negative.
CHAR – a single symbol. It uses UNICODE.
BOOL – represents the literals TRUE or FALSE.
FLOAT – a number with decimal part. It uses 64 bits.
Operators:
Arithmetic operators
( ) - parenthesis
*, /, % - multiplication, division, modulo
+, - - addition, subtraction
>, < - greater than, lesser than
>=, <= - greater than or equal to, lesser than or equal to
==, <> - equal, not equal
Logical operators (<BOOL expression><LogicalOperator><BOOL expression>)
AND - needs the two BOOL expression to be true to result to true, else false
OR - if one of the BOOL expressions evaluates to true, returns true, else false
NOT - the reverse value of the BOOL value
Unary operator
+ - positive
- - negative
Control structures:
If-else statement
IF (<BOOL expression>)
START
<statement>
STOP
IF (<BOOL expression>)
START
<statement>
STOP
ELSE
START
<statement>
STOP
While statement
WHILE (<BOOL expression>)
START
<statement>
STOP
INPUT – allow the user to input a value to a data type.
Syntax:
INPUT: <variableName>[,<variableName>]*
Sample use:
INPUT: x, y
means in the screen you have to input two values separated by comma(,)
* my first program in CFPL
VAR abc, b, c AS INT
VAR x, w_23='w' AS CHAR
VAR t="TRUE" AS BOOL
START
abc=b=10
w_23='a'
* this is a comment
OUTPUT: abc & "hi" & b & "#" & w_23 & "[#]"
STOP
10hi10
a#
VAR xyz, abc=100 AS INT
START
xyz= ((abc *5)/10 + 10) * -1
* xyz should have the value -60
OUTPUT: "[[]" & xyz & "[]]"
STOP
[-60]
VAR a=100, b=200, c=300 AS INT
VAR d="FALSE" AS BOOL
START
d = (a < b AND c <>200)
OUTPUT: d
STOP
TRUE
VAR a=100, b=200, c=300 AS INT
VAR d="FALSE", e="TRUE" AS BOOL
START
d = (a < b AND c <>200)
e = NOT d
IF (d)
START
OUTPUT: "IF BLOCK#"
STOP
ELSE
START
OUTPUT: "ELSE BLOCK#"
STOP
IF (c <> 300)
START
OUTPUT: "IF BLOCK#"
STOP
ELSE
START
OUTPUT: "ELSE BLOCK#"
STOP
STOP
IF BLOCK
ELSE BLOCK
VAR i=10 AS INT
START
WHILE (i >= 0)
START
OUTPUT: i & "#"
IF (i == 0)
START
OUTPUT: "End of loop!"
STOP
i = i - 1
STOP
STOP
10
9
8
7
6
5
4
3
2
1
0
End of loop!