1. Homepage
  2. Programming
  3. CS320 Concepts of Programming Languages Fall2023 - Project Part 1

CS320 Concepts of Programming Languages Fall2023 - Project Part 1

Engage in a Conversation
BostonBUConcepts of Programming LanguagesFunctional ProgrammingOCaml

CS320 Fall2023 Project Part 1 CourseNana.COM

November 2023 CourseNana.COM

1 Overview CourseNana.COM

Stack-oriented programming languages utilize one or more stack data structures which the programmer manipulates CourseNana.COM

to perform computations. The specification below lays out the syntax and semantics of such a language CourseNana.COM

which you will need to implement an evaluator for, taking a program and evaluating it into an OCaml value. CourseNana.COM

You must implement a function: CourseNana.COM

interp : string -> string list option CourseNana.COM

Where the input string is some (possibly ill-formed) stack-language program and the result is a list of things CourseNana.COM

“printed” by the program during its evaluation. CourseNana.COM

1 CourseNana.COM

2 Grammar CourseNana.COM

For part 1, you will need to support the following grammar. The grammar specifies the form of a valid program. CourseNana.COM

Any invalid program, one which is not derivable from the grammar, cannot be given meaning and evaluted. In CourseNana.COM

the case of an invalid program, interp should return None. ⟨prog⟩ is the starting symbol. CourseNana.COM

2.1 Constants CourseNana.COM

⟨digit⟩ ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 CourseNana.COM

⟨nat⟩ ::= ⟨digit⟩ | ⟨digit⟩⟨nat⟩ CourseNana.COM

⟨int⟩ ::= ⟨nat⟩ | -⟨nat⟩ CourseNana.COM

⟨bool⟩ ::= True | False CourseNana.COM

⟨const⟩ ::= ⟨int⟩ | ⟨bool⟩ | Unit CourseNana.COM

2.2 Programs CourseNana.COM

⟨prog⟩ ::= ⟨coms⟩ CourseNana.COM

⟨com⟩ ::= Push ⟨const⟩ | Pop | Trace CourseNana.COM

| Add | Sub | Mul | Div CourseNana.COM

| And | Or | Not CourseNana.COM

| Lt | Gt CourseNana.COM

⟨coms⟩ ::= ϵ | ⟨com⟩; ⟨coms⟩ CourseNana.COM

Note: ϵ is the empty symbol. We use ϵ to refer to empty strings or empty lists depending on context. CourseNana.COM

2 CourseNana.COM

3 Operational Semantics CourseNana.COM

For part 1, you will need to support the following operational semantics. The operational semantics specifies CourseNana.COM

the meaning of a valid program. For the stack-language, a program is evaluated using a stack and it produces CourseNana.COM

a trace. Once we have fully evaluated the program, we return the resulting trace from interp. CourseNana.COM

3.1 Configuration of Programs CourseNana.COM

A program configuration is of the following form. CourseNana.COM

[ S | T ] P CourseNana.COM

• S: (Stack) stack of intermediate values CourseNana.COM

• T: (Trace) list of strings logging the program trace CourseNana.COM

• P: (Program) program commands to be interpreted CourseNana.COM

Examples: CourseNana.COM

[ ϵ | ϵ ] Push True; Not; Push 1; Lt; ϵ (1) CourseNana.COM

[ 1 :: 2 :: ϵ | "True" :: "0" :: ϵ ] Push True; Push 9; Pop; ϵ (2) CourseNana.COM

[ 0 :: True :: ϵ | ϵ ] Push 10; Push 9; Add; Trace; ϵ (3) CourseNana.COM

[ True :: False :: 321 :: ϵ | "123" :: "False" :: ϵ ] Pop; Pop; Trace; Gt; ϵ (4) CourseNana.COM

3.2 Program Reduction CourseNana.COM

The operational semantics of the language is defined in terms of the following single step relation. CourseNana.COM

[ S1 | T1 ] P1 ⇝ [ S2 | T2 ] P2 CourseNana.COM

In one step, program configuration [ S1 | T1 ] P1 evaluates to [ S2 | T2 ] P2. For configurations where P = ϵ, we CourseNana.COM

say that evaluation has terminated as there is no program left to interpret. In this case, return trace T as the CourseNana.COM

final result of your interp function. CourseNana.COM

3.3 Push CourseNana.COM

Given any constant c, the command Push c pushes c onto the current stack S. Push never fails. CourseNana.COM

Push CourseNana.COM

[ S | T ] Push c; P ⇝ [ c :: S | T ] P CourseNana.COM

Examples: CourseNana.COM

• [ 1 :: True :: ϵ | "Unit" :: "False" :: ϵ ] Push 2; ϵ ⇝ [ 2 :: 1 :: True :: ϵ | "Unit" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ 1 :: True :: ϵ | "5" :: ϵ ] Push True; ϵ ⇝ [ True :: 1 :: True :: ϵ | "5" :: ϵ ] ϵ CourseNana.COM

3 CourseNana.COM

3.4 Pop CourseNana.COM

Given a stack of the form c :: S (constant c is on top of S), the Pop command removes c and leaves the rest of CourseNana.COM

stack S unmodified. CourseNana.COM

The Pop command has 1 fail state. CourseNana.COM

1. PopError: The stack is empty (S = ϵ). CourseNana.COM

When Pop fails, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

PopStack CourseNana.COM

[ c :: S | T ] Pop; P ⇝ [ S | T ] P CourseNana.COM

PopError CourseNana.COM

[ ϵ | T ] Pop; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ 1 :: True :: ϵ | "Unit" :: "False" :: ϵ ] Pop; ϵ ⇝ [ True :: ϵ | "Unit" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ ϵ | "5" :: ϵ ] Pop; Push 12; ϵ ⇝ [ ϵ | "Panic" :: "5" :: ϵ ] ϵ CourseNana.COM

3.5 Trace CourseNana.COM

Given a stack of the form c :: S where c is any valid constant, the Trace command removes c from the stack CourseNana.COM

and puts a Unit constant onto the stack. The string representation of c as determined by the toString function CourseNana.COM

to prepended to the trace. CourseNana.COM

The Trace command has 1 fail state. CourseNana.COM

1. TraceError: The stack is empty (S = ϵ). CourseNana.COM

When Trace fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

TraceStack CourseNana.COM

[ c :: S | T ] Trace; P ⇝ [ Unit :: S | toString(c) :: T ] P CourseNana.COM

TraceError CourseNana.COM

[ ϵ | T ] Trace; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

The toString function is a special function which you must define to convert constant values into their string CourseNana.COM

representations. The following equations illustrate the strings expected for typical inputs. CourseNana.COM

toString(123) = "123" (1) CourseNana.COM

toString(True) = "True" (2) CourseNana.COM

toString(False) = "False" (3) CourseNana.COM

toString(Unit) = "Unit" (4) CourseNana.COM

Examples: CourseNana.COM

• [ 1 :: True :: ϵ | "Unit" :: "False" :: ϵ ] Trace; ϵ ⇝ [ Unit :: True :: ϵ | "1" :: "Unit" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ ϵ | "5" :: ϵ ] Trace; Push 12; ϵ ⇝ [ ϵ | "Panic" :: "5" :: ϵ ] ϵ CourseNana.COM

4 CourseNana.COM

3.6 Add CourseNana.COM

Given a stack of the form i :: j :: S where both i and j are integer values, the Add command removes i and j CourseNana.COM

from the stack and puts their sum (i + j) onto the stack. CourseNana.COM

The Add command has 3 fail states. CourseNana.COM

1. AddError1: Either i or j is not an integer. CourseNana.COM

2. AddError2: The stack is empty (S = ϵ). CourseNana.COM

3. AddError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When Add fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

AddStack CourseNana.COM

i and j are both integers CourseNana.COM

[ i :: j :: S | T ] Add; P ⇝ [ (i + j) :: S | T ] P CourseNana.COM

AddError1 CourseNana.COM

i or j is not an integer CourseNana.COM

[ i :: j :: S | T ] Add; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

AddError2 CourseNana.COM

[ ϵ | T ] Add; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

AddError3 CourseNana.COM

[ c :: ϵ | T ] Add; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ 4 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Add; ϵ ⇝ [ 9 :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: True :: Unit :: ϵ | "False" :: ϵ ] Add; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: ϵ | "False" :: ϵ ] Add; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

3.7 Sub CourseNana.COM

Given a stack of the form i :: j :: S where both i and j are integer values, the Sub command removes i and j CourseNana.COM

from the stack and puts their difference (i − j) onto the stack. CourseNana.COM

The Sub command has 3 fail states. CourseNana.COM

1. SubError1: Either i or j is not an integer. CourseNana.COM

2. SubError2: The stack is empty (S = ϵ). CourseNana.COM

3. SubError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When Sub fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

SubStack CourseNana.COM

i and j are both integers CourseNana.COM

[ i :: j :: S | T ] Sub; P ⇝ [ (i − j) :: S | T ] P CourseNana.COM

SubError1 CourseNana.COM

i or j is not an integer CourseNana.COM

[ i :: j :: S | T ] Sub; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

SubError2 CourseNana.COM

[ ϵ | T ] Sub; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

SubError3 CourseNana.COM

[ c :: ϵ | T ] Sub; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ 4 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Sub; ϵ ⇝ [−1 :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: True :: Unit :: ϵ | "False" :: ϵ ] Sub; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: ϵ | "False" :: ϵ ] Sub; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

5 CourseNana.COM

3.8 Mul CourseNana.COM

Given a stack of the form i :: j :: S where both i and j are integer values, the Mul command removes i and j CourseNana.COM

from the stack and puts their product (i °ø j) onto the stack. CourseNana.COM

The Mul command has 3 fail states. CourseNana.COM

• MulError1: Either i or j is not an integer. CourseNana.COM

• MulError2: The stack is empty (S = ϵ). CourseNana.COM

• MulError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When Mul fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

MulStack CourseNana.COM

i and j are both integers CourseNana.COM

[ i :: j :: S | T ] Mul; P ⇝ [ (i °ø j) :: S | T ] P CourseNana.COM

MulError1 CourseNana.COM

i or j is not an integer CourseNana.COM

[ i :: j :: S | T ] Mul; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

MulError2 CourseNana.COM

[ ϵ | T ] Mul; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

MulError3 CourseNana.COM

[ c :: ϵ | T ] Mul; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ 4 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Mul; ϵ ⇝ [ 20 :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: True :: Unit :: ϵ | "False" :: ϵ ] Mul; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: ϵ | "False" :: ϵ ] Mul; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

6 CourseNana.COM

3.9 Div CourseNana.COM

Given a stack of the form i :: j :: S where both i and j are integer values, the Div command removes i and j CourseNana.COM

from the stack and puts their quotient (i °¿ j) onto the stack. CourseNana.COM

The Div command has 4 fail states. CourseNana.COM

1. DivError0: Both i and j are integers and j = 0. CourseNana.COM

2. DivError1: Either i or j is not an integer. CourseNana.COM

3. DivError2: The stack is empty (S = ϵ). CourseNana.COM

4. DivError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When Div fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

DivStack CourseNana.COM

i and j are both integers, j ̸= 0 CourseNana.COM

[ i :: j :: S | T ] Div; P ⇝ [ (i °¿ j) :: S | T ] P CourseNana.COM

DivError0 CourseNana.COM

i is an integer CourseNana.COM

[ i :: 0 :: S | T ] Div; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

DivError1 CourseNana.COM

i or j is not an integer CourseNana.COM

[ i :: j :: S | T ] Div; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

DivError2 CourseNana.COM

[ ϵ | T ] Div; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

DivError3 CourseNana.COM

[ c :: ϵ | T ] Div; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ 16 :: 8 :: True :: Unit :: ϵ | "False" :: ϵ ] Div; ϵ ⇝ [ 2 :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 16 :: 0 :: True :: Unit :: ϵ | "False" :: ϵ ] Div; Push Unit; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ 16 :: True :: Unit :: ϵ | "False" :: ϵ ] Div; Add; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: ϵ | "False" :: ϵ ] Div; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

7 CourseNana.COM

3.10 And CourseNana.COM

Given a stack of the form a :: b :: S where both a and b are boolean values, the And command removes a and b CourseNana.COM

from the stack and puts their conjunction (a ∧ b) onto the stack. CourseNana.COM

The And command has 3 fail states. CourseNana.COM

1. AndError1: Either a or b is not a boolean. CourseNana.COM

2. AndError2: The stack is empty (S = ϵ). CourseNana.COM

3. AndError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When And fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

AndStack CourseNana.COM

a and b are both booleans CourseNana.COM

[ a :: b :: S | T ] And; P ⇝ [ (a ∧ b) :: S | T ] P CourseNana.COM

AndError1 CourseNana.COM

a or b is not a boolean CourseNana.COM

[ a :: b :: S | T ] And; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

AndError2 CourseNana.COM

[ ϵ | T ] And; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

AndError3 CourseNana.COM

[ c :: ϵ | T ] And; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ True :: True :: Unit :: ϵ | "False" :: ϵ ] And; ϵ ⇝ [ True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ False :: True :: Unit :: ϵ | "False" :: ϵ ] And; Trace; ϵ ⇝ [ False :: Unit :: ϵ | "False" :: ϵ ] Trace; ϵ CourseNana.COM

• [ True :: 4 :: Unit :: ϵ | "False" :: ϵ ] And; Pop; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

3.11 Or CourseNana.COM

Given a stack of the form a :: b :: S where both a and b are boolean values, the Or command removes a and b CourseNana.COM

from the stack and puts their disjunction (a ∨ b) onto the stack. CourseNana.COM

The Or command has 3 fail states. CourseNana.COM

1. OrError1: Either a or b is not a boolean. CourseNana.COM

2. OrError2: The stack is empty (S = ϵ). CourseNana.COM

3. OrError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When Or fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

OrStack CourseNana.COM

a and b are both booleans CourseNana.COM

[ a :: b :: S | T ] Or; P ⇝ [ (a ∨ b) :: S | T ] P CourseNana.COM

OrError1 CourseNana.COM

a or b is not a boolean CourseNana.COM

[ a :: b :: S | T ] Or; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

OrError2 CourseNana.COM

[ ϵ | T ] Or; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

OrError3 CourseNana.COM

[ c :: ϵ | T ] Or; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ True :: True :: Unit :: ϵ | "False" :: ϵ ] Or; ϵ ⇝ [ True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ False :: True :: Unit :: ϵ | "False" :: ϵ ] Or; Trace; ϵ ⇝ [ True :: Unit :: ϵ | "False" :: ϵ ] Trace; ϵ CourseNana.COM

• [ True :: 4 :: Unit :: ϵ | "False" :: ϵ ] Or; Pop; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

8 CourseNana.COM

3.12 Not CourseNana.COM

Given a stack of the form a :: S where a is a boolean values, the Not command removes a from the stack and CourseNana.COM

puts its negation (°˛a) onto the stack. CourseNana.COM

The Not command has 2 fail states. CourseNana.COM

1. NotError1: a is not a boolean. CourseNana.COM

2. NotError2: The stack is empty (S = ϵ). CourseNana.COM

When Not fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

NotStack CourseNana.COM

a is a boolean CourseNana.COM

[ a :: S | T ] Not; P ⇝ [ (°˛a) :: S | T ] P CourseNana.COM

NotError1 CourseNana.COM

a is not a boolean CourseNana.COM

[ a :: S | T ] Not; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

NotError2 CourseNana.COM

[ ϵ | T ] Not; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ True :: Unit :: ϵ | "False" :: ϵ ] Not; ϵ ⇝ [ False :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: Unit :: ϵ | "False" :: ϵ ] Not; Pop; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

• [ ϵ | "False" :: ϵ ] Not; Add; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

3.13 Lt CourseNana.COM

Given a stack of the form i :: j :: S where both i and j are integer values, the Lt command removes i and j CourseNana.COM

from the stack and puts the boolean result of their comparison (i < j) onto the stack. CourseNana.COM

The Lt command has 3 fail states. CourseNana.COM

1. LtError1: Either i or j is not an integer. CourseNana.COM

2. LtError2: The stack is empty (S = ϵ). CourseNana.COM

3. LtError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When Lt fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

LtStack CourseNana.COM

i and j are both integers CourseNana.COM

[ i :: j :: S | T ] Lt; P ⇝ [ (i < j) :: S | T ] P CourseNana.COM

LtError1 CourseNana.COM

i or j is not an integer CourseNana.COM

[ i :: j :: S | T ] Lt; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

LtError2 CourseNana.COM

[ ϵ | T ] Lt; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

LtError3 CourseNana.COM

[ c :: ϵ | T ] Lt; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ 4 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Lt; ϵ ⇝ [ True :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 5 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Lt; ϵ ⇝ [ False :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: True :: Unit :: ϵ | "False" :: ϵ ] Lt; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

9 CourseNana.COM

3.14 Gt CourseNana.COM

Given a stack of the form i :: j :: S where both i and j are integer values, the Gt command removes i and j CourseNana.COM

from the stack and puts the boolean result of their comparison (i > j) onto the stack. CourseNana.COM

The Gt command has 3 fail states. CourseNana.COM

1. GtError1: Either i or j is not an integer. CourseNana.COM

2. GtError2: The stack is empty (S = ϵ). CourseNana.COM

3. GtError3: The stack has only 1 element (S = c :: ϵ). CourseNana.COM

When Gt fails, the stack is cleared, the string "Panic" is prepended to the trace and the program terminates. CourseNana.COM

GtStack CourseNana.COM

i and j are both integers CourseNana.COM

[ i :: j :: S | T ] Gt; P ⇝ [ (i > j) :: S | T ] P CourseNana.COM

GtError1 CourseNana.COM

i or j is not an integer CourseNana.COM

[ i :: j :: S | T ] Gt; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

GtError2 CourseNana.COM

[ ϵ | T ] Gt; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

GtError3 CourseNana.COM

[ c :: ϵ | T ] Gt; P ⇝ [ ϵ | "Panic" :: T ] ϵ CourseNana.COM

Examples: CourseNana.COM

• [ 4 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Gt; ϵ ⇝ [ False :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 10 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Gt; ϵ ⇝ [ True :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 5 :: 5 :: True :: Unit :: ϵ | "False" :: ϵ ] Gt; ϵ ⇝ [ False :: True :: Unit :: ϵ | "False" :: ϵ ] ϵ CourseNana.COM

• [ 4 :: True :: Unit :: ϵ | "False" :: ϵ ] Gt; Trace; ϵ ⇝ [ ϵ | "Panic" :: "False" :: ϵ ] ϵ CourseNana.COM

10 CourseNana.COM

4 Full Examples CourseNana.COM

• Compute the polynomial x2 − 4x + 7 at 3: CourseNana.COM

Push 3; CourseNana.COM

Push 3; CourseNana.COM

Mul; CourseNana.COM

Push -4; CourseNana.COM

Push 3; CourseNana.COM

Mul; CourseNana.COM

Add; CourseNana.COM

Push 7; CourseNana.COM

Add; CourseNana.COM

Trace; CourseNana.COM

Result: Some ["4"] CourseNana.COM

• De Morgan’s Law: CourseNana.COM

Push False; CourseNana.COM

Push False; CourseNana.COM

And; CourseNana.COM

Not; CourseNana.COM

Trace; CourseNana.COM

Push False; CourseNana.COM

Not; CourseNana.COM

Push False; CourseNana.COM

Not; CourseNana.COM

Or; CourseNana.COM

Trace; CourseNana.COM

Result: Some ["True"; "True"] CourseNana.COM

• x2 is monotonic: CourseNana.COM

Push 2; CourseNana.COM

Push 2; CourseNana.COM

Mul; CourseNana.COM

Push 3; CourseNana.COM

Push 3; CourseNana.COM

Mul; CourseNana.COM

Gt; CourseNana.COM

Trace; CourseNana.COM

Result: Some ["True"] CourseNana.COM

11 CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Boston代写,BU代写,Concepts of Programming Languages代写,Functional Programming代写,OCaml代写,Boston代编,BU代编,Concepts of Programming Languages代编,Functional Programming代编,OCaml代编,Boston代考,BU代考,Concepts of Programming Languages代考,Functional Programming代考,OCaml代考,Bostonhelp,BUhelp,Concepts of Programming Languageshelp,Functional Programminghelp,OCamlhelp,Boston作业代写,BU作业代写,Concepts of Programming Languages作业代写,Functional Programming作业代写,OCaml作业代写,Boston编程代写,BU编程代写,Concepts of Programming Languages编程代写,Functional Programming编程代写,OCaml编程代写,Bostonprogramming help,BUprogramming help,Concepts of Programming Languagesprogramming help,Functional Programmingprogramming help,OCamlprogramming help,Bostonassignment help,BUassignment help,Concepts of Programming Languagesassignment help,Functional Programmingassignment help,OCamlassignment help,Bostonsolution,BUsolution,Concepts of Programming Languagessolution,Functional Programmingsolution,OCamlsolution,