Theory of Programming Languages: Small step semantics of divide by 0 error

Computer Science
Price: $20 USD

Question description

Relevant files:

IMP_syntax.png smallStepSemantics_p1.png smallStepSemantics_p2.png 




Exercise 1: Modify the IMP semantics we discussed in class -- both big-step and small-step -- to properly handle division by 0. If you encounter a division by 0, the program should stop, yielding a configuration with the state (e.g., the mapping of names to values) current at the time of the division by 0 operation. Remember, we discussed this in class. You can take your inspiration from the solution to the die construct that we discussed.


Ok, so I get stuck at a certain point.  I know that I need to add "die;" to the IMP syntax, in the Stmt section, that is: 

Stmt ::= die; | Block | Id = AExp |  ... // rest of Stmt definition as given in IMP_syntax.png file

We also need to make the relation ternary, to add a place holder for the programs status, a value from the set {live, die}, with live meaning "keep going like normal" and "die" meaning "end computation and return the state sigma at the time when the division by 0 occurred."  Where I get stuck is specifying the semantics.

Certain statements won't be affected.  Like SmallStep-Lookup in p1 of smallStepSemantics shouldn't.  But I think we'll need new rules with the "live".  In fact I think I first need a new data type, like "HealthState ::= {living, dead}" in the IMP_syntax file, but I'm not sure.  Then I think you'd have 

<x, sigma, living> -> <sigma(x), sigma, living>      (SmallStep-Lookup, living)

<x, sigma, dead> -> <sigma(x), sigma, dead>      (SmallStep-Lookup, dead)

to account for both possibilities, but neither changes state since a div by 0 can't occur just from looking up a variables value in the memory store.  I'm not sure though, even about that simple example.  And I'm really not sure about the one's where div by 0 is relevant, like any arithmetic expression.  Like in the next one in smallStepSemantics_p1, (SmallStep-Add-Arg1).   And of course (SmallStep-Div) would need to be changed.   

Any help is appreciated.

Right now I only have $10 in my account, but if you think you could do this and need more, just let me know and I'll add it if I can't find anyone at $10.  

Thank you

Tutor Answer

(Top Tutor) Daniel C.
School: UC Berkeley
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1829 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors