37 parse call expressions#38
Merged
Merged
Conversation
- Add CallExpression to ast/ast.go - Fields: Token token.Token, Function Expression, Arguments []Expression - Implements expressionNode(), TokenLiteral() and String() to render calls like fn(arg1, arg2)
- Register LPAREN as a call-expression infix so function-call sites are parsed correctly - Add parseCallExpression and parseCallArguments to build call AST nodes and consume arguments - Add/update tests in parser/parser_test.go to verify call parsing and operator precedence inside arguments
* Convert let statement cases to table-driven inputs * Add expected values for integer, boolean, and identifier assignments
* Replace placeholder token skipping with expression parsing in let and return statements.
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the Monkey interpreter’s front-end by adding function call expression parsing (e.g., add(1, 2)) and by enabling let/return statements to actually parse and store their expression values in the AST.
Changes:
- Add call-expression precedence and parsing via
(as an infix operator, including argument parsing. - Populate
LetStatement.ValueandReturnStatement.ReturnValueby parsing expressions instead of skipping them. - Introduce
ast.CallExpressionplus parser tests for call parsing and operator precedence involving calls.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
parser/parser.go |
Adds call-expression parsing and enables expression parsing for let/return. |
parser/parser_test.go |
Adds call-expression parsing tests and expands precedence/let-statement tests. |
ast/ast.go |
Introduces CallExpression AST node and stringification. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…r semicolon Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
feat(parser): add call expression parsing