# ln028 - Review Language ONE Lets develop an operational...

This preview shows pages 1–5. Sign up to view the full content.

Review: Language ONE Let’s develop an operational semantics for a simple programming language called ONE ; ONE : < exp >* ::= < exp > + < mulexp > | < mulexp > < mulexp > ::= < mulexp > * < rootexp > | < rootexp > < rootexp > ::= ( < exp > ) | < constant > < constant > ::= all valid integer constants Note: The grammar is unambiguous, both precedence and associativity rules of “standard” arithmetic are observed. Do the following sentences belong to L ( ONE )? Why? Why not? s = 1 + 2 * 3 s = (1 + 2) * 3 s = a + 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Review: Prolog Interpreter for ONE val1(plus(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), Value is XValue + YValue. val1(times(X,Y),Value) :- val1(X,XValue), val1(Y,YValue), Value is XValue * YValue. val1(const(X),X). A simple interpreter that computes a semantic value for syntactic constructs, the computation of this semantic value can be interpreted as the behavior: val1 / 2, AST input and semantic value as output.
Problems What is the value of a constant? Interpreter says val1(const(X),X). This means that the value of a constant in Language One is whatever the value of that same constant is in Prolog Unfortunately, different implementations of Prolog handle this differently

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
?-
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern