Mark Masulis Andre Domingo Raymond Lin
E1 --> E2 + T E1.val := sum(E2.val, T.val) E1 --> E2 - T E1.val := difference(E2.val, T.val) E --> T E.val := T.val
F --> float F.val := float.val F1 --> -F2 F1.val := inverse(F2.val)
T1 --> T2 * F T1.val := product(T2.val, F.val) T --> F T.val := F.val(Edited: 2021-12-06)
Nicholas Semaan and Yuanye Yang 8. Differentiate applicative versus normal order evaluation. Give an example using Scheme. Give an example of defining a new macro in Scheme. Applicative order evaluates subexpressions when, i.e. just before, the procedure is applied. Normal order passes subexpressions as they are, without evaluation, and proceeds with the evaluation only when the corresponding formal parameter is actually to be itself evaluated. Example: def double x = (plus x x) def average x y = (divide (plus x y) 2) Normal: (double (average 2 4)) => (plus (average 2 4) (average 2 4)) => (plus (divide (plus 2 4) 2) (average 2 4)) => (plus (divide 6 2) (average 2 4)) => (plus 3 (average 2 4)) => (plus 3 (divide (plus 2 4) 2)) => (plus 3 (divide 6 2)) => (plus 3 3) => 6 Applicative: double (average 2 4) => double (divide (plus 2 4) 2) => double (divide 6 2) => double 3 => plus 3 3 => 6 Macro Example: If your Scheme lacks the conditional special form when, you could define when as the following macro: (define-syntax when (lambda (test . branch) (list 'if test (cons 'begin branch))))(Edited: 2021-12-06)
lambda(y)( (set! x (+ x y)))
)) (define add1 (add 2)) (add1 5)
count++;}
int count = 0; increment(count); printf("%d", count);}
begin n: n+1 k: k+4 print(n) end
n = 0 p(n) print(n) end
return 2;} function testReturns(){
for($i = 0; $i < 100; $i++){ for($j = 0; $j < 20; $j++){ if($j == 20){ echo "Return 1 at "; echo $j; echo "\n"; return 1; } if($i == 50){ echo "Return 2 at "; echo $i; echo "\n"; two_return(); } } }}
Scheme Continuations: Use the function call-with continuation or call/cc to set a single parameter procedure to receive and manipulate an environment. After call/cc, the procedure is run in the supplied environment and once call/cc completes the execution resumes.
Team Members: Angela Pham, Jesse Dong, Ian Chavez, Arun Murugan 10. square_sum_up(1,1) :-!. square_sum_up(N,X) :- N1 is N-1, square_sum_up(N1,X1), X is X1+(N * N). diff_sum(LO,HI,X) :- LO1 is LO-1, square_sum_up(LO1,X1), square_sum_up(HI,X2), X is X2-X1.(Edited: 2021-12-06)
Question 2: Jason Hammar Leo Alciso Edward Phan
Attribute grammars are a framework for defining semantics of programming languages in a syntax-directed fashion.
S-attributed Grammars are grammars where the left-hand side consists of a non-terminal that is dependent on the attribute of a non-terminal on the right-hand side. Example: A->B > A.Val = B.Val L-attributed Grammars are grammars that have a non-terminal on the right-hand side which has its value depend on another attribute on the right hand side of the same production rule. Example: A->BC > B.Val = C.Val
A side effect is something a programming language has where it influences subsequent computation in any way other than by returning a value for use in the surrounding context. i.e. In some languages, making a variable on the global scope may affect the return value of the function.(Edited: 2021-12-06)