- This project is for education purposes.
- This interpreter written in c.
This interpreter can handle:
- Int and float variables
- Expressions
- If statements
- Label statement
- Functions
- While loops
- For loops
- Comments
Some Notes:
• Functions share the same stack of the program, so all the variables are global.
• Comments must be in in a separate line.
• You don't need to declare the variables type.
Declaring variables:
Variable name must start with underscore
_
or an alphabet characterA to Z
.
Variable name can consist of underscores or characters or digits.
Examples:
- name
- _name
- _name1
Expressions:
Operators:
- Not
!
- Power
**
- Multiplication
*
- division
/
- Mod
%
- Plus
+
- Minus
-
- Left shift
<<
- Right shift
>>
- Greater than
>
- Smaller than
<
- Greater than or equal
>=
- Smaller than or equal
<=
- Equal to
==
- Not equal to
!=
- Bit wise and
&
- Bit wise or
|
- XOR
^
- Logical AND
&&
- Logical OR
||
- Equal assign
=
- Multiply assign
*=
- Division assign
/=
- Mod assign
%=
- Plus assign
+=
- Minus assign
-=
- Left shift assign
<<=
- Right assign
>>=
- Bit wise and assign
&=
- Bit wise or assign
|=
- XOR assign
^=
Operators precedence:
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
---|---|---|---|---|---|---|---|---|---|---|
! | ||||||||||
** | ||||||||||
* | / | % | ||||||||
+ | - | |||||||||
<< | >> | |||||||||
< | <= | > | >= | |||||||
== | != | |||||||||
& | ||||||||||
^ | ||||||||||
| | ||||||||||
&& | ||||||||||
|| | ||||||||||
= | *= | /= | %= | += | -= | <<= | >>= | &= | |= | ^= |
Examples:
-
x *= - - - - - - 3 - + - + 4 * 4 + + + 2 ** 2
-
y = 2/6 + -3 - -2 + -4/-10 + 2*6 + (7 + -7)*-5/2/(3 - 5 + 4*4)
-
s = 3 & 4 || 3 ^ 2
-
m = !((s = 5) && 0 ) || 3 <= 2
If statements:
The if statement should start with the key word
if
then thecondition
then:
.
After that you can write the scope of the if statement.
Then you can close the if statement with the key wordendif
.
if #Condition# :
//scope
endif
Examples:
-
if 3 <= 2 :
//condition should be false
endif -
if 1 && (2 > 1) || 3 :
//condition should be true.
endif
Label statement:
The label statement should start with a valid variable name
labelName
then a colon:
.
If you want to go to the label statement all what you need is to use the key wordgoto
then write the label namelabelName
.
labelName:
//Some lines
goto labelName
Examples:
-
start:
//comment
goto start
-
x = 5
start:
if x < 15 :
x += 5
goto start
endif
Functions:
To declare a function you need to start with the key word
function
then the function namefunctionName
then the parameters(x , y)
and finally the colon:
.
Then you can write the scope of the function, and in the end of the function you need to close the function scope with the closing key wordendFunction
.When you want to call the function all what you need is to write the function name
functionName
then the parameters(1 , 2)
.
function #functionName# ( # parameters #) :
# The scope of the function #
endFunction
and to call the function:
#functionName# (# parameters #)
Examples:
-
function firstFunction (x , y) :
//comment
endFunctionfirstFunction (1, 2)
-
function secondFunction () :
//some lines
endFunctionsecondFunction()
While loops:
To declare a while loop you need to start with the
while
key word then thecondition
then the colon:
.
After that you can write the scope of the loop, then you need to close the loop with the key wordendLoop
.
while # Condition # :
#scope#
endLoop
Examples:
-
while 1 :
//comment
endLoop
-
x = 0
while x < 10 :
x += 1
endLoop
For loops:
To declare a for loop you need to start with the
for
key word then thecontrol variable
after that a semicolon;
thencondition
after that a semicolon again;
thenchanging variable value
and finally the colon:
.
After that you can write the scope of the loop, then when you want to close the loop you need to use the key wordendLoop
.
for #control variable# ; #condition# ; #changing variable value expression# :
# The scope of the loop #
endLoop
Examples:
-
x = 0
for x ; x < 10 ; x += 1 :
//comment
endLoop
-
for i = 100 ; i >= 0 ; i -= 1 :
//some lines
endLoop
Comments:
To declare a comment all what you need is to start the line with two forward slashes
//
then thecomment
.
// #comment#
Examples:
-
// This is the first comment
-
// This is the second comment
- The interpreter has a simple text editor.
- You can load a ready text file that you can edit, compile and save.
- You can start to write a new code that you can compile and save.
Some key words you need to know while you are writing a code:
- The key word
EDIT
this key word will give you the ability to edit a particular line in the code.
- The key word
REMOVE
this key word will give you the ability to delete a particular line in the code.
- The key word
ADD
this key word will give you the ability to add a new line in a particular index in the code.
- The key word
UNDO
this key word will give you the ability to undo recent changes.
- The key word
REDO
this key word will give you the ability to redo recent changes.
- The key word
RUN
you use this key word when you want to compile or save the code.