Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Quiz on Language Grammar and Types, Quizzes of Programming Languages

A series of quiz questions related to language grammar and types. The questions cover various aspects of expression evaluation, well-formedness, and type assignment. Students of computer science, particularly those studying programming languages or formal logic, may find this document useful for exam preparation or as a supplement to lecture notes.

Typology: Quizzes

Pre 2010

Uploaded on 08/30/2009

koofers-user-a65
koofers-user-a65 🇺🇸

10 documents

1 / 27

Toggle sidebar

Related documents


Partial preview of the text

Download Quiz on Language Grammar and Types and more Quizzes Programming Languages in PDF only on Docsity! Quiz • Question #1: What is the value of the following expression? {+ 1 2} • Wrong answer: 0 • Wrong answer: 42 • Answer: 3 1-4 Quiz • Question #2: What is the value of the following expression? {+ fun 17 8} • Wrong answer: error • Answer: Trick question! {+ fun 17 8} is not an expression 5-7 Quiz • Question #4: What is the value of the following expression? {{fun {} 1} 7} • Answer: 1 (according to some interpreters) • But no real language would accept {{fun {} 1} 7} • Let's agree to call {{fun {} 1} 7} an ill-formed expression because {fun {} 1} should be used with only zero arguments • Let's agree to never evaluate ill-formed expressions 12-15 Quiz • Question #5: What is the value of the following expression? {{fun {} 1} 7} • Answer: None - the expression is ill-formed 16-17 Quiz • Question #6: Is the following a well-formed expression? {+ {fun {} 1} 8} • Answer: Yes 18-19 Quiz • Question #9: Is the following a well-formed expression? {+ {{fun {x} x} 7} 5} • Answer: Depends on what we meant by inside in our most recent agreement Anywhere inside - No Immediately inside - Yes • Since our intrepreter produces 12, and since that result makes sense, let's agree on immediately inside 25-27 Quiz • Question #10: Is the following a well-formed expression? {+ {{fun {x} x} {fun {y} y}} 5} • Answer: Yes, but we don't want it to be! 28-29 Quiz • Question #11: Is it possible to define well-formed (as a decidable property) so that we reject all expressions that produce errors? • Answer: Yes: reject all expressions! 30-31 Types 1 : num true : bool {+ 1 2} num num num {+ 1 false} num bool no type 37-45 Type Rules <num> : num true : bool false : bool <MFAE>1 : num <MFAE>2 : num {+ <MFAE>1 <MFAE>2} : num 1 : num true : bool 1 : num 2 : num {+ 1 2} : num 1 : num false : bool {+ 1 false} : no type 46-49 Type Rules <num> : num true : bool false : bool <MFAE>1 : num <MFAE>2 : num {+ <MFAE>1 <MFAE>2} : num 1 : num 2 : num {+ 1 2} : num 3 : num {+ {+ 1 2} 3} : num 50 Types: Variables and Functions x : no type {fun {x : bool} x} bool (bool → bool) {if x 1 2}{fun {x : bool} } bool num num num (bool → num) 70-79 Variable and Function Type Rules [ ... <id>←τ ... ] <id> : τ Γ[ <id>←τ1 ] e : τ2 Γ {fun {<id> : τ1} e} : (τ1 → τ2) Abbreviations: τ = <type> e = <MFAE> Γ = <env> 80 Variable and Function Type Rules [ ... <id>←τ ... ] <id> : τ Γ[ <id>←τ1 ] e : τ2 Γ {fun {<id> : τ1} e} : (τ1 → τ2) ∅ x : no type [ x←bool ] x : bool ∅ {fun {x : bool} x} : (bool → bool) [ x←bool ] x : bool [ x←bool ] 1 : num [ x←bool ] 2 : num [ x←bool ] {if x 1 2} : num ∅ {fun {x : bool} {if x 1 2}} : (bool → num) 81-83 Function Call Type Rule Γ e1 : (τ2 → τ3) Γ e2 : τ2 Γ {e1 e2} : τ3 ∅ {fun {x : bool} {if x 1 2}} : (bool → num) ∅ true : bool ∅ {{fun {x : bool} {if x 1 2}} true} : num ∅ {fun {x : bool} {if x 1 2}} : (bool → num) ∅ 5 : num ∅ {{fun {x : bool} {if x 1 2}} 5} : no type ∅ 7 : num ∅ 5 : num ∅ {7 5} : no type 97-100 Types: Multiple Arguments {+ x y}{fun {x : num y : num} } num num num (num num → num) {{fun {x : num y : num} {+ x y}} 5 6} (num num → num) num num num {{fun {x : num y : num} {+ x y}} 5} (num num → num) num no type 101-114 Revised Function and Call Rules Γ[ <id>1←τ1 ... <id>n←τn ] e : τ0 Γ {fun {<id>1 : τ1 ... <id>n : τn} e} : (τ1 ... τn → τ0) Γ e0 : (τ1 ... τn → τ0) Γ e1 : τ1 ... Γ en : τn Γ {e0 e1 ... en} : τ0 115
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved