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.mzph.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…