Grammar: subroutineDec* vs. subroutineDec+

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Grammar: subroutineDec* vs. subroutineDec+

peterxu422
On page 208 of the textbook, in Program Structure, class: 'class' className '{' classVarDec* subroutineDec* '}'

why is it subroutineDec* as opposed to subroutineDec+ ? Shouldn't there be at least one function defined in a class in Jack?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grammar: subroutineDec* vs. subroutineDec+

cadet1620
Administrator
peterxu422 wrote
On page 208 of the textbook, in Program Structure, class: 'class' className '{' classVarDec* subroutineDec* '}'

why is it subroutineDec* as opposed to subroutineDec+ ? Shouldn't there be at least one function defined in a class in Jack?
It's a simplification to make Jack parsing easier. Properly dealing with "one or more" is a lot harder in a recursive decent parser than "zero or more".

Or maybe it's because "x+" isn't in the grammar language's grammar (10.2.1). 8-)

--Mark
Loading...