SER 502 - TEAM 16
System Execution environment: Windows.
Tools Used: Java SDK 1.8, Eclipse, ANTLR4.
Instructions to install Fish Programming Language:
-Download the install folder present in the repository -The folder consists of .jar file for compiler and runtime. -The 2 .bat files are used to execute the compiler and runtime
Instructions to build and execute the program:
-Write the Input program snippet with the file name <FileName>.fish within the same folder of the .jar files if not give the absolute path to the program file.
Command to Execute the compiler and the runtime:
-Execute using the given .bat commands to run the .fish file.
fishCompile <FileName>.fish if in same folder fishCompile "absolute path" \<FileName>.fish for different folder Output: <FileName>.fish.ic
To generate output:
fish <FileName>.fish.ic if in same folder fish "absolute path" \<FileName>.fish.ic for different folder output: Generates the program output on to the command prompt
Navigate to the install folder or use absolute path and then
java -jar compile.jar <FileName>.fish Output: <FileName>.fish.ic
To generate output:
java -jar runtime.jar <FileName>.fish.ic Output: Generates the program output on to the command prompt
FISH language programming guidelines:
FISH is a simple programming language that starts and ends with a statement as:
startFISH write "Hello FISH" endFISH
It consists of the following: (Click to expand)
- Data Types
Fish language supports assignment statements and can be written as:
$f f = 1
Data types should be declared with a $ sign as:
Write is used to display a prompt such as:
$f f=27 write f
Write can also be used to display portion of a line:
write "Keep fishing"
Read is used for obtaining input of the primitive types such as Int and can be writen as:
$f write "give the value of f:" read f
It is recommended that Integer values are to be declared at the start of the program and can be initialized as follows:
$f f = 0
We can also have multiple initializations on the same line
$f $i f = 0 i = -1
Real numbers such as 1.0, 2.2, 3.67 etc., can be initialized as follows:
$f f = 2.7
As Fish language supports dynamic typing we do not have to specify the type.
Fish supports boolean types and can be initialized as:
$f f = true $i i = false
Fish programming language supports arithmetic operations such as addition '+', subtraction '-', multiplication '*', division '/', modulus '%'.
$f $i $operate i = 2 read f operate = (f % 3) - i write operate
Fish supports relational operators such as equalto '==', notequalto '!=', lessthan '<', graterthan '>', lessthaorequalto '<=', greaterthanorequlato'>='.
$f $i f = 2 read i if(i >= 2): write "i is greater than or equal to 2" endif
Logical operators AND '&&' , OR '||' are supported by fish and their syntax is as follows:
$f f=1 if(f&&1): write "It works" endif
If is a control flow statement that starts as if(): and ends with endif as:
$f read f if(f == 0): write "f is zero" endif
If can also be followed with an else statement:
$f $i $s $h f=0 i=1 read h if( h == 0): s = f + i write s else: s = f * i write s endif
The loop statement continually executes a block while a particular condition is true. Its syntax can be expressed as:
$f f=4 loop(f > 1): write f f = f - 1 endloop
Fish language supports functions that start with fun(), ends with endfun and should have a return as:
fun NAME($f): <statements> <return Statement> endfun
Functions in Fish supports function calls as that also writes return values:
$f $i f = NAME(<argument>) f = i + NAME(<argument>) write NAME(<argument>)
Scope & Restrictions
This sections talks about what FISH programming language can do. The list below has a detailed explanation of the same.
1. Dynamic Typing
- Our programming language dynamically decides the data types of variables just like Java Script/Python.
- We support three data types and user only need to declare variable, need not bother about type of variable.
- Whenever a variable is declared we are giving default value as "0" and setting default type as "NONE".
- Based on the context, we typecast data or shows error message to perform operations among data types.
- Consider the example program dynamicTyping.fish o/p of that program is :
a: 1 type:NUMBER a: 3.0 type:REAL
The output illustrates the dynamic typing in our language because based on context the type of variable "a" is changing.
Scenario 1 (in case of Arithmetic and Relational Operations):
REAL > NUMBER > NONE (example "dynamicTyping.fish" also illustrates this concept at the statement a = a + b
where b = 2.0 after executing this statement a becomes REAL prior to that it is NUMBER)
Scenario 2 (in case of Logical operations) :
BOOLEAN (logical operations such as AND/OR works only if operands are BOOLEAN)
2. Strong Typing
- Identifier and assignment statement are places where we can loose our control over program. Whenever we are assigning a identifier to another identifier i.e a=b (b must hold a value prior to this assignment statement). Since Fish is a Strongly typed language it
checks scope of 'b' in the environment before assignment.
Consider the program StrongTyping.fish
o/p of that program is :
variable not declared : d variable not declared : b
(PRINTING ERROR MESSAGES AS OUR OWN EXCEPTIONS ARE NOT DEFINED)
3. Meta Language Inspiration
- Inspired from ML, Fish also prints type of "variable" on console when used along with write "statement" (i.e write a => display value and type of 'a' on console).
Printing type of variable will also exhibits our "DYNAMIC TYPING".
4. Wonders of FISH write Statement
- FISH Functions can take expressions as "arguments" and Fish Functions can be part of expressions. This scenario is illustrated in the sampleFunc.fish program.
6. Variable Declaration
- Fish allows to declare variable at any part of program and from that point of declaration that variable holds "Global Scope". This is good thing but this led to some restriction for us i.e. Use of Same variables in the Function Block and Main Block can corrupt the program. This problem is due to use of global environment hash table instead we have to create environment states block specifically to restrict scope.
- FISH functions demand at least one argument. Our grammar and runtime is in accordance with this feature.
- FISH functions do not support "Recursion".
The reason for this is because we havent created Dynamic Stack Frame to handle environment and runtime stack of each function. We handled everything in global stack.
- FISH functions expects definition of recent function call first.
Consider the example "sampleFunctions.fish" in this as "SUB" is latest function call the definition of the SUB must be found prior to "ADD"
The reason for this restriction is due to usage of stack during compile time while forming intermediate code to store the point of function call.
- Functions can take given expressions as arguments bu it is recommend to leave a space between the operand and operators. Consider the example of f+1, this recommended to be written as f + 1.