FISH-Language

所属分类:内容生成
开发工具:Java
文件大小:5742KB
下载次数:0
上传日期:2018-05-10 21:42:21
上 传 者sh-1993
说明:  FISH编程语言是使用Antlr4和Java开发的,包括中间代码生成和运行...
(FISH Programming Language has been developed using Antlr4 and Java that includes intermediate code generation and runtime.)

文件列表:
data (0, 2018-05-11)
data\Test-Cases (0, 2018-05-11)
data\Test-Cases\Intermediate-code (0, 2018-05-11)
data\Test-Cases\Intermediate-code\binaryOperation.fish.ic (210, 2018-05-11)
data\Test-Cases\Intermediate-code\dynamicTyping.fish.ic (254, 2018-05-11)
data\Test-Cases\Intermediate-code\evenOdd.fish.ic (288, 2018-05-11)
data\Test-Cases\Intermediate-code\factorial.fish.ic (392, 2018-05-11)
data\Test-Cases\Intermediate-code\fibonacci.fish.ic (576, 2018-05-11)
data\Test-Cases\Intermediate-code\firstFish.fish.ic (339, 2018-05-11)
data\Test-Cases\Intermediate-code\palindrome.fish.ic (707, 2018-05-11)
data\Test-Cases\Intermediate-code\palindromeFunctions.fish.ic (906, 2018-05-11)
data\Test-Cases\Intermediate-code\primeList.fish.ic (899, 2018-05-11)
data\Test-Cases\Intermediate-code\sampleFunc.fish.ic (967, 2018-05-11)
data\Test-Cases\Intermediate-code\strongTyping.fish.ic (140, 2018-05-11)
data\Test-Cases\Intermediate-code\wondersOfWrite.fish.ic (571, 2018-05-11)
data\Test-Cases\Test-Programs (0, 2018-05-11)
data\Test-Cases\Test-Programs\binaryOperation.fish (121, 2018-05-11)
data\Test-Cases\Test-Programs\dynamicTyping.fish (95, 2018-05-11)
data\Test-Cases\Test-Programs\evenOdd.fish (146, 2018-05-11)
data\Test-Cases\Test-Programs\factorial.fish (157, 2018-05-11)
data\Test-Cases\Test-Programs\fibonacci.fish (231, 2018-05-11)
data\Test-Cases\Test-Programs\firstFish.fish (89, 2018-05-11)
data\Test-Cases\Test-Programs\palindrome.fish (313, 2018-05-11)
data\Test-Cases\Test-Programs\palindromeFunctions.fish (394, 2018-05-11)
data\Test-Cases\Test-Programs\primeList.fish (373, 2018-05-11)
data\Test-Cases\Test-Programs\sampleFunc.fish (273, 2018-05-11)
data\Test-Cases\Test-Programs\strongTyping.fish (47, 2018-05-11)
data\Test-Cases\Test-Programs\wondersOfWrite.fish (220, 2018-05-11)
doc (0, 2018-05-11)
doc\SER502-Team16.pdf (399490, 2018-05-11)
doc\SER502-Team16.pptx (874552, 2018-05-11)
doc\contribution.txt (4520, 2018-05-11)
doc\design (0, 2018-05-11)
doc\design\Compiler-Design.jpg (136756, 2018-05-11)
doc\design\FISH.jpg (24428, 2018-05-11)
... ...

FISH LANGUAGE

SER 502 - TEAM 16

**Team:**
[Naga Ravi Teja Thoram](https://github.com/ravitejathoram) - nthoram@asu.edu
[Tarun Kolla](https://github.com/tarunkolla) - tkolla@asu.edu
[Koushik Kotamraju](https://github.com/koushik1610) - kkotamra@asu.edu
[Siva Pranav Mandadi](https://github.com/mspranav) - smandad1@asu.edu
**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 .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:**
**For Windows:** -Execute using the given .bat commands to run the .fish file. To Compile: fishCompile .fish if in same folder fishCompile "absolute path" \.fish for different folder Output: .fish.ic To generate output: fish .fish.ic if in same folder fish "absolute path" \.fish.ic for different folder output: Generates the program output on to the command prompt **For OSX:** Navigate to the install folder or use absolute path and then To Compile: java -jar compile.jar .fish Output: .fish.ic To generate output: java -jar runtime.jar .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)
  1. Statements
  2. Assignment

    Fish language supports assignment statements and can be written as: ``` $f f = 1 ```

    Declarative

    Data types should be declared with a $ sign as: ``` $a $b ```

    Write

    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

    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 ```

  3. Data Types
  4. Int

    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

    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.

    Boolean

    Fish supports boolean types and can be initialized as: ``` $f f = true $i i = false ```

  5. Operation
  6. Arithmetic

    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 ```

    Relational

    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

    Logical operators AND '&&' , OR '||' are supported by fish and their syntax is as follows: ``` $f f=1 if(f&&1): write "It works" endif ```

  7. Constructs
  8. Conditional

    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 ```

    Iterative

    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 ```

  9. Functions
  10. Function Block

    Fish language supports functions that start with fun(), ends with endfun and should have a return as: ``` fun NAME($f): endfun ```

    Function call

    Functions in Fish supports function calls as that also writes return values: ``` $f $i f = NAME() f = i + NAME() write NAME() ```

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.
  • The simple principle we followed in order to achieve dynamic typing is taking care of context/types whenever assignment statement triggers.
  • The priority FISH follows to choose type based on context whenever heterogeneous types occurs is
    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*)
  • This program proves that FISH dont allow assignment of undeclared variable to another variable or use of undeclared variable any where in the program thereby proving the quality of STRONG TYPING.
  • The restriction in this strong typing occurs only at "checking no.of arguments at functioncall == no.of parameters at function definition". We have not checked this during runtime.

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

  • write can hold a function call (prints return value)
  • write can evaluate expressions (arithmetic operations,logical and relational operations)
  • (illustrated in wondersOFWrite.fish program and sampleFunc.fish )

5. Arguments

  • 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.

7. Restriction

  • 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.


Other Resources


* [Compiler Design](doc/design/Compiler-Design.jpg) * [FISH Logo](doc/design/FISH.jpg) * [FISH Language Grammar](doc/design/grammar/FishLanguage.g4) * [Sample FISH programs](data/Test-Cases/Test-Programs) * [Watch the 15:00 minutes video to know more](https://youtu.be/XoU5I9I3MAk)

近期下载者

相关文件


收藏者