首页 > > 详细

COMP712编程实验代写、代做program语言、C/C++程序实验代做代写Python程序|帮做Haskell程序

COMP712 Programming Languages
Assignment 2 (35%)
Deadline: 23 October 2020 11:59pm
This assignment consists of two parts that are linked. You are required to submit a written
document for part 1, and a Racket program for Part 2.
Part 1 LL(1) Grammar for mLang (20%)
Tasks:
1. Develop a syntax grammar for the mLang programming language as described in Assignment
1. The description of the language is provided after Part 2 of this assignment for convenience.
It must be shown to be an LL(1) Grammar. BNF notation should be used. Take care to include
all types of statements allowed and function declarations and calls. At least one production
rule should include ε.
Hint: Search for the grammar definitions of an imperative language like C on the Internet. Use
relevant parts of this grammar as a starting point. But note that the grammars are not be
exactly the same.
2. Derive the Parse Table for your grammar. Obtain the FIRST and FOLLOW sets and then derive
the PREDICT sets (Parse Table) from them.
Submission: Submit a document that includes both tasks for this part of the assignment. The grammar
must be typed with the grammar production rules formatted neatly. You will need to include a short
explanation why your grammar is considered LL(1). The second part could be typed or handwritten.
But handwriting should be legible. It must be submitted through Blackboard by the deadline.
Marking Scheme: 12 marks are allocated for the LL(1) grammar rules. One mark will be deducted for
each error in the grammar submitted, excluding LL(1) compliance. 2 marks are allocated to LL(1)
compliance and your short explanation why you consider this an LL(1) grammar. 2 marks are allocated
to the correct FIRST sets, 2 marks for the FOLLOW sets, and 2 marks for the Parse Table.
2
Part 2 Implementation of Table Driven LL(1) Parser (15%)
Task: Write a Racket program that performs Table-driven LL(1) parsing based on the skeleton
pseudo-code described in the lecture. The parser will be passed a list of tokens that are
generated as the output of the Lexer you have developed in Assignment 1. The output of the
parser should be a message to say whether the syntax of the source code conforms to the
grammar of mLang that you come up with in Part 1. If there are syntax errors, the output of
the parser should indicate that a syntax error is encountered.
You have the freedom to decide how the grammar rules are to be encoded in Racket.
Submission: Your submission should consists of the following files:
(1) Racket source code of your parser AND lexer. Although the lexer is not marked, it is
required for completeness;
(2) a file of mLang source codes used for testing; and
(3) a file of the outputs of the test cases conducted.
These three files must be archived (i.e. zipped) into a single file with your name and student
number as the filename.
Marking Scheme:
Parser runs correctly for all test cases provided 5%
Test cases provided covers all major elements of the language 2%
Parser runs correctly for the unseen test cases of the marker 5%
Parser generates error messages 1%
Adequate comments in the Racket source code 2%
-------------------------------------------------------------------------------------------------------
Total: 15%
*************************************
The mLang programming language:
mLang is a simple programming language with a C-like syntax. There are three basic types:
integer, Boolean, and string. It binds values to names in the following way:
let x = 3;
let name = ”John”;
let num = 4 * (2 + 3) / 5;
mLang also supports arrays. Elements in arrays are accessed by integer indices starting from
zero:
3
let a = [1, 2, 3];
a[0] // =1
Texts after // are comments.
mLang also supports hashes:
let person = [”name”: ”John”, ”age”: 20];
person[”John”] // = 20
With mLang, functions are defined in the following way:
let add = fn(a, b) {return a + b;};
Values can be returned through a return statement as above. They can also be returned
implicitly as the last computed value:
let add = fn(a, b) {a + b;};
Note the semi-colon after the }. Functions are called in the usual way with parameters in
round parentheses:
add(3, 6);
mLang supports recursive function calls. An example function that calculates the Fibonacci
numbers is shown here:
let fib = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
1
} else {
fib(x – 1) + fib(x – 2);
}
}
};
Also note that semi-colon after 0 and 1 are optional.
Functions in mLang are first-class and therefore can be used as arguments to another function.
Hence, it also supports higher-order functions:
let twice = fn(f, x) {
4
return f(f(x));
};
let square = fn(x) {
return x*x;
}
twice(square,2); // = 16
---------------END---------------

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点文章
程序代写更多图片

联系我们 - QQ: 99515681 微信:codinghelp
© 2014 www.7daixie.com
程序代写网!