11\section* {Interpreter Support }
22
33\begin {itemize }
4- \item \lstinline {parse(x)}: \textit {primitive}, returns the parse tree that results from parsing
5- the string \lstinline {x} as a Source program.
64\item \lstinline {apply_in_underlying_javascript(f, xs)}: \textit {primitive}, calls the function \lstinline {f}
75with arguments \lstinline {xs}. For example:
86\ begin{lstlisting}
@@ -11,4 +9,139 @@ \section*{Interpreter Support}
119}
1210apply_in_underlying_javascript(times, list(2, 3)); // returns 6
1311\end {lstlisting }
12+ \item \lstinline {parse(x)}: \textit {primitive}, returns the parse tree that results from parsing
13+ the string \lstinline {x} as a Source program. The following two pages describe the shape of the parse tree.
1414\end {itemize }
15+
16+ \newpage
17+ \KOMAoptions {paper=landscape,pagesize}
18+ \recalctypearea
19+
20+ \begin {alignat* }{9}
21+ && \textit {program } &&\quad ::= &\quad && \textit {statement } \ \ldots
22+ && \texttt {list("sequence", list of <statement>) } \\ [1mm]
23+ && \textit {statement } &&\quad ::= &\quad && \textbf {\texttt {const } }\ \textit {name } \
24+ \textbf {\texttt {= } }\ \textit {expression } \ \textbf {\texttt {; } }
25+ && \texttt {list("constant\_ declaration", <name>, <expression>) } \\
26+ && && | &\quad && \textit {let } \ \textbf {\texttt {; } }
27+ && \textrm {see below}\\
28+ && && | &\quad && \textit {assignment } \ \textbf {\texttt {; } }
29+ && \textrm {see below}\\
30+ && && | &\quad && \textit {expression } \textbf {\texttt {[ } }
31+ \textit {expression } \textbf {\texttt {] } } \
32+ \textbf {\texttt {= } }\ \textit {expression } \ \textbf {\texttt {; } }
33+ && \texttt {list("array\_ assignment", <expression>, <expression>) } \\
34+ && && | &\quad && \textbf {\texttt {function } }\ \textit {name } \
35+ \textbf {\texttt {( } }\ \textit {parameters } \ \textbf {\texttt {) } }\ \textit {block } \quad
36+ && \textrm {treat as}:\ \textbf {\texttt {const } }\ \textit {name } \
37+ \textbf {\texttt {= } }\ \textit {parameters } \ \textbf {\texttt {=> } }\ \textit {block } \textbf {\texttt {; } } \\
38+ && && | &\quad && \textbf {\texttt {return } }\ \textit {expression } \ \textbf {\texttt {; } }
39+ && \texttt {list("return\_ statement", <expression>) } \\
40+ && && | &\quad && \textit {if-statement } \quad
41+ && \textrm {see below}\\
42+ && && | &\quad && \textbf {\texttt {while } }\
43+ \textbf {\texttt {( } }\ \textit {expression } \ \textbf {\texttt {) } } \
44+ \textit {block }
45+ && \texttt {list("while\_ loop", <expression>, <statement>) } \\
46+ && && | &\quad && \textbf {\texttt {for } }\ \textbf {\texttt {( } } \
47+ (\ \textit {\hyperlink {for}{assignment} } \ | \ \textit {\hyperlink {for2}{let} }\ ) \textbf {\texttt {; } } \\
48+ && && &\quad && \ \ \ \ \ \ \ \ \ \ \textit {expression } \ \textbf {\texttt {; } } \\
49+ && && &\quad && \ \ \ \ \ \ \ \ \ \ \textit {assignment } \ \textbf {\texttt {) } } \
50+ \textit {block }
51+ && \texttt {list("for\_ loop", <statement>, <expression>, <statement>, }\\
52+ &&&&&&&&&\ \ \ \ \ \ \texttt { <statement>) } \\
53+ && && | &\quad && \textbf {\texttt {break } }\ \textbf {\texttt {; } }
54+ && \texttt {list("break\_ statement") } \\
55+ && && | &\quad && \textbf {\texttt {continue } }\ \textbf {\texttt {; } }
56+ && \texttt {list("continue\_ statement") } \\
57+ && && | &\quad && \textit {block }
58+ && \textrm {see below}\\
59+ && && | &\quad && \textit {expression } \ \textbf {\texttt {; } }
60+ && \textrm {see below}\\ [1mm]
61+ && \textit {parameters } && ::= &\quad && \epsilon \ | \ \textit {name } \
62+ (\ \textbf {\texttt {, } } \ \textit {name }\ )\ \ldots
63+ && \texttt {list of <name> } \\
64+ && \textit {if-statement } && ::= &\quad && \textbf {\texttt {if } }\
65+ \textbf {\texttt {( } }\ \textit {expression } \ \textbf {\texttt {) } }\
66+ \textit {block } \\
67+ && && & && \textbf {\texttt {else } }\
68+ (\ \textit {block }
69+ \ | \
70+ \textit {\href {https://sicp.comp.nus.edu.sg/chapters/21\#footnote-1}{if-statement} } \ )
71+ && \texttt {list("conditional\_ statement", <expression>, } \\
72+ &&&&&&&&&\ \ \ \ \ \ \texttt {<statement>, <statement>) } \\
73+ && \textit {block } && ::= & && \textbf {\texttt {\{ } }\ \textit {program } \ \textbf {\texttt {\} } } \quad
74+ && \texttt {list("block", <statement>) } \\
75+ && \textit {let } && ::= &\quad && \textbf {\texttt {let } }\ \textit {name } \
76+ \textbf {\texttt {= } }\ \textit {expression }
77+ && \texttt {list("variable\_ declaration", <name>, <expression>) } \\
78+ && \textit {assignment } && ::= &\quad && \textit {name } \
79+ \textbf {\texttt {= } }\ \textit {expression }
80+ && \texttt {list("assignment", <name>, <expression>) } \\
81+ \end {alignat* }
82+
83+ \begin {alignat* }{9}
84+ && \textit {expression } && ::= &\quad && \textit {number } && \textrm {self-evaluating} \\
85+ && && | &\quad && \textbf {\texttt {true } }\ |\ \textbf {\texttt {false } }
86+ && \textrm {self-evaluating} \\
87+ && && | &\quad && \textbf {\texttt {null } }
88+ && \textrm {self-evaluating} \\
89+ && && | &\quad && \textit {string } && \textrm {self-evaluating} \\
90+ && && | &\quad && \textit {name } && \texttt {list("name", string) } \ \textrm {or}\ \texttt {list("name", string, location) } \\
91+ && && | &\quad && \textit {expression } \ \textit {binary-operator } \
92+ \textit {expression } \qquad
93+ && \texttt {list("application", <name>, list of <expression>) } \\
94+ && && | &\quad && \textit {unary-operator } \
95+ \textit {expression }
96+ && \texttt {list("application", <name>, list of <expression>) } \\
97+ && && | &\quad && \textit {expression } \
98+ \textbf {\texttt {( } }\ \textit {expressions }\
99+ \textbf {\texttt {) } }
100+ && \texttt {list("application", <expression>, list of <expression>) } \\
101+ && && | &\quad && (\ \textit {name }\ | \
102+ \textbf {\texttt {( } }\ \textit {parameters }\ \textbf {\texttt {) } }\
103+ )\
104+ \texttt {\textbf {=> } }\ \textit {expression }
105+ && \texttt {list("function\_ definition", <parameters>, } \\
106+ && && & && && \texttt {list("return\_ statement", <expression>)) } \\
107+ && && | &\quad && (\ \textit {name }\ | \
108+ \textbf {\texttt {( } }\ \textit {parameters }\ \textbf {\texttt {) } }\
109+ )\
110+ \texttt {\textbf {=> } }\ \textit {block }
111+ && \texttt {list("function\_ definition", <parameters>, <statement>) } \\
112+ && && | &\quad && \textit {expression } \ \textbf {\texttt {? } }\
113+ \textit {expression }
114+ \ \textbf {\texttt {: } }\
115+ \textit {expression }\
116+ && \texttt {list("conditional\_ expression", <expression>, } \\
117+ &&&&&&&&&\ \ \ \ \ \ \texttt {<expression>, <expression>) } \\
118+ && && | &\quad && \textit {expression } \textbf {\texttt {[ } }
119+ \textit {expression } \textbf {\texttt {] } }
120+ && \texttt {list("array\_ access", <expression>, <expression>) } \\
121+ && && | &\quad && \textbf {\texttt {[ } }\
122+ \textit {expressions }\
123+ \textbf {\texttt {] } }
124+ && \texttt {list("array\_ expression", list of <expression>) } \\
125+ && && | &\quad && \textbf {\texttt {( } }\ \textit {expression } \
126+ \textbf {\texttt {) } } && \textrm {treat as:}\ \textit {expression } \\ [1mm]
127+ && \textit {binary-operator } \
128+ && ::= &\quad && \textbf {\texttt {+ } }\ |\ \textbf {\texttt {- } }\ |\ \textbf {\texttt {* } }\ |\ \textbf {\texttt {/ } }\ |\ \textbf {\texttt {\% } }\ |\
129+ \textbf {\texttt {=== } }\ |\ \textbf {\texttt {!== } }\ \\
130+ && && | &\quad && \texttt {\textbf {> } }\ |\ \texttt {\textbf {< } }\ |\ \texttt {\textbf {>= } }\ |\ \texttt {\textbf {<= } }\
131+ |\ \textbf {\texttt {\&\& } }\ |\ \texttt {\textbf {|| } }
132+ && \texttt {list("name", string) } \\ [1mm]
133+ && \textit {unary-operator }
134+ && ::= &\quad && \textbf {\texttt {! } }\ |\ \textbf {\texttt {- } }
135+ && \texttt {list("name", string) } \\
136+ && \textit {expressions } && ::= &\quad && \epsilon \ | \ \textit {expression }\ (
137+ \ \textbf {\texttt {, } } \
138+ \textit {expression } \
139+ )\ \ldots
140+ && \texttt {list of <expression> } \\
141+ \end {alignat* }
142+
143+
144+
145+ \newpage
146+ \KOMAoptions {paper=portrait,pagesize}
147+ \recalctypearea
0 commit comments