Skip to content

Latest commit

 

History

History
53 lines (43 loc) · 1.74 KB

README.md

File metadata and controls

53 lines (43 loc) · 1.74 KB

SwiftyInterpreter

Interpreter for Swift-like language Swifty.

Overview of the repository

I decied to write two versions of this language to ilustrate different types of variables binding - dynamic and static. Core features of the language are identical. Repository is divided into two branches:

  1. Dynamic binding
  2. Static binding

Both containing:

  1. Grammar file Swifty.cf with language grammar for BNF Converter (bnfc)
  2. Interpreter implementation files generated with bnfc, EvalSwifty.hs with evaluation functions, TypeChecker.hs with type checker code.
  3. Docs directory:
  4. Language description, grammar etc in Swifty.pdf (generated by bnfc)
  5. Swifty.tex generated with bnfc
  6. Examples directory:
  7. Good directory with examples of working code in Swifty
  8. Bad directory with examples of typical error (syntax, runtime, type)

Language description

Swifty is interpreted, strongly typed programming language. Types of the variables are inferred by interpreter. Variables are dynamically/statically binded. Syntax of the language is derived from Apple's programming language Swifty.

Data types

  1. Basic
  2. Integers (int)
  3. Boolean (bool)
  4. Complex
  5. Arrays
  6. Structures
  7. Tuples

Expressions

  1. Boolean expressions: ||, &&, ==, !=
  2. Arithmetic expressions: +,-,*,/ (integer division)
  3. Unary expressions: -, !

Declarations

  1. Block
  2. Functions and procedures
  3. Variables, arrays, structs

Statements

  1. Assignment
  2. if, if-else
  3. while loop, foreach
  4. return

Implementation

Code of the interpreter is written in Haskell. Parser and lexer were generated by BNF Converter. Evaluation functions are written in Continuation Passing Style, type checker is written with use of Monad State.