首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
辅导command-language留学生、讲解Java编程、解析BigInteger、讲解Java语言 辅导Python编程|辅导Python
Assignment 2. Sets.
For this assignment an interpreter has to be written for a calculator with the
"command-language" shown further down. All "sentences" in this command-language
are statements for operations with sets of arbitrary big natural numbers.
The calculator should be able to store an arbitrary number of variables (A variable
being a combination of a name and a value.).
Proceed as follows:
1. Make a specification for an Identifier ADT and a Set
ADT. The type
Identifier will be the type of the name and the type Set
will be the type
of the value of each variable stored by the calculator.
2. From the API use (1) the class BigInteger to implement the arbitrary big
natural numbers and (2) the class HashMap
to store the arbitrary
number of variables.
3. Implement the class List
according to the specification given in the
ListInterface
. The given class Node has to be used in the implementation
of this class List. We provide a class ListTest which you can optionally use
to test your implementation. You can find this class on Blackboard.
Instructions on how to use it are at the end of this document.
4. Implement the class Set
with the class List
.
5. Use instances of the class APException in case you want to throw an
exception.
6. Make, using the objects, a design for the interpreter. Use the method of
recursive descent (see the example at the end).
7. Get approval for the self-made interfaces, as well as the design of the
interpreter, at the meetings with the assistant.
8. Once your design and interfaces have been approved, and you have
implemented the interfaces, you can start with programming. First,
completely write-out the parser part of your design. Which means, write a
program that reads lines of input, and does nothing in case of a correct
command, but returns a clear error-message in case there are incorrect
commands.
9. Only when the parser works, must you proceed to extend it to an interpreter.
The interpreter must recognize and execute commands written in the
command-language specified below.
You can find the interface ListInterface, the class Node and the class APException
on Blackboard.
With the aid of the command-language specified further down, we can manipulate
the sets of natural numbers and the variables that are contained in the calculator.
Only identifiers are allowed as names for variables. There are four operators that can be used on sets in this language:
+ : A + B = { x | x ∈ A ∨ x ∈ B } union
* : A * B = { x | x ∈ A ∧ x ∈ B } intersection
: A B = { x | x ∈ A ∧ x B } complement
| : A | B = { x | x ∈ A + B ∧ x A * B } symmetric difference
= { x | x ∈ (A + B) (A * B) }
The operator '*' has a higher priority than '+', '|' and '-', whom have the same
priority. The operators are left-associative.
Example: A B * Set1 + D is to be evaluated as (A ? (B * Set1)) + D.
There are two commands available. For each of those an example is given:
1. Set1 = A + B Set1 * (D + Set2)
Calculate the set that is the result of the expression to the right of the
'='-sign and associate the variable with the identifier Set1 with this Set.
2. Set1 + Set2
Calculate the set that is the result of the expression, and print the
elements of this set: separated by spaces on a single line on the
standard output.
Do not print any other text or commas because this will interfere
with the automated test.
Syntax command-language
We use the EBNF-notation for describing the syntax-portion of the commandlanguage
grammar. Furthermore the signs ‘<’ and ‘>’ are used for descriptions (for
example
).
program = { statement }
;
A program is any arbitrary number of statements (commands) ended by the
end of file.
statement = assignment | print_statement | comment ;
A statement is an assignment-statement, a print-statement or a comment-line.
assignment = identifier '=' expression
;
An assignment statement is an identifier, followed by the '=' sign, after which
there is an expression, followed by an end-of-line. print_statement = '?' expression
;
A print statement is a '?' followed by an expression and ended with an end-ofline.
comment = '/'
;
A comment is a line of text that starts with the '/' -sign and is closed by an
end-of-line.
identifier = letter { letter | number } ;
An identifier starts with a letter and only consists of letters and numbers.
expression = term { additive_operator term } ;
An expression is a term, followed by zero or more terms. All terms are
separated by an additive-operator.
term = factor { multiplicative_operator factor } ;
A term is a factor, followed by 0 or more factors. All factors are separated by
a multiplicative-operator.
factor = identifier | complex_factor | set ;
A factor is an identifier, a complex factor or a set.
complex_factor = '(' expression ')' ;
A complex factor is an expression between round brackets.
set = '{' row_natural_numbers '}' ;
A set is a row of natural numbers between accolades.
row_natural_numbers = [ natural_number { ',' natural_number } ] ;
A row of natural numbers is empty or a summation of one or more natural
numbers separated by commas.
additive_operator = '+' | '|' | '?' ;
An additive operator is a '+', a '|' or a '-' sign.
multiplicative_operator = '*' ;
A multiplicative operation is a '*' -sign.
natural_number = positive_number | zero ;
A natural number is a positive number or zero.
positive_number = not_zero { number } ;
A positive number does not start with a zero, does not have a sign, and has 1
or more numbers.
number = zero | not_zero ; A number is a zero or not a zero.
zero = '0' ;
Zero is the number 0.
not_zero = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
Not-zero is the number from the range 1 up to and including 9.
letter = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' |
'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' |
'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' |
'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' ;
A letter is a capital letter or a small letter.
Remarks
1. Spaces in natural numbers and identifiers are not allowed. Elsewhere, spaces
have no function and they can be added to any line to increase readability.
2. When a faulty statement is discovered, then a clear error message needs to be
printed, followed by a new-line. Explanatory error messages like this are
necessary in the test-phase to discover what the program exactly does (this is
usually something else than what it should do).
3. The program has to read from standard input and write to standard output.
The output must consist of one-line error-messages or one-line with
numbers, separated with spaces and ending with an end-of-line after the last
number.
4. Comments have to be ignored.
Recursive descent
We illustrate how to make a design by showing how a factor can be recognized
with the method "recursive descent". "recursive descent" means that the methods
that parse the input call each other recursively.
We can, for example, design a method factor() that:
1. returns a set of natural numbers as the result of the function if there is
grammatically correct input, and
2. gives an exception, and throws an APException if there is grammatically
incorrect input.
When the method factor() parses a complex factor, the right expression has to
be parsed, for which a term has to be parsed, for which another correct factor has to
be parsed. So after 3 calls in between, factor() is called again (in other words
there is recursion). A first sketch of the method factor() is:
Set factor () throws APException {
/* factor() reads, if possible, a correct factor of the input.
If this succeeds this factor is evaluated and the resulting
set is returned.
If this fails, then an error-message is given and a
APException is thrown.
*/
if (the next character is a letter) {
read an identifier
retrieve the set that belongs with that identifier
} else
if (the next character is '{') {
read a set
} else
if (the next character is '(') {
determine the set that is the result of the complex factor
} else
give a clear error-message
throw APException
}
RETURN the value of the set
}
Also, pay attention to the similarity between the syntax-definition of a factor and
the design of factor(). The syntax-rules are a very thorough
analysis/description of the input and only have to be converted to a Java during the
design process. Testing List implementation
In order to help you implement the ListInterface, we provide you with a unit test ListTest.java. You
can download it from Canvas. Usage of this test is completely optional. You won't get any points for
using it, but testing might help you to implement the list faster and with less errors.
If you name your implementation of the ListInterface List.java, you can automatically use these tests
(if you have a different class name, you need to change all occurrences of the type “List” in the test
file accordingly).
Test framework: JUnit
The unit test uses JUnit (junit.org). Follow this?tutorial?on?how?to?use?JUnit?in?Eclipse. If you want to
learn more about JUnit, look at the documentation.
Quickstart
In short, you need to follow these steps to use our test suite in Eclipse:
1. Right-click on the package in which you want to create the test and select New > JUnit Test
Case.
2. Fill “ListTest” into the name field and click Finish.
3. Eclipse prompts you to add JUnit to the build path. Approve this by clicking OK.
4. Paste the content from ListTest.java on Blackboard into this newly generated file.
5. Right-click on the newly generated file ListTest.java and select Run as > JUnit Test. Eclipse
will open a list of tests which were passed and failed.
If anything is unclear follow the detailed tutorial at
https://courses.cs.washington.edu/courses/cse143/11wi/eclipse‐tutorial/junit.shtml
More testing
The provided tests are not complete. You can add additional tests for lists in the same file. If you want to create a
test for another class, you can use the file as a template.
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
辅导 comm2000 creating socia...
2026-01-08
讲解 isen1000 – introductio...
2026-01-08
讲解 cme213 radix sort讲解 c...
2026-01-08
辅导 csc370 database讲解 迭代
2026-01-08
讲解 ca2401 a list of colleg...
2026-01-08
讲解 nfe2140 midi scale play...
2026-01-08
讲解 ca2401 the universal li...
2026-01-08
辅导 engg7302 advanced compu...
2026-01-08
辅导 comp331/557 – class te...
2026-01-08
讲解 soft2412 comp9412 exam辅...
2026-01-08
讲解 scenario # 1 honesty讲解...
2026-01-08
讲解 002499 accounting infor...
2026-01-08
讲解 comp9313 2021t3 project...
2026-01-08
讲解 stat1201 analysis of sc...
2026-01-08
辅导 stat5611: statistical m...
2026-01-08
辅导 mth2010-mth2015 - multi...
2026-01-08
辅导 eeet2387 switched mode ...
2026-01-08
讲解 an online payment servi...
2026-01-08
讲解 textfilter辅导 r语言
2026-01-08
讲解 rutgers ece 434 linux o...
2026-01-08
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!