Камила Хамидуллина
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Stage 4. Final Design, Imlementation & Presentation ## Project title Kassym-Jomart ## Project team members and their roles in the project. * Dias Usenov: - [x] finish compiler - [x] type checker * Makshe Seytkaliev: - [x] demo application - [x] documentation * Kamila Khamidullina: - [x] language design - [x] testing ## General description of the target programming language, its core ideas, and list of features. #### Statically-typed functional programming language like Racket. * Predefined functions: let, set, define, cond. * Iterations: for, for\list * Records: record, record-keywords, record-values, record-field * Arrays: array, array-rem, array-get, array-add, array-set * Arithmetic functions: plus, minus, mul, div. * List operations: head, tail, cons. * Comparison functions: equal, nonequal, less, lesseq, greater, greatereq. * Predicates: isint, isreal, isbool, isstring, islist. * Logical operators: and, or, xor, not #### Features: * Base types (mandatory) * User-defined terms and types (mandatory) * Standard libraries: arithmetic, logic, list (mandatory) * First-class functions (lambda) (mandatory) * Nested functions (mandatory) * Simple Constraint-Based Type Inference (mandatory) * Functions with multiple arguments (1) * Sequencing (1) * Exceptions (3) * Tuples (3) * Built-in lists (4) * Records (3) * Wildcard bindings (1) * General recursion (2) ###### total: `18 points` ## Language design. * Program is a set of elements. Elements are either atoms, literals or declarations. * Literals are just values that are written explicitly. There are integer, real, boolean, string, list, array or record literals. * Atoms can be considered as variables. * Declaration elements are functions that declare new variables or methods. * List is a sequence of elements separated by whitespaces and enclosed by parentheses. List can contain several types of literals. So the list in the program is heterogeneous. And since list elements cant be changed it can be considered as tuples. List can build with two ways: * List build functions * With ‘ symbol, example: ‘(1 2 3 4) * Array is a sequence of elements as list, but it is homogeneous and its elements can be changed. * Record is a collection of name-value mappings (like a dictionary or hash-tables). * The program execution starts from its very first element. Each element is evaluated in accordance with its semantics. If the current element is an atom, the program(interpreter) simply returns its value. ### Types The language has * integer * real * boolean * string * list * array * record types. Each variable has one of this types, and each function should return one of this types or nothing. ### Predefined functions * (let Atom:Type Element) - declaration function that creates Atoms. * (set Atom Element) - set a new value to an already existing atom. ``` > (let v:Integer 5) > v 5 > (set v 10) > v 10 ``` * (define Name (Atom:Type, Atom:Type)) -> Type {Body} - define a new function. ``` > (define double (a:Integer)) { > (return (times a a)) > } > (double 5) 25 ``` * (cond [Boolean Any]*) -> Any - the form is the construct for conditional evaluation. It can contain several arguments, each argument has two elements. First element is the condition, the second is the returned element if the condition is true. Program will go through arguments starting from first, If one of the conditions is true, then the program returns its second element, and ends the function. ``` > (let a:Integer 5) > (let b:Integer 10) > (cond [(less a b) (b)] [else (a)]) 10 ``` ### Iteration functions * (for Atom {List\|Integer}) {Body} - the form supports iteration over the sequence. First element is the iterator name, second is either the list or integer. If second is the list, it goes through the list, if integer it goes through all integers starting from 0 to give integer. Element is a body of iteration, at each step it will return some element. ``` > (for i '(1 2 3)) { > i > } 1 2 3 > (for i 4) { > i > } 0 1 2 3 ``` * (for/list (Atom {List\|Integer}) Any) -> List - same as previous but instead of just returning elements, it will construct the list with these elements. ``` > (for/list (i '(1 2 3)) (plus i i)) '(2 4 6) ``` ### Arithmetic functions * ({plus\|minus\|mul\|div} {Integer\|Real} {Integer\|Real}) -> {Integer\|Real} - simple arithmetic functions, have as an argument two elements, both of them are either integer or real, if one the elements is real, the resulting value also be real, in other way it will be integer. ``` > (plus 5 6) 11 > (minus 10 2) 8 > (plus 2.0 3.1) 5.1 > (let a:Real 5.5) > (let b:Real 3.5) > (plus a b) 9 > (mul 3 3) 9 > (div 10 2) 5 > (div 10 3) 3 > (div 10.0 3.0) 3.333 ``` ### List operations * (list Any*) -> List - Function can have various types, and it will build and return a list with elements in a given order. * (head List) -> Any - Element should be a list, the function will return the first element of the given list. * (tail List) -> Any - Element should be a list, the function will return the last element of a given list. * (rest List) -> List - Element should be a list, the function will return the list without the first Element. * (empty List) -> Boolean - Element should be a list, the function will return true if list is empty, if not false. * (append List List) -> List - The function will add a second list to the tail of the first list. ``` > (list “a” “b” “c”) > ‘(“a” “b” “c”) > (head '(1 2 3 4 5)) 1 > (tail '('abac 5 10 true 1.0)) 1.0 > (cons 1 2) '(1 2) > (append '(1 2 3 4) '(5 6 7 8)) '(1 2 3 4 5 6 7 8) ``` ### Array operators * (array Any*) -> Array - Array build function can have just one type, and it will build and return an array with elements in a given order. * (array-rem Array Integer) -> Array - Array function that removes element in a given array and returns it. * (array-get Array Integer) -> Any - Array function that returns element in a given index. * (array-add Array Integer Any) -> Array - Array function that inserts element in position. * (array-set Array Integer Any) -> Array - Array function that changes value of element in some position to another value. ``` > (array 1 2 3 4 5) '[1 2 3 4 5] > (array-rem '[1 2 3 4 5] 2) '[1 2 4 5] > (array-get '[1 2 3 4 5] 4) 5 > (array-add '["a" "b" "d"] 2 "c") '["a" "b" "c" "d"] > (array-set '[1 2 3 4 5] 0 10) '[10 2 3 4 5] ``` ### Record operators * (record (Keyword Any)*) -> Record - Record build function, can contain several (name-value) fields, each field is a set of keywords and its value. * (record-keywords Record) -> List - Return a list of keys with a given record. * (record-values Record) -> List - Return list of values with a given record. * (record-field Record Keyword) -> Any - Return value of key in a record. ``` > (let rec (record (#name "Dias") (#age 20) (#city Innopolis))) > rec (record #age:20 #city:Innopolis #name:"Dias") > (record-keywords rec) ‘(#age #city #name) > (record-values rec) '(20 Innopolis "Dias") > (record-field rec #name) "Dias" ``` ### Comparison functions * ({equal \| nonequal \| less \| lesseq \| greater \| greatereq} Element Element) - simple comparison functions, that compares two elements. Elements should be either real or integer. And the resulting value will be true or false. ``` > (less 5 10) true > (equal 'abac' 'abac') true > (equal 5 5.0) false ``` ### Predicates * ({isint\|isreal\|isbool\|islist\|isstring} Any) -> Boolean - the functions return a boolean value: true, if the argument is of type that the function expects, and false otherwise. ``` > (isint 5) true > (isbool 'true') false ``` ### Logical operators * ({or\|and\|xor} Boolean Boolean) -> Boolean and (not Boolean) -> Boolean - the functions perform usual logical operators on evaluated arguments and return a boolean value. Elements should be boolean types. ``` > (and true true) true > (and (xor true false) (not (or true true))) false ``` ### Input * (read-line Type) -> Type - user input function, try to read line with given Type, if it can not throw an exception. ``` > (let a (read-line Integer)) # 100 > a 100 ``` ## A link to the source code of prototype. The source code can be found [here](https://github.com/DiazzzU/AAC) ## General description of the implementation * Building the project - to build the project run the *main.cpp* file in the main folder * Using the prototype - to use the prototype paste your code into *sourcecode.txt* file in the main folder and run the *main.cpp* file * Valid and invalid programs Coorect tests checking the features of the language: ``` (define correctTests ()) { (cond[(checkLetSet) "Let ans set are correct"] [else "Let ans set are incorrect"]) (cond[(checkCond) "Condition is correct"] [else "Condition is incorrect"]) (cond[(checkArithmetic) "Arithmetic is correct"] [else "Arithmetic is incorrect"]) (cond[(checkList) "List is correct"] [else "List is incorrect"]) (cond[(checkFor) "For is correct"] [else "For is incorrect"]) (cond[(checkArray) "Array is correct"] [else "Array is incorrect"]) (cond[(checkRecord) "Record is correct"] [else "Record is incorrect"]) (cond[(checkComp) "Comparison is correct"] [else "Comparison is incorrect"]) (cond[(checkPred) "Predicate is correct"] [else "Predicate is incorrect"]) (cond[(checkLogic) "Logic is correct"] [else "Logic is incorrect"]) } (define checkLetSet ()) { (let v:Integer 6) (let a:Boolean (equal v 6)) (set v 10) (let b:Boolean (equal v 10)) (return (and a b)) } (define checkCond ()) { (return (cond [true true] [else false])) } (define checkFor ()) { (let a:Integer 0) (for i '(1 2 3)) { (set a (plus a i)) } (let f:Boolean (equal a 6)) (set a 0) (let l:List (for/list (i '(1 2 3)) (plus i i))) (let t:Boolean (equal (head l) 2)) (return (and f t)) } (define checkArithmetic ()) { (let a:Boolean (equal (plus 3 5) 8)) (let b:Boolean (equal (minus 8 10) -2)) (let c:Boolean (equal (mul 3 5) 15)) (let d:Boolean (equal (div 9 3) 3.0)) (let e:Boolean (equal (plus 3.1 5.6) 8.7)) (let f:Boolean (equal (minus 3.8 2.3) 1.5)) (let g:Boolean (equal (mul 1.2 8.2) 9.84)) (return (and a (and b (and c (and d (and e (and f g))))))) } (define checkList ()) { (let l:List (list "a" 1 2 3)) (let a:Boolean (equal (head l) "a")) (let b:Boolean (equal (tail l) 3)) (let c:Boolean (equal (plus (head (rest l)) (tail (rest l))) 4)) (let d:Boolean (not (empty l))) (let n:List (append '(1 2 3) '(4 5 6))) (let e:Boolean (equal (plus (head n) (tail n)) 7)) (return (and a (and b (and c (and d e))))) } (define checkArray ()) { (let ar:Array (array 1 2 3 4 5)) (let a:Boolean (equal (array-get ar 2) 3)) (set ar (array-rem ar 2)) (let b:Boolean (equal (array-get ar 2) 4)) (set ar (array-add ar 2 9)) (let c:Boolean (equal (array-get ar 2) 9)) (set ar (array-set ar 2 0)) (let d:Boolean (equal (array-get ar 2) 0)) (return (and a (and b (and c d)))) } (define checkRecord()) { (let rec:Record (record (#name "Dias") (#age "25") (#city "Innopolis"))) (let keys:List (record-keywords rec)) (let val:List (record-values rec)) (let a:Boolean (equal (head val) "25")) (let b:Boolean (equal (tail val) "Dias")) (let one:String (record-field rec (head keys))) (let c:Boolean (equal one "25")) (return (and a (and b c))) } (define checkComp()) { (let a:Boolean (equal 1 1)) (let b:Boolean (nonequal 1 1)) (let c:Boolean (less 5 1)) (let d:Boolean (lesseq 3 7)) (let e:Boolean (greater 5 2)) (let f:Boolean (greatereq 4 4)) (return (and a (and (not b) (and (not c) (and d (and e f)))))) } (define checkPred ()) { (let a:Boolean (isint 5.5)) (let b:Boolean (isint 4)) (let c:Boolean (isreal 5.0)) (let d:Boolean (isbool true)) (let e:Boolean (islist (array 3 4 5))) (let f:Boolean (isstring "true")) (return (and (not a) (and b (and c (and d (and (not e) f)))))) } (define checkLogic ()) { (let a:Boolean (or true false)) (let b:Boolean (or true true)) (let c:Boolean (or false false)) (let d:Boolean (and true false)) (let e:Boolean (and true true)) (let f:Boolean (and false false)) (let g:Boolean (not true)) (let h:Boolean (not false)) (let i:Boolean (or false true)) (let j:Boolean (and false true)) (return (and a (and b (and (not c) (and (not d) (and e (and (not f) (and (not g) (and h (and i (not j))))))))))) } (correctTests) ``` Incorrect tests * Incorrect type assignmnent ``` (let v:Integer "start") ``` * Wrong number of arguments ``` (mul 1 2 3) ``` * Incorrect argument: trying to get an element from array that does not exist ``` (let ar:Array (array 1 2 3 4 5)) (array-get ar 10) ``` * Incorrect type of passed argument ``` (plus 5 "add") ``` * Incorrect number of paranthesis ``` (let a:Integer (plus 5 3))) ``` ## Sketch of a demo program It is a guess a number game. We have an array of numbers from 0 to 99, user enters some number, we convert it to another number and it will be an index of the hidden number from the array. Then the user has 5 attempts to guess the number, the program will give hints if the hidden number is greater or less than the user guess. ``` define create (field:Array)){ (for i 100){ (set field (array-add field 0 i)) } (return field) } (define guess-number ()){ (let field:Array (array)) (set field (create field)) "Welcome to the game, enter a number from 0 to 10" (let num:Integer (read-line Integer)) (set num (minus (mul (plus num 9) 5) (plus num 8))) (let number:Integer (array-get field num)) "Ok, now you have 5 attempts to guess the number" (let win:Integer 0) (let check:Integer 0) (for i 5){ (cond [(equal win check) (set win (play number))]) } (cond [(equal win check) "You lose"] [else "You win"]) } (define play(number:Integer)){ "Your guess" (let guessed:Integer 0) (let user-number:Integer (read-line Integer)) (cond [(equal user-number number) (set guessed 1)]) (cond [(less user-number number) "Greater"]) (cond [(greater user-number number) "Less"]) (return guessed) } (guess-number) ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully