Skip to main content.

Final Project: FAQ

Project Specification

Answers to your commonly asked questions.

General Code Questions

What code can I change?
Any and all of it. Make sure you understand why you are changing it and use branching and commits judiciously so you can roll back.
These variable names/method names/... don't make sense to me,
After you understand their purpose, rename them with a descriptive name that would be more helpful.
How does a switch statement work?
Switch statement tutorial

Tokenization

I know I need to handle quoted strings for the images, but when I try to get the string, I only get the quote.
This requires understanding a bit about the StreamTokenizer class, which is used by the Tokenizer class. Look what it says in the nextToken about ttype and in the ttype documentation about quoted strings.
What does tokenNameToToken represent?
First, see where it is updated/used. Right click on the name, then go to References and select Project. It's being updated in the initBuiltinFunctionTokenMappings. That name is probably more descriptive than the map's name. It maps the name of the function to the Token class that represents the function. It is used to distinguish between a known function name and an identifier (a variable).
The minus sign is included in the variable name when I try to evaluate the expression x-y. This isn't a problem with the other operators.
Here is a terrible hack to solve this. I think this should usually work (and not break something else). In Tokenizer's parseTokens method, add this statement (and its comment) as the first line:
       // - is seen as a numeric character. If we try to parse, e.g., x-y, 
       // it is seen as one string "x-y".  See StreamTokenizer documentation about
       // handling words. So, our imperfect solution is to always add
       // a space before a minus sign. Negative numbers will still be
       // seen as numbers, and the space will mark the end of a word.
       s = s.replace("-", " -"); 

Here's what is happening: the StreamTokenizer looks at characters and tries to figure out what to do with them. According to the documentation, "A word token consists of a word constituent followed by zero or more word constituents or number constituents." So, when the StreamTokenizer sees the x in x-y, it grabs every word or numeric constituent that follows. We need the minus character to be a number constituent because we want to be able to parse numbers, e.g., -1. If we try to make the minus sign an "ordinary" character, we can no longer parse negative numbers. So, since this really isn't the focus of the assignment, we'll go with the imperfect solution provided above. (Although I am open to hearing proposals of better solutions.)

Parsing

The order of operations constants don't make sense. GROUPING should have high precedence.
You're learning to try to read someone else's code. Note that GROUPING is not yet used, and this is partial code. I am not sure if it would be used. It seems like it's placed for the parentheses of a function, but I don't know what the original goals of this code were. You can and should change this code to be whatever makes the most sense to you--well, and has good design.

Semantic Analyzer

I made my code for the negate/inversion (!) operator and updated all the right files, but my code isn't finding its semantic analyzer.
This one is tricky. ! is a comment for the properties file. You'll need to escape the character (using the escape character: \) in the properties file.

Evaluating

How should ImageWrap and ImageClip work?
See if this helps:

Error Handling

If there is an error when evaluating an expression, the next [valid] expression evaluated doesn't work either. But, if you press the button again, it works.
Add some print statements to try to figure out what's happening. Is there something leftover from the erroroneous expression?

Testing

I can't test method X because it's private
If it's private, is there a method that calls that method that you can test instead?

GitHub

My commits aren't being attributed to me in the GitHub Contributors page of our project.
GitHub says that the email address used for the commits must match the email address associated with your account. To update the name and address used for the commits, see this helpful tutorial.
Eclipse is saying that there are conflicts in our main branch, and I'm unable to merge my branch.
Yeah, that happens. Try to resolve the conflicts. You'll need to decide if you want to use that version or your version or maybe do a merge. After resolving the conflicts, stage them for commitment and then commit. Eclipse's User Guide