`
guoyiqi
  • 浏览: 1001715 次
社区版块
存档分类
最新评论

ECE/CPSC 3520

 
阅读更多

ECE/CPSC 3520
Fall 2014
Software Design Exercise #1
Blackboard submission only
Assigned 9-08-2014
Due 9-24-2014 11:59PM
Contents
1 Preface 3
1.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 The Bigger Picture: SDEs 2 and 3 . . . . . . . . . . . . . . . . 3
2 Resources and Notation 4
2.1 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Prolog Argument Designations . . . . . . . . . . . . . . . . . . 4
3 The Lexical Constraints and Data Structures 5
3.1 Basic Lexical Constraints . . . . . . . . . . . . . . . . . . . . . 5
3.2 ’needs’ Predicate and Argument Syntax . . . . . . . . . . . . . 5
3.3 ’resources’ Predicate and Argument Syntax . . . . . . . . . . . 6
4 Using flex and bison to Validate The Syntactic Correctness
of an Input String 7
4.1 Entities to be Recognized . . . . . . . . . . . . . . . . . . . . 7
4.2 Naming and Building . . . . . . . . . . . . . . . . . . . . . . . 8
5 Sample Use 8
6 Notes 11
1
7 Format of the Electronic Submission 11
2
1 Preface
1.1 Objectives
The overall objectives of SDE1 are:
1. To introduce flex and bison as general purpose scanner/parser devel-
opment tools.
2. To use flex and bison to build a grammatical recognizer to check the
syntactic correctness of a set of data structures to be used in SDEs 2
and 3.
These data structures will be used with Prolog and ocaml to satisfy a
scheduling (CSP) problem (see the section below).
Alternately, we are designing, implementing and testing an application-
dependent syntactic recognizer, implemented as a scanner/parser.
3. To give you experience in grammatical inference. Given the specifica-
tions herein, you will design G and implement it using flex and bison.
Grammatical ambiguity is not desired.
All work is to be done on a linux platform. Your grade is based upon a
correctly working implementation. Significant in-class discussion will accom-
pany this SDE. Get started now.1
This is an individual (not group) effort.
1.2 The Bigger Picture: SDEs 2 and 3
As a part of my ’un-retirement’ from the ECE Graduate Coordinator posi-
tion, I am now faced with a significant problem every semester:
The ECE Department offers many undergraduate labs. These
labs must be staffed by graduate Teaching Assistants (TAs).
Thus, the framework for a real problem. The long-term purpose of this
project is to design, implement and test systems for the scheduling of ECE
Graduate student teaching assistants (TAs). All representation and manip-
ulation will be done using Prolog (SDE2) and ocaml (SDE3). System inputs
1At least install flex and bison.
3
include department TA needs and available TA capabilities. System output
will be an assignment of TAs to labs. Here, the problem is to check the
syntactic correctness of inputs.
2 Resources and Notation
2.1 Resources
As discussed in class, it would be foolish to attempt this SDE without care-
fully exploring:
1. The text, especially the many examples in Chapter 6;
2. The flex manual (http://flex.sourceforge.net/manual/); and
3. The bison manual (http://www.gnu.org/software/bison/manual/).
2.2 Notation
The data structures will be used as Prolog arguments in SDE2. For now,
we concentrate on the structure (syntax) of the arguments. This does two
things:
1. It gets you familiar with the data structures you’ll use in SDE 2; and
2. It provides an application for flex and bison.
2.3 Prolog Argument Designations
See the book, p. 77, Section 3.1.5. This was discussed in class. I show argu-
ment structure with a combination of the notation used for Prolog predicate
arguments (+,-,?) and the notation for the positive closure set (+). For
example,
+Course+
indicates a variable ’Course’, which is bound when used (the left +), and
may be repeated 1 or more times (the right +).
4
3 The Lexical Constraints and Data Struc-
tures
3.1 Basic Lexical Constraints
1. Days are atoms m,tu,w,th,f.
2. Times are unsigned integers and causal (Stop_Time > Start_Time).
You do not need to check for causality.
3. Sections are unsigned integers.
4. Course names are the letters ’ece’ followed by four digits.
5. Student names are variable-length and comprised of lowercase alpha-
betic characters, e.g., jason, freddy, michael.
6. White space (see the text and examples) is allowed.
You need to develop REs for each of these entities, as a precursor to
building a scanner. I strongly recommend you design, implement
and test a freestanding scanner first.
3.2 ’needs’ Predicate and Argument Syntax
needs([+Course_List+])
where
Course_List itself is a list of form:
[+Course_name,+Section,+Day,+Start,+End]
A sample ’needs’ argument is shown below:
[[ece2090,1,m,13,16],
[ece2090,2,tu,13,16],
[ece2090,3,w,13,16],
[ece2090,4,f,9,12],
[ece2060,1,tu,11,14],
[ece2060,2,tu,14,17],
[ece2060,3,w,9,12],
[ece2060,4,f,13,16],
[ece3520,1,tu,11,14],
5
[ece3520,2,tu,14,17],
[ece4420,1,w,13,16],
[ece4420,2,f,13,16]]
Thus, the predicate could be used in Prolog (SDE 2) as:
needs([
[ece2090,1,m,13,16],
[ece2090,2,tu,13,16],
[ece2090,3,w,13,16],
[ece2090,4,f,9,12],
[ece2060,1,tu,11,14],
[ece2060,2,tu,14,17],
[ece2060,3,w,9,12],
[ece2060,4,f,13,16],
[ece3520,1,tu,11,14],
[ece3520,2,tu,14,17],
[ece4420,1,w,13,16],
[ece4420,2,f,13,16]]).
Notice the (allowed) use of whitespace.
3.3 ’resources’ Predicate and Argument Syntax
The Prolog predicate ’resources’ is an arity-1 predicate whose single argument
is used to ’hold’ the list-structured database of resources.
resources([+Student_Resource+])
The resources argument is a list of the overall resources database and is
of (list-of-lists) form, where individual student resource entries are lists of
resources_entry structure:
[+Student_Name,+Course_Capabilities_List,+Unavailable_List]
The 2nd and 3rd elements of the above resources_entry are variable-
length lists. Course_Capabilities_List is just a list of courses the student
is qualified to TA for. Time periods a student is not available are represented
in Unavailable_List with structure
6
=[[+Day,+Start_Time,+Stop_Time]+]
An empty Unavailable_List = [] means a student is available 24/5.
As a note in the Prolog solution (later), you MUST revise a specific
student’s Unavailable when used in a generated schedule.
Sample resources and resource entries:
[[joe, [ece2090,ece2010,ece3520,ece4420],[[m,8,9]]],
[sam, [ece2010,ece4420],[[tu 9,11],[th,9,11]]],
[pete, [ece3520,ece4420],[]],
[randi, [ece2090],[]],
[gwen, [ece2090,ece2010],[]]]
4 Using flex and bison to Validate The Syn-
tactic Correctness of an Input String
Here you will treat scanning and parsing of an input file, using a prespecified
set of data structures, as if it were ’source code’ constrained by a grammar
whose corresponding language is shown in Section 3. I’ll discuss syntactic
correctness in class and show examples of correct and incorrect files.
This SDE MUST be done using both flex and bison (and c).
4.1 Entities to be Recognized
The examples presented (both valid and errors) should help in understanding
of the desired syntax.
The following syntactically correct valid expressions, later to be used as
Prolog arguments, are to be recognized:
• needs
• unavailable_list
• course_capabilities_list
• resources_entry
• resources (resources_list)
7
The astute reader will note that some of the above entities are parts of others
(e.g., resources_entry and resources_list). In this case, the recognizer
should recognize the larger entity, not the component.
As shown in the examples, after recognition of each, a printf statement is
used to signify recognition of a syntactically correct construct. The display
format shown in the examples is to be used.
4.2 Naming and Building
The evaluation of your work will be partially automated. Therefore, you
must adhere to a number of specifications. The flex input file is to be
named schedule.in; the bison file is to be named schedule.y; the c file
containing main is to be named schedule.c; and the linux executable is to
be named schedule. We will use flex and bison to build your executable
with the following script (buildit):
#! /bin/bash
## to build scanner/parser */
bison -d -v $1.y
flex $1.in
gcc $1.c -lfl -Wall -o $1
For reference, here is the building of my solution:
$./buildit schedule
$
Anybody see any errors or warnings?
5 Sample Use
Here are a few cases. I’ll discuss these in class. Your effort should follow the
output format shown.
$./buildit scheduler
$ cat needs
[[ece2090,4,f,9,12],
[ece2095,4,w,9,12],
[ece3090,1,tu,1,3]
8
]
$./schedule <needs
found valid ’needs’ list’
$cat bad_needs
[[ece2090,4,f,9,12],
[ece2095,w,9,12],
[ece3090,1,tu,1,3]
]
$./schedule <bad_needs
syntax error
$cat bad_needs2
[[ece2090,4,f,9,12],
[cpsc2095,4,w,9,12],
[ece3090,1,tu,1,3]
]
$./schedule <bad_needs2
syntax error
$cat unavail_list0
[]
$./schedule <unavail_list0
found valid ’unavailable_list’
$cat unavail_list1
[[tu,7,9],[w,13,16]]
$./schedule <unavail_list1
found valid ’unavailable_list’
$cat bad_unavail_list1
[[tu,7,9][w,13,16]]
$./schedule <bad_unavail_list1
syntax error
$cat bad_unavail_list2
[[tu,7,9],[w,13-16]]
$./schedule <bad_unavail_list2
syntax error
$cat course_capabilities_list1
[ece2090,ece2010,ece3520,ece4420]
$./schedule <course_capabilities_list1
9
found valid ’course_capabilities’ list
$cat bad_course_capabilities_list1
[[ece2090,ece2010,ece3520,ece4420]]
$./schedule <bad_course_capabilities_list1
syntax error
$cat resources_entry1
[sam, [ece2010,ece4420],[]]
$./schedule < resources_entry1
found valid ’resources_entry’ list
$cat bad_resources_entry1
[ece3400, [ece2010,ece4420],[]]
$./schedule < bad_resources_entry1
syntax error
$cat bad_resources_entry2
[jenny, [ece2010,ece4420],[12,13]]
$./schedule < bad_resources_entry2
syntax error
$cat resources2
[
[joe, [ece2090,ece2010,ece3520,ece4420],[[m,8,9]]],
[sam, [ece2010,ece4420],[[tu,9,11],[th,9,11]]],
[pete, [ece3520,ece4420],[]],
[randi, [ece2090],[]],
[gwen, [ece2090,ece2010],[]]
]
$./schedule <resources2
found valid ’resources list’
$cat resources2b
[[joe, [ece2090,ece2010,ece3520,ece4420],[[m,8,9]]],
[sam, [ece2010,ece4420],[[tu,9,11],[th,9,11]]],
[pete, [ece3520,ece4420],[]],
[randi, [ece2090],[]],
[gwen, [ece2090,ece2010],[]]]
$./schedule <resources2b
found valid ’resources list’
$cat bad_resources2b
[[joe, [ece2090,ece2010,ece3520,ece4420],[[m,8,9]]],
[sam, [ece2010,ece4420],[[tu,9,11],[th,9,11]]],
10
[pete, [ece3520,ece4420],[sat,12,15]],
[randi, [ece2090],[]],
[gwen, [ece2090,ece2010],[]]]
$./schedule <bad_resources2b
syntax error
$cat bad_resources1
[[joe, [ece2090,ece2010,ece3520,ece4420],[]],
[sam, [ece2010,ece4420],[]],
[pete, [ece3520]],
[randi, [ece2090],[]],
[gwen, [ece2090,ece2010],[]]]
$./schedule <bad_resources1
syntax error
6 Notes
• Building of the scanner parser should not generate any shift/reduce
conflicts and/or useless rule or nonterminal warnings.
• The parser should never report that a file is syntactically correct in
addition to reporting an error.
• If we can’t build your scanner/parser with the buildit script, we can’t
grade it.
7 Format of the Electronic Submission
The final zipped archive is to be named <yourname>-sde1.zip, where <yourname>
is your (CU) assigned user name. You will upload this to the Blackboard
assignment prior to the deadline.
The use of gcc, flex and bison should not generate any errors or warn-
ings. The grader will attempt to build and then test your executable. The
grade is based upon a correctly working solution.
The minimal contents of your archive are:
1. A readme.txt file listing the contents of the archive and a brief de-
scription of each file. Include ’the pledge’ here. Here’s the pledge:
11
Pledge:
On my honor I have neither given nor received aid on this
exam.
This means, among other things, that the code you submit is your
code, and it was developed independently. Thus, you should not be
discussing your approach or solution with others in class or anywhere
else.
2. The flex, bison and c sources for your implementation named schedule.*,
where * is in, y and c, respectively. We will use the yyerror.c file
shown in class and in the book, page 180, Figure 6.11 to build the
executable. You should too. Do not redefine this function or include
yyerror.c in your archive.
3. A log of 6 sample uses (3 correct, 3 errors) of the resulting executable for
each element to be recognized in Section 4.1. Name this log schedule.log.
Pick examples other than the ones shown here.
12

分享到:
评论

相关推荐

    ECE_TRANS_WP.29_2020_79_E.pdf

    文件指出,GRVA工作组基于2019年修订的框架文件ECE/TRANS/WP.29/2019/34,对新提案进行了讨论,并在2020年的会议中进一步修订了该提案。 此外,文件还提到了1958年协议,这是国际上对于汽车技术法规进行协调的一项...

    9 [E_]ECE_TRANS_WP.29_GRSG_2010_8-EN.pdf

    根据2006-2010年内陆运输委员会工作计划(ECE/TRANS/166/Add.1,项目活动02.4),世界论坛的任务是发展、协调和更新法规,以提高车辆的性能。提交此文档是为了遵循这一授权。 修订的目的是为了使测试流程更加精简和...

    ECE R131 .pdf

    Concerning the Adoption of Uniform Technical Prescriptions for Wheeled Vehicles, Equipment and Parts which can be Fitted and/or be Used on Wheeled Vehicles and the Conditions for Reciprocal ...

    2020-05-28_ECE-R151_EN.pdf

    2. BSIS标准是欧盟在2019年通过的ECE R151法规中的一部分,该法规修订了车辆、设备和零部件的统一技术规定。ECE R151法规是《关于为轮式车辆装备和/或在轮式车辆上使用的设备和零部件采用统一技术规定联合国法规的...

    12 R026r2e.pdf

    同时,该文档还提及了其他几个具有法律效力的文件,如ECE/TRANS/WP.29/2015/82、ECE/TRANS/WP.29/2020/15和ECE/TRANS/WP.29/2020/26,这些文件可能包含进一步的修订或指导。 车辆外部投影的规定涉及车辆的各个方面...

    ECE R155.pdf

    联合国ECE R155规定是关于车辆网络安全和网络安全管理体系的统一规定。文档中提到的ECE R155是在日内瓦通过的两个历史协议基础上发展起来的,这些协议分别是1958年的《关于采纳统一条件的车辆装备和部件批准和批准...

    ECE法规目录列表(中英对照)[参照].pdf

    ECE法规目录列表(中英对照) ECE法规目录列表(中英对照)是指1958 Agreement ECE法规的目录列表,该列表提供了车辆设备的法规标准,包括头灯、尾灯、倒车镜、方向指示器、制动灯等车辆设备的法规要求。该列表对...

    unity手指足球游戏项目源码

    unity手指足球游戏项目源码,源码演示视频地址:https://www.bilibili.com/video/BV1cvg4ecE7R/;unity手指足球游戏项目源码,源码演示视频地址:https://www.bilibili.com/video/BV1cvg4ecE7R/;unity手指足球游戏...

    ECE R79 转向认证 (含中英文版)

    ECE R79转向认证是联合国欧洲经济委员会(UNECE)发布的一项法规,全称为《关于转向装置方面批准车辆的统一规定》。该法规主要针对自动驾驶汽车的安全标准,特别是涉及车辆转向系统的控制、性能和安全要求。在自动...

    ECE工况MATLAB数据_ECE_电压电流数据_ece工况_工况_转速数据_

    ECE工况,全称是欧洲循环测试工况(European Driving Cycle),是一种模拟真实驾驶条件的测试标准,常用于评估汽车的动力系统性能和排放水平。在这个工况下,MATLAB数据集提供了车辆在ECE工况下的关键参数,主要包括...

    ECE R79-关于转向装置方面批准车辆的统一规定.pdf

    ECE R79是关于机动车辆转向装置批准的国际统一规定。该规定旨在为轮式车辆、安装和/或用于轮式车辆的装备和部件的批准提供统一的技术条件,并基于这些条件实现相互认可。 首先,ECE R79规范的背景在于,传统转向...

    ECE R94标准

    ### ECE R94标准详解 #### 一、概述 ECE R94标准是针对车辆正面碰撞安全的一项国际统一技术规定。该标准由联合国欧洲经济委员会(UNECE)制定,旨在确保车辆在发生正面碰撞时能有效保护车内乘员的安全。ECE R94...

    ECE R13H-乘用车制动系统型式认证的统一规定.pdf

    ECE R13H-乘用车制动系统型式认证的统一规定 知识点详细解析: 1. ECE R13H定义及背景 ECE R13H是一套针对乘用车制动系统的型式认证统一规定。这份规定属于联合国欧洲经济委员会(ECE)制定的技术条例之一,旨在通过...

    ECE R64翻译版

    ECE R64翻译版是一份涉及轮胎压力监测系统的欧盟法规文件,它规定了轮胎压力监测系统(TPMS)的法规和试验要求。这一文件对于汽车制造商和相关行业来说是十分重要的,因为它定义了关于轮胎压力监测系统认证、技术...

    ECE statics

    ### ECE Statics:UIUC Statics Notes及在电气与计算机工程领域的应用 #### 基础知识(Foundations) 本部分介绍了概率论的基础概念及其在工程应用中的重要性。首先,作者强调了不确定性在实际工程问题中的普遍...

    ECE-R129标准的解读.pdf

    "ECE-R129标准的解读" ECE R129标准是欧洲经济委员会(United Nations Economic Commission for Europe,简称UNECE)制定的儿童约束系统标准,旨在确保儿童约束系统的安全性和可靠性。本标准对儿童约束系统的设计、...

    ECE R79针对乘用车法规解读

    ECE R79法规是欧洲经济委员会(ECE)制定的一套关于车辆辅助驾驶系统(Automatic Driving Assistance Systems, ADAS)的规定,旨在确保这些系统的安全性和有效性。在本压缩包中,"ECE R79法规解读"文档将提供对该...

    ECE021 汽车安全标准

    ### ECE021汽车安全标准详解 #### 标题:ECE021 汽车安全标准 - **解读**:此标题指出了一个关键的汽车行业安全标准——ECE021。ECE(European Agreement Concerning the Adoption of Uniform Technical ...

Global site tag (gtag.js) - Google Analytics