Question: # | We will define the syntax and semantics for SAEL, the Simple Arithmetic Expression Language. SAEL is our object language. The metalanguage we (
#
We will define the syntax and semantics for SAEL, the Simple
Arithmetic Expression Language. SAEL is our object language. The
metalanguage we well you will use to define SAEL is ACLs The
metametalanguage we well us Ferdinand & Olin, in this
assignment use to discuss all of this is Mathematical English.
Here's a "Fundies style data definition.
A simple arithmetic expression, saexpr, is one of the following:
a rational number we use the builtin ACLs type rational
a variable we use the builtin ACLs type var
a unary expression, which is a list of the form
; Negation
; Reciprocal
where is an arithmetic expression
a binary expression, which is a list of the form
where is one of or
and both s are simple arithmetic expressions.
#
; It really isn't important to know the exact definition of varp,
; although you can query ACLs with :pe varp". Just notice that none
; of the operators are vars, but symbols such as x y z etc are
; vars.
checkvarp nil
checkvarp nil
checkvarp nil
checkvarp nil
checkvarp nil
check varp x
;; Q
;; Use defdata to define the unary operators. Fill in the XXXs
;; below. If you have questions, ask on Piazza.
defdata uoper enum XXX
;; Q
;; Use defdata to define boper the binary operators
defdata boper enum XXX
check boperp
check boperp
checkboperp nil
;; Q
;; Use defdata to define saexpr. We will want names for all the
;; subtypes, so use the following template. Note that data definitions
;; can be mutually recursive.
defdata
saexpr or rational ; or is the same as oneof
var
usaexpr ; unary sael expression
bsaexpr ; binary sael expression
usaexpr XXX
bsaexpr XXX
;; We now have a formal definition of the SAEL language! That is we
;; have a recognizer saexprp, which is defined in our metalanguage,
;; ACLs and which recognizes expressions in the object language,
;; SAEL. We formalized the syntax of SAEL expressions! Notice that
;; defdata made this very easy to do
;; In short, a SAEL expression can now be represented as a
;; piece of ACL data, so we can operate on one with ACL code.
check saexprp x y z
checksaexprp x y z nil
;; We are now going to define the semantics of SAEL expressions.
;; First, some helper definitions.
;; An assignment is an alist from vars to rationals.
;; An alist is just a list of conses.
;; In the RAP notes, the term "valuation" is also used instead of assignment.
defdata assignment alistof var rational
check assignmentp x y
;; This is nil because are not rationals.
checkassignmentp x y nil
;; Now, on to the semantics.
;; How do we assign semantics to SAEL expressions such as
;; x y
;; We will define saeval below a function that given an saexpr and
;; an assignment evaluates the expression, using the assignment to
;; specify the values of var's.
;; If a var appears in the saexpr but is not in the assignment, then
;; the value of the var should be
;; Q
;; Use the following helper function to lookup the value of v in a
;; Remember return if v isn't in a
definec lookup v :var a :assignment :rational
XXX
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
