I have placed a copy of JFlex 1.8.2 in the MultiLab machines here:
There is documentation nearby:
You may use it instead of 1.6.1, but please fix your Makefile
accordingly and document this substitution. I have tried it and it
seems to work.
Must identifiers be separated by whitespace? For example, if I have
some identifier with an illegal character, such as iden%tifier,
should my scanner read that as two identifiers (iden
and tifier) and an
invalid character, or should it throw the whole thing out as an invalid
That's two identifiers separated by an invalid character. After all,
a+b is perfectly valid.
The document defines a multi-line comment as beginning with ##, but
the example begins with @@. Which is correct?
Sorry for the inconsistency. I intend multi-line comments to start with
@@ and end with @@.
I have fixed the document.
Are we responsible for errors in our generated Yylex.java? Mine is
prompting me with 4 warnings concerning fall-through. The bizarre
thing to me is that Yylex.java seems to include many instances of
"intentional" fall-through that don't seem to cause warnings, and I'm
not sure why these 4 instances in particular do so.
You may ignore the Java compile-time warnings produced by Yylex.java.
Program 3: Parser
I have updated the test data for project 4 (fixing the old %% to the new
@@ delimiters for multi-line comments) in the public.tar.gz file. If
you want to test your parser against valid programs, please use these
new versions. Of course, you need to have your own test data as well.
The document recommends we use a List to store
declarations, but I wasn't able to compile my parser when using List<DeclNode> with CUP version 10k, as indicated in
the default Makefile. I was able to use List<DeclNode> with CUP 11b, but this introduces a few
warnings, such as the parser() method being
deprecated. Am I responsible for the additional warnings version 11k shows, or
is there a way to use Lists with version 10k?
You may use 11k and ignore its warnings, if it works. But all the nonterminals
can be associated with classes, not lists of classes. For instance, you can
have a class DeclsNode, which has a member that is a
List<DeclNode>. Version 10k is perfectly fine
Shouldn't ProgramNode contain a List<DeclNode> instead of List<VarDeclNode>, as suggested in the document?
I think you are right.
Program 4: Semantics checker
I am a little confused on when a runtime exception should be thrown or
when an error should just be counted as a semantic error. I noticed in
the startup code you throw a runtime exception when checking the
semantics of the kind of identNode in asgNode (mustBe(kind.val ==
You want to continue the semantic analysis through the entire AST.
Don't throw an exception; just print a diagnostic (with line and maybe
column number) and continue.
Sematic rule #31 states, "It is invalid to use the value of a local variable if
there is no earlier assignment to that variable." Does this rule apply to
arrays? A char array could be initialized by being
assigned a string literal. However, an int or bool array of size n would require (at least) n assignments
to guarantee that every element of the array has been assigned.
This rule does not apply to arrays.
Since for loop labels are local declarations (sematic
rule #25), may a nested for loop's label hide an outer
loop's label? That is, may a nested loop have the same label as an outer loop?
Yes, the same label may appear in an inner loop; the inner
label hides the outer one.
Is it valid for a read statement to contain the same
variable name twice?
Yes, but the meaning is then undefined as to which one is effective.
Sematic rule #24 states "Any expression of type int,
bool may be type-cast to an int, char, or bool value. These are the
only type casts allowed." To be clear, does this rule mean that arrays may
not be type cast? If so, is it acceptable to add support for array
type casts if the feature is documented in the README? For example,
casting a char array of size n to an int array would result in an int
array of size n.
Arrays may not be type-cast. You may add support for array casts, but
you will find it hard to implement that feature in the next assignment.
Program 5: Code generator