CS 320—Week 8 Homewor


CS 320—Week 8 Homework—Due W 3/27 11:59pm
Write your answers to the problems in the space indicated. Scan your solution and submit
to Gradescope as a PDF file. You will receive an email about the Gradescope account.
You may do this from your phone using free scanning apps, or with a desktop scanner.
Do NOT edit this file and move things around, the format must remain the same.
Problem One (Monad Do Expressions)
This problem will exercise your understanding of the “assembly language” of Haskell’s do
expression syntax. “Translation” in this exercise refers to converting between the forms
(i), (ii) and (iii) shown on the last page. Use bound variables x, y, and z (as necessary).
(A) Show what phase (i) of the translation for example ex9’ in
MonadLectureCode2.hs would look like (this is in the Maybe Monad).
(B) Show what phases (i) and (ii) of the translation for example ex14 in
MonadLectureCode2.hs would look like (this is in the Maybe Monad).
(C) Show what phases (i) and (ii) of the translation for example ex4 in
MonadLectureCode3.hs would look like (this is in the Checked Monad).
Name: BU ID (no dashes):
S -> E
E -> E + T | T
T -> T * F | F
F -> P ^ F | P
P -> - P
P -> 1 | 2 | 3
Problem Two (Derivations and Parse Trees)
This problem concerns context-free grammars and the relationship between
parse trees and derivations, using the grammar shown at right.
(A) Give a left-most derivation of the string
3 * 2 + - 3 ^ 1 .
(B) Give a right-most derivation of the string
3 * 2 + - 3 ^ 1 .
(D) Suppose we consider the parse tree you created in part
(C). If you walk around the tree in preorder, and each time
you touch a non-terminal, you add a derivation step to a
derivation, what kind of derivation would result?
(E) Considering the same process as in (D), what kind of traversal of a tree would
correspond to a right-most derivation (see at the link on traversals posted with lecture 2)?
(F) Give a short, informal proof of the following statement: If a grammar is not
ambiguous, then for any string w in the language, every derivation of w has the same
length (same number of derivation steps). Hint: think about the relationship between
derivations and parse trees.
In (A) and
(B) you do
not need to
give the
number of
the rule, nor
underline
the nonterminal

being
rewritten at
each step.
See the YT
video for
hints on
how to do
(D) and (E).
(C) Give a parse tree for the string
3 1 + - 2 .
Problem Three (Context-Free Grammars and Languages)
This problem will have you write context-free grammars and also think about how to
characterize context-free languages.
For parts (A) and (B), give an intuitive description of the language generated by the given
context-free grammars, where T = { a, b }.
(A) S -> a A | b A -> a S | b A | ?
(B) S -> a S b S | b S a S | ?
For parts (C) and (D), give a context-free grammar for the language specified.
(C) The language of matching delimiters over the alphabet:
{ } [ ] ( )
The following are in the language: (()) ({}) {()}{}
and the following are not: ({)} {{{}}) ?

(D) The language { an bm an | n ≥ 0 and m>1}, i.e., strings aaa..abbb…baaa..a with at least
one b, and starting and ending with substrings of a’s of the same length.
The following are in the language: b abbbba aaabbaaa
and the following are not: aaba aaaa (i) =>(ii) =>(iii) =>
This page for reference ONLY, please do not scan and submit this page!

因為專業,所以值得信賴。如有需要,請加QQ99515681 或郵箱:99515681@qq.com?

微信:codinghelp

轉載于:https://www.cnblogs.com/helpyourjava/p/10595459.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/248283.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/248283.shtml
英文地址,請注明出處:http://en.pswp.cn/news/248283.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

javascript隨堂練習(分支,循環語句)

var flag true;//while語句執行:while(flag){//獲取用戶輸入選擇信息號碼:(字符串中的 \n 為換行的效果) var num prompt(你好,我是小娜\n請輸入編號或者關鍵詞選擇功能,輸入Q(q)退出聊天\n1.計算\n2.時間\n3.笑話) // 利用swit…

vue組件間函數調用

vue父子組件間函數調用 <Child ref"myChild"></Child> // 父組件 // 引入子組件 import Child from ./Child export default {// 注冊子組件components: {Child},created () {// 調用子組件中的childMethod&#xff0c;并且傳遞參數data&#xff0c;需要…

Cocoapods pod update執行失敗報錯CocoaPods was not able to update the `master` repo.2019的解決...

很久沒動pod&#xff0c;最近更新發現&#xff1a; CocoaPods報CocoaPods was not able to update the master repo. If this is an unexpected issue and persists you can inspect it running pod repo update --verbose錯誤。 使用命令pod repo update --verbose依然 不行&a…

javaScrip第五天(1)

06JavaScript基礎 核心知識點 函數 2. 函數中的參數 2. 函數中的返回值 今日學習目標 能夠完成函數相關案例 2. 能夠理解函數中的參數 2. 能夠理解函數中的返回值 函數 為什么要學函數&#xff1f; 1.求 1到100之間的數字之和什么是函數&#xff1f; 函數的概念 函數&…

偽靜態回發

&#xff08;1&#xff09;自定義一個Actionlessform類&#xff0c;在aspx中不再使用系統提供的form 標記 創建此類并對其進行編譯之后&#xff0c;要在 ASP.NET Web 應用程序中使用它&#xff0c;應首先將其添加到 Web 應用程序的 References 文件夾中。然后&#xff0c;要 使…

Supercomputer 解題報告

Supercomputer 設\(f_i\)為前\(i\)個時間內必須的完成的任務個數&#xff0c;那么答案就是\[ \max_{i}\lceil\frac{f_i}{i}\rceil \] 現在要支持區間加和全局\(\max\) 考慮分塊&#xff0c;對每個塊維護一個\(tag\)表示加標記 塊內的\(\max\)則為\[ \max_i \frac{1}{i}\times t…

OCS (錯誤代碼: 0-1-492)

http://hi.baidu.com/windowserver/blog/item/dcd6b851151d062d43a75b72.html 轉載于:https://www.cnblogs.com/hubj/archive/2010/06/12/1757279.html

javaScript第五天(2)

javaScript基礎 01.知識點-函數【重點】 學習函數的目的 就是為將重復的功能代碼包裝成一個工具(盒子), 方便程序員重復調用學習函數的路徑 定義函數調用函數為了讓函數的功能更加強大, 學習函數的 參數函數的返回值 函數的使用 函數的定義及調用 函數的定義 通過 function關…

How to ignore files and directories in subversion?

Step 1 Copy the files and directories to other place. Step 2 Delete the files and directories. Step 3 Commit. Step 4 Paste the files and directories from backup place. Step 5 Commit.轉載于:https://www.cnblogs.com/mouseleo/p/10605322.html

arguments使用

只有函數才有argumentsfunction fn(){console.log(arguments);console.log(arguments.length);console.log(arguments[2]);//我們可以按照數組的方式遍歷argumentsfor (let i 0; i < arguments.length; i) {console.log(arguments[i]);}}fn(1,2,3);偽數組 并不是真正意義上…

2.0 es6中forEach以及數組操作

前言&#xff1a; 小白的js之路...... 1. 遍歷數組/集合 forEach usernameArray []; //遍歷 users.forEach((user, index) > {let username user.name;//取出用戶名添加到數組usernameArray[index] username; }) 2. 數組過濾filter()和查找find() let arr s.filter( x &…

輸出GPLT

L1-023 輸出GPLT &#xff08;20 分)給定一個長度不超過10000的、僅由英文字母構成的字符串。請將字符重新調整順序&#xff0c;按GPLTGPLT....這樣的順序輸出&#xff0c;并忽略其它字符。當然&#xff0c;四種字符&#xff08;不區分大小寫&#xff09;的個數不一定是一樣多的…

javaScript第六天(1)

JavaScript基礎 核心知識點 對象 4種創建對象的方式操作對象&#xff08;取值&#xff0c;賦值&#xff09; 今日學習目標 能夠使用對象方式保存數據能夠理解自定義構造函數如何創建對象能夠獲取對象中的值及給對象賦值 對象 思考&#xff1a; 如何通過js函數將人的信息輸…

Reversing-x64Elf-100

一道很簡單的小題 作為python小白這道題主要是學習了一點python知識...... 可以看出來 sub_4006FD 這個函數是用來判斷輸入密碼是否正確的 我們看一下它的偽代碼&#xff1a; signed __int64 __fastcall sub_4006FD(__int64 a1) {signed int i; // [rsp14h] [rbp-24h]const ch…

javaScript第六天(2)

07-javaScript基礎 ? 函數其他部分 arguments [掌握] arguments 作用? 解決當函數的形參個數不確定的時候,通過arguments獲取實參的值如何使用arguments 獲取用戶傳遞實參的值? arguments 在函數中就是用來保存實參信息的偽數組 (可以按照數組的方式去遍歷, 但是不能使用數…

論wpf的設備無關性 - 簡書

論wpf的設備無關性 - 簡書 原文:論wpf的設備無關性 - 簡書 WPF從發布之日起&#xff0c;一直將“分辨率無關(resolution independence)”作為其亮點&#xff0c;聲稱使用WPF制作的用戶界面在輕巧的Ultra-Mobile PC的屏幕上和在50英寸的電視機上都能很好地顯示。微軟之所以稱WPF…

暑期學習總結6

本周書面學習時間大概6小時&#xff0c;代碼上5小時&#xff0c;java的基礎知識已經基本都學過一遍了&#xff0c;剩下的就是要鞏固&#xff0c;進行了一些實例操作&#xff0c;過程還算滿意&#xff0c;類的運用已經掌握了很多&#xff0c;現在已經習慣了java的類定義方法&…

javaScript第七天(1)

JavaScript基礎 核心知識點 Math對象中的方法數組對象中的方法字符串中的方法 今日學習目標 能夠掌握Math對象中的相關方法能夠掌握數組對象中的push方法能夠掌握操作字符串的方法 內置對象介紹 ? JavaScript組成&#xff1a; ECMAScript | DOM | BOM ? ECMA…

ISLR學習筆記(2)線性回歸

第三章 幾種常見的線性模型 1、簡單線性回歸 Y≈β0β1X 2、多元線性回歸 Y≈β0β1X1β2X2... 3、擴展線性回歸 Y≈β0β1X1β2X2β3X1X1 克服了多元線性模型 X1X1 與 X2X2 不協同作用的假設。 4、多項式回歸 Y≈β0β1X1β2X12β3log(X1)β4√X4 轉載于:https://www.cnblog…

淺談Aho-Corasick automaton(AC自動機)

Aho-Corasick automaton是什么&#xff1f; 要學會AC自動機&#xff0c;我們必須知道什么是Trie&#xff0c;也就是字典樹。Trie樹&#xff0c;又稱單詞查找樹或鍵樹&#xff0c;是一種樹形結構&#xff0c;是一種哈希樹的變種。典型應用是用于統計和排序大量的字符串&#xff…