- Adding a new 'statementlist' nonterminal
Here we simply need to add 'statementlist' to the end of the %type line in the .yacc
%type program body statement statementlist
- Revising the body rule to expect a statementlist
This is simply replacing statement with statementlist in the body rule:
body:
BEGTOK
statementlist
ENDTOK
;
- Adding the statementlist rules
In the yacc rules we'll add two rules for statementlist, one for a statementlist
being a single statement and one for it being one statement followed by more statements:
statementlist: statement ;
statementlist: statement statementlist;
- Testing the new grammar rules
In theory, our programs can now have any number of statements (NUMTOKs, SETTOKs,
and IDENTTOKs) inside the body. We'll revise our test1.vurb to try it out:
main
begin
12345
foo
set
set
0
whatever
end
Now run make to create the updated lab1, and try it with
./lab1 < test1.vurb