|
CS 3723
Programming Languages
Spring 2014 |
Questions and Corrections,
with Responses
|
Please direct questions or corrections or comments to the following
email address,
where δοτ is a "dot" and
ατ is an "at-sign":
<nealδοτwagnerατgmailδοτcom>
I will often post technical questions and my answers to this page,
after stripping off any personal matters or identifying portions.
The questions may be edited to improve them.
Please do NOT use the email address reserved for submissions
(the one with "extra" embedded inside)
in order to ask questions.
- Question (Sun Feb 16 20:48:00 CST 2014):
I have a question regarding the function G() which is supposed to
generate the MIPS instructions to get the Input .
The recitation has the following sample for the input:
p = 3 + (1/7);
> r;
v = (4/3)*p*r*r*r;
< p; < N;
< r; < N;
< v; < N;
$
Could you please let me know what would be the MIPS instructions
for reading an input at Runtime and assigning it to a variable.
These would be the instructions that the G() function of the compiler
should generate.
Answer:
The "Euler series" example, with a link on the calendar page,
shows how to write MIPS code to read a double:
Euler Series.
Here, the Tiny statement: "> m; " is translated to the following MIPS:
# Read M[22] as double
li $v0, 7
syscall
s.d $f0, 176($s1)
This is the same for all reads, except for the "176", which is specific
for the "m" in the tiny statement. This should be directly translated
to the address "176($S1)" where the variable m should reside.
- Question (Mon Feb 17 08:53:37 CST 2014):
Recitation 5 refers once to "Recitation 6". Also there is a
reference to a non-terminal U and to a parsing function
U().
Answer: Sorry, there were several misprints in
Recitation 5. I hope they're all gone now.
- Correction (Thu Feb 20 15:49:13 CST 2014): This is based on
questions from two students in the recitation session: they were having
trouble with the grammar for
Recitation 6:
Old Grammar for Tiny®
language |
M −−> L '$'
L −−> S { S }
S −−> I | W | A | P | G
I −−> '[' E '?' L ':' L ']' | '[' E '?' L ']'
W −−> '{' E '?' L '}'
A −−> lower-case '=' E ';'
P −−> '<' E ';' | '<' ('B' | 'N' | 'T') ';'
G −−> '>' lower-case ';'
E −−> T {('+' | '-') T}
T −−> F {('*' | '/') F}
F −−> '(' E ')' | lower-case | digit
|
Their problem was with the grammar rule:
L −−> S { S }
This works for a short way to describe the language,
but using it makes the R-D parser
somewhat more difficult.
For simplicity, I would get rid of L, and put in
S { S } wherever L appeared, to get the following grammar:
New Grammar for Tiny®
language |
M −−> S { S } '$'
S −−> I | W | A | P | G
I −−> '[' E '?' S { S } ':' S { S } ']' | '[' E '?' S { S } ']'
W −−> '{' E '?' S { S } '}'
A −−> lower-case '=' E ';'
P −−> '<' E ';' | '<' ('B' | 'N' | 'T') ';'
G −−> '>' lower-case ';'
E −−> T {('+' | '-') T}
T −−> F {('*' | '/') F}
F −−> '(' E ')' | lower-case | digit
|
To write the parser, wherever S { S } appears (which means
there is a sequence of one or more statements), keep calling
S( ) until next has the proper value to terminate
the sequence of calls:
- Inside M( ) call S( ) until next == '$'
- Inside W( ) call S( ) until next == '}'
- Inside I( ) call S( ) until next == ':'
or next == ']'
Notice that each call to S( ) should end with finding
one of ';', ']', or '}' in the next variable. After scanning
past that character, return from S( ).
Then call S( ) again unless you find the proper one
of the four characters above.
(It is possible to use the rule L above:
Inside L keep calling S as long as the
character in next is the start of a statement,
namely, a lower-case letter, or one of '<'. '>', '[', or '{'.)
Revision date: 2014-02-20.
(Please use ISO
8601, the International Standard.)
|