SlideShare a Scribd company logo
1 of 18
Download to read offline
Hello!
Can someone help me to answer Task4 and Task7:
Complete "TODO" in this files:
AssignCompiler.scala
AssignInstrs.scala
AssignRuntime.scala
Task4: It is about handling conditional statements. The statement can be assign. For example,
a=5;
This is already done. Now, we need to handle if statement. For example, if(false) { x := x + 1 } {
x := 0 }
which is if Expr stmt* stmt*. (stmt*) many statements.
This is all the definition:
Prog ::= Stmt*
Stmt ::= Identifier = Expr | if Expr Stmt* Stmt*
Expr ::= Identifier | Literal | Expr {+,-,/,*,&&,||,=} Expr | {-,!} Expr
Literal ::= Number | true | false
Identifier ::= String
Task7 same idea but with while loop.
# Conditionals
In the first part of this exercise, we extend the Assign language with
conditional statements.
Syntax of the Assign language with conditionals
Prog ::= Stmt*
Stmt ::= Identifier = Expr | if Expr Stmt* Stmt*
Expr ::= Identifier | Literal | Expr {+,-,/,*,&&,||,=} Expr | {-,!} Expr
Literal ::= Number | true | false
Identifier ::= String
Task 1: Define the SOS relations for expressions and programs that add
conditionals to the assign language. Provide traces for 3 different
programs.
Done
# Compile conditionals
We compile conditionals to a machine that features only two
instructions: one for assignment as before and one for conditional
jumps.
Instr ::= Idx = Expr | jumpif Number Expr
For `jumpif`, the first component describes the target program
counter, which must be a constant number. The second component
describes the condition under which the jump takes place. That is, a
jump only takes place if the condition evaluates to `true` and is
skipped otherwise.
We reuse machine states unchanged:
State ::= (Prog, PC, Heap)
PC ::= Number
Heap ::= empty | Literal; Heap
Task 2: Define the semantics of the Assign language with conditionals
as a state transition relation. Provide traces for 3 different
programs.
Done
# Implementation of conditionals
To gain a detailed understanding of the Assign language with
conditionals and to facilitate experimentation, we will implement the
compiler and the abstract machine of the language in Scala. We use
[SBT](http://www.scala-sbt.org/) for building the project and
[ScalaTest](http://www.scalatest.org/) for testing. To compile the
project, run `sbt compile` on the command-line. With `sbt test` you
can execute the tests.
Task 3: Study the code of the Assign language and add two tests for
programs with assignments to `AssignTest.scala`.
Done
Task 4: Implement conditionals for the Assign language. We already
extended the expression type with conditionals. Please do not change
any of the signatures of expressions, because this makes it impossible
for us to test your code! To solve this task, add conditionals jumps
to the instructions, extend the compiler to handle conditionals and
extend the runtime of the abstract machine to handle conditional
jumps. Add at least 3 tests to `AssignTest.scala`, that test programs
containing conditionals.
# The While language
Next we want to add while loops to the language:
Syntax of the While language
Prog ::= Stmt*
Stmt ::= Identifier = Expr | if Expr Stmt* Stmt* | while Expr Stmt*
Expr ::= Identifier | Literal | Expr {+,-,/,*,&&,||,=} Expr | {-,!} Expr
Literal ::= Number | true | false
Identifier ::= String
Task 5: Define the SOS relations for expressions and programs of the
While language. Provide traces for 3 different programs.
# Compiled While language
While loops are also compiled to conditional jumps. The set of
instructions and the abstract machine stay unchanged:
State ::= (Prog, PC, Heap)
PC ::= Number
Heap ::= empty | Literal; Heap
Task 6: Define the semantics of the compiled While language as a state
transition relation. Provide traces for 3 different programs.
# Implementation of while loops
Task 7: Implement while loops for the Assign language with
conditionals. Use the same code base that you created for task 3. Add
at least 3 tests to `WhileTest.scala`, that test programs containing
while loops.
# Security vulnerabilities?
Task 8: Can you spot weaknesses in our model of While that may yield
security vulnerabilities later on? Describe any weakness you can find and
discuss whether it is exploitable or how it would become exploitable.
Solution
Task-4 :A shift-reduce conflict that frequently occurs involves the if-else construct. Assume we
have the following rules:
and the following state:
We need to decide if we should shift the ELSE or reduce the IF expr stmt at the top of the stack.
If we shift then we have
where the second ELSE is paired with the second IF. If we reduce we have
where the second ELSE is paired with the first IF. Modern programming languages pair an ELSE
with the most recent unpaired IF. Consequently the former behavior is expected. This works well
with yacc because the default behavior, when a shift-reduce conflict is encountered, is to shift.
Although yacc does the right thing it also issues a shift-reduce warning message. To remove the
message give IF-ELSE a higher precedence than the simple IF statement.
task-7
The while statement is used for repeated execution as long as an expression is true:
This repeatedly tests the expression and, if it is true, executes the first suite; if the expression is
false (which may be the first time it is tested) the suite of the else clause, if present, is executed
and the loop terminates.
A break statement executed in the first suite terminates the loop without executing the else
clause’s suite. A continue statement executed in the first suite skips the rest of the suite and goes
back to testing the expression.
task-1 :-
In case the result of
s
S
,
is not available we say that
is a
stuck
configuration and there
is no subsequent transitions.
Although SOS emphasizes to the intermediate execution, the
meaning
of a program
P
on
an input state
s
is the set of
final
states (also stuck configuration) that can be executed in
arbitrary finite steps.
Example Semantic
Going back to the “While” programming language example, the first two axioms
]
[
sos
ass
and
]
[
sos
skip
have not changed at all because the assignment and
skip
statements are
fully executed in one step.
[
]
[
]
s
s
skip
a
x
s
s
a
x
ass
sos
sos
=
,
]
[
,
:
]
[
skip
6
The two rules
]
[
1
sos
comp
and
]
[
2
sos
comp
for a statement
2
1
S
;
S
express that the execution
starts with the first step of
1
Sfrom
s
. Then there are two possible outcomes derived from
the two possibilities for transition relation:
1.
]
[
1
sos
comp
- The execution of
1
S
has not been completed we have to complete it
before embarking on the execution of
2
S . In this case the first step of
s
S
,
is an
intermediate configuration
'
,
'
1
s
S
then the next configuration is
'
,
;
'
2
1
s
S
S
.
'
,
;
'
,
;
'
,
'
,
]
[
2
1
2
1
1
1
1
s
S
S
s
S
S
s
S
s
S
comp
sos
2.
]
[
2
sos
comp
- The execution of
1
S has been completed we can start on the execution
of
2
S . In this case the result of execution
1
S from is a final state
s’
then the next
configuration is
'
,
2
s
S
Operational Semantics
Page 13
'
,
,
;
'
,
]
[
2
2
1
1
2
s
S
s
S
S
s
s
S
comp
sos
The first step of the condition statement starts with testing
b
, then branching according to
the outcome:
[
]
[]
ff
s
b
s
S
s
S
S
b
if
tt
s
b
s
S
s
S
S
b
if
ff
sos
tt
sos
=
=
if
else
then
if
if
else
then
if
,
,
]
[
,
,
]
[
2
2
1
1
2
1
The first step of the while statement is to “unf
old” it one level, that is to rewrite it as a
condition. In the next execution step a test is performed and the execution resumes. Note
that the
]
[
sos
while
rule breaks the compositional structur
e of the semantic (the reason is
that the rule defines the semantic in terms of
itself), hence structural induction doesn’t
work here fine.
skip,s
S
b
S;
b
s
S
b
while
sos
else
)
do
while
(
then
if
do
while
,
]
[
Derivation Sequence
A derivation sequence of a statement
S
starting in state
s
is either:
1. a finite sequence:
k
,..,
,.
,
2
1
0
of configurations satisfying:
•
s
S
,
0
=
•
0
,
0
1
<
+
k
k
i
i
i
for
•
ion
configurat
stuck
or
ion
configurat
terminal
a
either
is
k
2. an infinite sequence
,...
,
,
2
1
0
of configurations satisfying:
•
s
S
,
0
=
•
i
i
i
+
0
1
for
More notations:
1. For a terminal or a stuck configuration
i
we write:
i
i
0
- indicates that there are
i
steps in the execution from
i
to
0
i
*
0
- indicates that there is a finite number of steps from
i
to
0
2. we construct a derivation tree for each step in the sequence (see example below)
Examples
:
1.
()
z
y
y
x
x
z
=
=
=
:
;
:
;
:
assuming
5
0
=
x
s
and
7
0
=
y
s
The derivation sequence can be constructed as follows:
()
[]
[][]
[][][]
5
)
7
)
5
((
7
)
5
(
,
:
5
,
:
;
:
,
:
;
:
;
:
0
0
0
0
6
6
6
6
6
6
y
x
z
s
x
z
s
z
y
z
s
z
y
y
x
s
z
y
y
x
x
z
Thats all i know to give ans !!

More Related Content

Similar to Hello!Can someone help me to answer Task4 and Task7Complete T.pdf

Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design FileArchita Misra
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while LoopJayBhavsar68
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1Prerna Sharma
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentalsumar78600
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
control statements
control statementscontrol statements
control statementsAzeem Sultan
 
Control structures c2 c3
Control structures c2 c3Control structures c2 c3
Control structures c2 c3Omar Al-Sabek
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...Mark Simon
 
C++ control structure
C++ control structureC++ control structure
C++ control structurebluejayjunior
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrayssshhzap
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diarySHARDA SHARAN
 
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docxCMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docxmary772
 

Similar to Hello!Can someone help me to answer Task4 and Task7Complete T.pdf (20)

Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
9-java language basics part3
9-java language basics part39-java language basics part3
9-java language basics part3
 
Programming in C Session 1
Programming in C Session 1Programming in C Session 1
Programming in C Session 1
 
Control structures
Control structuresControl structures
Control structures
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
Chap05
Chap05Chap05
Chap05
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
control statements
control statementscontrol statements
control statements
 
Control structures c2 c3
Control structures c2 c3Control structures c2 c3
Control structures c2 c3
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diary
 
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docxCMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
CMPS 5P Assignment 3 Spring 19Instructions1. The aim o.docx
 

More from forwardcom41

Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfforwardcom41
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfforwardcom41
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfforwardcom41
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfforwardcom41
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfforwardcom41
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfforwardcom41
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfforwardcom41
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfforwardcom41
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfforwardcom41
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfforwardcom41
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfforwardcom41
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfforwardcom41
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfforwardcom41
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfforwardcom41
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfforwardcom41
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfforwardcom41
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfforwardcom41
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfforwardcom41
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdfforwardcom41
 
These are the answer I got but are not fully correct and ineffic.pdf
These are the answer I got but are not fully correct and ineffic.pdfThese are the answer I got but are not fully correct and ineffic.pdf
These are the answer I got but are not fully correct and ineffic.pdfforwardcom41
 

More from forwardcom41 (20)

Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdfHey I need help creating this code using Visual Studio (Basic) 2015.pdf
Hey I need help creating this code using Visual Studio (Basic) 2015.pdf
 
Given technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdfGiven technology today, would it be more feasible than in the pa.pdf
Given technology today, would it be more feasible than in the pa.pdf
 
Explain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdfExplain the difference between a contaminated culture and a mix c.pdf
Explain the difference between a contaminated culture and a mix c.pdf
 
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdfExplain in detail how OFDM helps mitigates multipath fading effects..pdf
Explain in detail how OFDM helps mitigates multipath fading effects..pdf
 
Complete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdfComplete a scientific inquiry research using three credible sources..pdf
Complete a scientific inquiry research using three credible sources..pdf
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
Describe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdfDescribe and illustrate the use of a bank reconciliation in controll.pdf
Describe and illustrate the use of a bank reconciliation in controll.pdf
 
Why is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdfWhy is it important for a trainer (trainers) to understand the commu.pdf
Why is it important for a trainer (trainers) to understand the commu.pdf
 
What are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdfWhat are the various portals an enterprise can use What is the func.pdf
What are the various portals an enterprise can use What is the func.pdf
 
What is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdfWhat is the nature of thermal energy What is heat at the atomic lev.pdf
What is the nature of thermal energy What is heat at the atomic lev.pdf
 
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdfw Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
w Hstory Bookmarks Window Help Apple Bing Google Taho0 NewaDetals MIN.pdf
 
Which of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdfWhich of the following is not one of the ethical standards included .pdf
Which of the following is not one of the ethical standards included .pdf
 
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdfUsing the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
Using the guidance from ASC 855-10-55-1 and 855-10-55-2 Answer the f.pdf
 
why we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdfwhy we need mixed methodology for researchSolutionMixed metho.pdf
why we need mixed methodology for researchSolutionMixed metho.pdf
 
What property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdfWhat property doesnt apply to fluids Newtons second, cons of ene.pdf
What property doesnt apply to fluids Newtons second, cons of ene.pdf
 
What is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdfWhat is the threat to culture by a read-only world, and how do t.pdf
What is the threat to culture by a read-only world, and how do t.pdf
 
What is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdfWhat is one hypothesis to explain why there are more endemic bird sp.pdf
What is one hypothesis to explain why there are more endemic bird sp.pdf
 
What are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdfWhat are the ethical tensions in advertisingWho are the responsib.pdf
What are the ethical tensions in advertisingWho are the responsib.pdf
 
Use the following information to answer the next Question. The graph.pdf
Use the following information to answer the next Question.  The graph.pdfUse the following information to answer the next Question.  The graph.pdf
Use the following information to answer the next Question. The graph.pdf
 
These are the answer I got but are not fully correct and ineffic.pdf
These are the answer I got but are not fully correct and ineffic.pdfThese are the answer I got but are not fully correct and ineffic.pdf
These are the answer I got but are not fully correct and ineffic.pdf
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Hello!Can someone help me to answer Task4 and Task7Complete T.pdf

  • 1. Hello! Can someone help me to answer Task4 and Task7: Complete "TODO" in this files: AssignCompiler.scala AssignInstrs.scala AssignRuntime.scala Task4: It is about handling conditional statements. The statement can be assign. For example, a=5; This is already done. Now, we need to handle if statement. For example, if(false) { x := x + 1 } { x := 0 } which is if Expr stmt* stmt*. (stmt*) many statements. This is all the definition: Prog ::= Stmt* Stmt ::= Identifier = Expr | if Expr Stmt* Stmt* Expr ::= Identifier | Literal | Expr {+,-,/,*,&&,||,=} Expr | {-,!} Expr Literal ::= Number | true | false Identifier ::= String Task7 same idea but with while loop. # Conditionals In the first part of this exercise, we extend the Assign language with conditional statements. Syntax of the Assign language with conditionals Prog ::= Stmt* Stmt ::= Identifier = Expr | if Expr Stmt* Stmt* Expr ::= Identifier | Literal | Expr {+,-,/,*,&&,||,=} Expr | {-,!} Expr Literal ::= Number | true | false Identifier ::= String Task 1: Define the SOS relations for expressions and programs that add conditionals to the assign language. Provide traces for 3 different programs. Done # Compile conditionals We compile conditionals to a machine that features only two instructions: one for assignment as before and one for conditional
  • 2. jumps. Instr ::= Idx = Expr | jumpif Number Expr For `jumpif`, the first component describes the target program counter, which must be a constant number. The second component describes the condition under which the jump takes place. That is, a jump only takes place if the condition evaluates to `true` and is skipped otherwise. We reuse machine states unchanged: State ::= (Prog, PC, Heap) PC ::= Number Heap ::= empty | Literal; Heap Task 2: Define the semantics of the Assign language with conditionals as a state transition relation. Provide traces for 3 different programs. Done # Implementation of conditionals To gain a detailed understanding of the Assign language with conditionals and to facilitate experimentation, we will implement the compiler and the abstract machine of the language in Scala. We use [SBT](http://www.scala-sbt.org/) for building the project and [ScalaTest](http://www.scalatest.org/) for testing. To compile the project, run `sbt compile` on the command-line. With `sbt test` you can execute the tests. Task 3: Study the code of the Assign language and add two tests for programs with assignments to `AssignTest.scala`. Done Task 4: Implement conditionals for the Assign language. We already extended the expression type with conditionals. Please do not change any of the signatures of expressions, because this makes it impossible for us to test your code! To solve this task, add conditionals jumps to the instructions, extend the compiler to handle conditionals and extend the runtime of the abstract machine to handle conditional jumps. Add at least 3 tests to `AssignTest.scala`, that test programs containing conditionals.
  • 3. # The While language Next we want to add while loops to the language: Syntax of the While language Prog ::= Stmt* Stmt ::= Identifier = Expr | if Expr Stmt* Stmt* | while Expr Stmt* Expr ::= Identifier | Literal | Expr {+,-,/,*,&&,||,=} Expr | {-,!} Expr Literal ::= Number | true | false Identifier ::= String Task 5: Define the SOS relations for expressions and programs of the While language. Provide traces for 3 different programs. # Compiled While language While loops are also compiled to conditional jumps. The set of instructions and the abstract machine stay unchanged: State ::= (Prog, PC, Heap) PC ::= Number Heap ::= empty | Literal; Heap Task 6: Define the semantics of the compiled While language as a state transition relation. Provide traces for 3 different programs. # Implementation of while loops Task 7: Implement while loops for the Assign language with conditionals. Use the same code base that you created for task 3. Add at least 3 tests to `WhileTest.scala`, that test programs containing while loops. # Security vulnerabilities? Task 8: Can you spot weaknesses in our model of While that may yield security vulnerabilities later on? Describe any weakness you can find and discuss whether it is exploitable or how it would become exploitable. Solution Task-4 :A shift-reduce conflict that frequently occurs involves the if-else construct. Assume we have the following rules: and the following state: We need to decide if we should shift the ELSE or reduce the IF expr stmt at the top of the stack. If we shift then we have where the second ELSE is paired with the second IF. If we reduce we have
  • 4. where the second ELSE is paired with the first IF. Modern programming languages pair an ELSE with the most recent unpaired IF. Consequently the former behavior is expected. This works well with yacc because the default behavior, when a shift-reduce conflict is encountered, is to shift. Although yacc does the right thing it also issues a shift-reduce warning message. To remove the message give IF-ELSE a higher precedence than the simple IF statement. task-7 The while statement is used for repeated execution as long as an expression is true: This repeatedly tests the expression and, if it is true, executes the first suite; if the expression is false (which may be the first time it is tested) the suite of the else clause, if present, is executed and the loop terminates. A break statement executed in the first suite terminates the loop without executing the else clause’s suite. A continue statement executed in the first suite skips the rest of the suite and goes back to testing the expression. task-1 :- In case the result of s S , is not available we say that is a stuck configuration and there is no subsequent transitions. Although SOS emphasizes to the intermediate execution, the meaning of a program P on an input state s is the set of final states (also stuck configuration) that can be executed in arbitrary finite steps. Example Semantic
  • 5. Going back to the “While” programming language example, the first two axioms ] [ sos ass and ] [ sos skip have not changed at all because the assignment and skip statements are fully executed in one step. [ ] [ ] s s skip a x s s a x ass sos sos = , ]
  • 6. [ , : ] [ skip 6 The two rules ] [ 1 sos comp and ] [ 2 sos comp for a statement 2 1 S ; S express that the execution starts with the first step of 1 Sfrom s . Then there are two possible outcomes derived from the two possibilities for transition relation: 1. ] [ 1
  • 7. sos comp - The execution of 1 S has not been completed we have to complete it before embarking on the execution of 2 S . In this case the first step of s S , is an intermediate configuration ' , ' 1 s S then the next configuration is ' , ; ' 2 1 s S S . ' , ; ' ,
  • 9. S has been completed we can start on the execution of 2 S . In this case the result of execution 1 S from is a final state s’ then the next configuration is ' , 2 s S Operational Semantics Page 13 ' , , ; ' , ] [ 2 2 1 1 2 s S s S S s s
  • 10. S comp sos The first step of the condition statement starts with testing b , then branching according to the outcome: [ ] [] ff s b s S s S S b if tt s b s S s S S b if ff sos tt sos
  • 11. = = if else then if if else then if , , ] [ , , ] [ 2 2 1 1 2 1 The first step of the while statement is to “unf old” it one level, that is to rewrite it as a condition. In the next execution step a test is performed and the execution resumes. Note that the ] [ sos while
  • 12. rule breaks the compositional structur e of the semantic (the reason is that the rule defines the semantic in terms of itself), hence structural induction doesn’t work here fine. skip,s S b S; b s S b while sos else ) do while ( then if do while , ] [ Derivation Sequence A derivation sequence of a statement S starting in state s is either: 1. a finite sequence: k
  • 14. • ion configurat stuck or ion configurat terminal a either is k 2. an infinite sequence ,... , , 2 1 0 of configurations satisfying: • s S , 0 = • i i i
  • 15. + 0 1 for More notations: 1. For a terminal or a stuck configuration i we write: i i 0 - indicates that there are i steps in the execution from i to 0 i * 0 - indicates that there is a finite number of steps from i
  • 16. to 0 2. we construct a derivation tree for each step in the sequence (see example below) Examples : 1. () z y y x x z = = = : ; : ; : assuming 5 0 = x s and 7 0 = y s The derivation sequence can be constructed as follows: () []