Open
Conversation
+ In C, the comma operator has the LOWEST precedence, and we are instructed to give it the same precedence in Lox. That means that it must be parsed BEFORE the thing that PREVIOUSLY had lowest precedence—in our case, the OR operator. + We have the commaOperator() function in the parser return a new kind of expression—a CommaCollection (yeah, I know, I'm a verbose namer). We define that type of Expression in GenerateAst, and each time we build the expression type itself gets generated in Expr.java. (Don't change that file directly—it just gets overwritten). + That expression type receives a method in the Visitor Interface. So all of the interface's implementors (Resolver and Interpreter) must deal with comma collections. The interpreter evaluates the expression before the comma and the expression after the comma, and returns only the one after the comma. The resolver resolves both halves (maybe it doesn't need to resolve the left half if we're discarding the evaluation, but whatever). + FINALLY, we have to nudge over the code path for argument lists in functions. Like comma collections, the arguments of a function are delimited with commas. UNLIKE comma collections, the arguments of a function are all needed in the function and we can't just discard all but the last one. So instead of calling expression(), which now includes commaOperator() in its recursive descent path, we make a new function in the Parser called assignArg() that follows the same recursive descent path expression() followed BEFORE we added commaOperator().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.