I have an easy linux assignment. I am attaching the requirements and the zips. Please provide the most accurate and detailed answer possible.
The first project involves modifying the attached lexical analyzer and the compilation listing
generator code. You need to make the following modifications to the lexical analyzer,
scanner.l:
1. A new token ARROW should be added for the two character punctuation symbol =>.
2. The following reserved words should be added:
case, else, endcase, endif, if, others, real, then, when
Each reserved words should be a separate token. The token name should be the same as
the lexeme, but in all upper case.
3. Two additional logical operators should be added. The lexeme for the first should be or
and its token should be OROP. The second logical operator added should be not and its
token should be NOTOP.
4. Five relational operators should be added. They are =, /=, >, >= and 6 and 8 = 5 * (7 – 4);
end;
Compiled Successfully
Here is the required output for a program that contains more than one lexical error on the same
line:
1 — Function with two lexical errors
2
3 function test2 returns integer;
4 begin
5
7 $ 2 ^ (2 + 4);
Lexical Error, Invalid Character $
Lexical Error, Invalid Character ^
6 end;
Lexical Errors 2
Syntax Errors 0
Semantic Errors 0
You are to submit two files.
1. The first is a .zip file that contains all the source code for the project. The .zip file
should contain the flex input file, which should be a .l file, all .cc and .h files and a
makefile that builds the project.
2. The second is a Word document (PDF or RTF is also acceptable) that contains the
documentation for the project, which should include the following:
a. A discussion of how you approached the project
b. A test plan that includes test cases that you have created indicating what aspects
of the program each one is testing and a screen shot of your compiler run on that
test case
c. A discussion of lessons learned from the project and any improvements that could
be made
Here is the approach I recommend for project 1.
1) First build the skeleton for project 1 as shown in part 5 of the video series on lexical analysis
using the make file provided. Then run it on the test cases test1.txt – test3.txt that are
provided in Project 1 Skeleton Test Data file under the Week 2 videos and be sure that you
understand how it works. Examine the contents of lexemes.txt, so that you see the lexemetoken pairs that it contains.
2) A good starting point would be items 1 and 2 in the requirements, which include the arrow
symbol and the additional reserved words of the language. Each of these is a separate token and
require a separate translation rule. Examine the existing translation rules for the reserved words
as an example of how to proceed. In addition, add the token names for each one to the
enumerated type Tokens in tokens.h. The order in which you add them is unimportant. Rebuild
the program with the make file to ensure that it builds correctly.
Use test4.txt to test this modification. Shown below is the output that should result when
using that test case as input:
$ ./compile < test4.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- Program containing arrow symbol and new reserved words
function main b: integer returns integer;
a: real is 3;
begin
if a < 2 then
7 + 2 * (2 + 4);
else
case b is
when 1 => a * 2;
when 2 => a + 5;
others => a + 4;
endcase;
endif;
end;
You should receive no lexical errors. At this point, you should also examine lexemes.txt to see
each new reserved word and the arrow symbol have unique token numbers.
3) Adding all the operators as specified by items 3-8 in the requirements would be a good next
step. Examine the existing translation rules for the existing operators as an example of how to
proceed. As before, you must also add the token names for each new operator to the enumerated
type Tokens in tokens.h.
Use test5.txt to test this modification. Shown below is the output that should result when
using that test case as input:
$ ./compile < test5.txt
1
2
-- Program containing the new operators
3
4
5
6
7
8
9
10
11
12
13
14
15
function main b: integer, c: integer returns integer;
a: real is 3;
begin
if (a < 2) or (a > 0) and (b /= 0) then
7 – 2 / (9 rem 4);
else
if b >= 2 or b 0) and (b /= 0) or false then
7 – 2 / (9 rem 4);
else
if b >= 2 or b
4
5 — Valid identifiers
6
7 name_1
8 name_1_a2_ab3
9
10 — Invalid identifiers
11
12 name__2
Lexical Error, Invalid Character _
Lexical Error, Invalid Character _
13 _name3
Lexical Error, Invalid Character _
14 name4_
Lexical Error, Invalid Character _
15
16 — Literals
17
18 123 123.45 123. 1.2E2 1.e+2 1.2E-2 true false
19
20 — Logical operators
21
22 and or not
23
24 — Relational operators
25
26 = /= > >= <
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more