cui-unige/semantique

Homework #2

Opened this issue · 5 comments

Homework #2 has been available in README for some time. It must be done before 16th april 2018 08:00.

I made a mistake for the deadline, it is of course 17th april 2018 08:00.

The tests i am using for this homework:

    let test_expressions = [
         // Simple constant (correct):
        """
        let x = 1
        """,
        // Simple type (correct):
        """
        let x : Int = 1
        """,
        // Simple type/constant (correct):
        """
        let x : Int = 1
        """,
        // Simple type/constant (incorrect):
        """
        let x : Int = true
        """,
        // Expression (correct):
        """
        let x = 1 + 2 * 3 - 4
        """,
        // Expression (incorrect):
        """
        let x : Bool = 1 + 2 * 3 - 4
        """,
        // Propagation (correct):
        """
        let x = 1
        let y = x + 2
        """,
        // Propagation (incorrect):
        """
        let x : Bool = 1
        let y = x + 2
        """,
        // Mix (correct):
        """
        let x = 1
        let y : Int
        let z = x + y
        """,
        // Mix (incorrect):
        """
        let x = 1
        let y : String
        let z = x + y
        """,
        // Condition (correct):
        """
        let x = 2
        if x == 1 {
          let y = x
        } else {
          let y = "abcdef"
        }
        """,
        // Condition (incorrect):
        """
        let x = 2
        var y
        if x == 1 {
          y = x
        } else {
          y = "abcdef"
        }
        """,
        // Function declaration and call (correct):
        """
        fun f(_ a: Int) -> Int {
          return a
        }
        let y = f(2)
        """,
        // Function declaration and call (incorrect parameter):
        """
        fun f(_ a: String) -> Int {
          return a
        }
        let y = f(2)
        """,
        // Function declaration and call (incorrect result):
        """
        fun f(_ a: Int) -> String {
          return a
        }
        let y = f(2)
        """,
    ]


    func testHomework2() throws {
      do {
          for expression in test_expressions {
              print("Before: ")
              print("  == ", expression)
              let module = try parse(what: expression)
              var visitor = CheckTypesVisitor()
              try! visitor.visit(module)
              for (declaration, term) in visitor.variables {
                  print (declaration, term)
                  let result : Term = .var("answer")
                  let question = visitor.typeOf[term, result]
                  let answers = visitor.kb.ask(question)
                  print("  -> Question:", question)
                  for answer in answers {
                      print("  * ", answer[result] ?? "<unknown>")
                  }
              }
          }
      } catch let e {
          print(e)
          throw e
      }
    }

Grades have been pushed into your repositories, under branch homework-2. Please check them.

A lot of grades are 2, because you did not fill correctly the variables field of the visitor. For the students that got 2, please fix this problem (and only this problem) in the homework-2 branch and ask me to grade again your homework.

Hi,
I cannot find my grade for homework 2 and for homework 1, I don't understand because the compilation works on my computer

@dalexanderch please open an issue in your own repository, as your question is about your work/grade and not the homework in general. Also, have you looked at branches homework-1 and homework-2?