Description
Submit hardcopy solutions for each of the problems. Where code is required, make sure the code is embedded within your document, but also provide links to the code that you have saved on ideone or codepad. 1. Give an abstract syntax tree for the following C expression:
a 3 m 4 ~ 6 y 6 p
2. JavaScript’s implicit semicolon insertion is often considered to be poorly designed because the following four cases aren’t exactly intuitive:
:
8 a 4 .toString16
place mundo Hola Ciao.orach command alertcommand place
sayHello alertHello
alertoodye
What is being illustrated in each of the above? Go, Python, Scala, and Ruby all allow line endings to end statements and you don’t hear people complaining about them the way they do about JavaScript. Pick one of these four languages and show why they handle the four “problematic” cases of JavaScript.
3. Give an example of a program in C that would not work correctly if o re were allocated in static storage as opposed to the stack. For the purposes of this question, local variables do not include parameters.
4. Consider the following pseudocode:
100 setn n
1/30/2014 CMSI 386: Programming Languages: Homework #4
http://cs.lmu.edu/~ray/classes/pl/assignment/4/ 2/2
print console.log irst set1 print second set2 print set0 irst print second print
What does this program print if the language uses static scoping? What does it print with dynamic scoping? Why?
5. The expression a–f(b)–c*d can produce different values depending on how a compiler decides to order, or even parallelize operations. Give a small program in the language of your choice (or even one of your own design) that would produce different values for this expression for different evaluation orders. Please note that by “different evaluation orders” we do not mean that the compiler can violate the precedence and associativity rules of the language.
6. Explain the meaning of the following C declarations:
an n cn dn
7. Rewrite the four declarations in the previous problem in Go. Yes, I did say Go.
8. Translate the following expression into (a) postfix and (b) prefix notation, in both cases without using parentheses:
srt4 a c / 2 a
Do you need a special symbol for unary negation? Why or why not?
9. Write the interleave function from the previous three assignments in C++, using C-style arrays.
10. Write the interleave function from the previous three assignments in C++, using C++ eor (from the Standard Library).