Drill 4 Solutions
- 
Which of the following are valid expressions in the language as it stands after the most recent lecture?
-  
(add1 4) -  
(zero? not) -  
(if (num? 4) (add1 4) true) -  
(+ 4 7) -  
(+ false true) -  
(let ((x 4)) (+ x 7)) -  
(left (let ((x (pair 1 2))) (pair x 3))) -  
(left (right (pair (pair 1 2) 3))) 
 -  
 - 
Say you're developing an AST for a simple subset of HTML, as below: you have nested tags (like html, title, div, etc.) and text. Which of these might you have as constructors for your AST type?
<html> <head> <title>Page title</title> </head> <body> <div> <p>This is text</p> <strong>This is bolded text</strong> <em>This is italicized text</em> </div> </body> </html>
 
- Text
 - Word
 - Tag
 - CloseTag
 - LAngleBracket
 - ForwardSlash
 
- 
Does the current compiler ever put the address of a memory location on the stack into a register?
- No.
 
 - 
Write the assembly instruction that puts the value at stack index -8 into rax. (Your answer should start with
mov.)mov rax, [rsp + -8]
 - 
What is the main advantage of using Abstract Syntax Trees (ASTs) over working directly with s-expressions?
- ASTs are faster to process
 - ASTs only represent syntactically valid programs
 - ASTs use less memory
 - ASTs are easier to read