-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
12a Procedures #20
12a Procedures #20
Conversation
Parsing PROCEDURE statementsWe match for the PROCEDURE keyword: And implement it as follows:
At first glance, procedures look very similar to functions. Couldn't we just use the same Yes, kinda ... but we can only call procedures with the CALL keyword (i.e. calling a procedure is a statement in itself), while functions can be called anywhere in place of an expression. This means we need a way to differentiate functions and procedures, such that function calls are |
Resolving PROCEDURE statementsThis one is easy: Procedures have no return type that need matching or storing, and the name and argument declarations have no |
Executing PROCEDURE declarationsDeclaring a procedure is the easy part: We just store everything the procedure needs into the frame for now. Executing it is going to be another story ... And meanwhile we catch a typo bug: |
Testing
Result (frame):
Result:
Oops. At this point, Result (frame):
|
With branches and loops in place, let's move on to procedures, then functions.
We will have to add some features to allow procedures and functions to have their own frames for locally declared variables (if any). But not here, not yet. For now, our procedures will use the global frame.
A procedure with no parameters is defined as follows:
A procedure with parameters is defined as follows: