How Do I write codes for classVarDec* in the compileClass?

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

How Do I write codes for classVarDec* in the compileClass?

Ichiro
Hi,

I tried to parse classVarDec* in compileClass() using while expression for an attached sample Jack program. However, I received an error message 'list index out of range.' I wrote while expression as below.
test.jack
while token[i]=='static' or 'field':
         cn.CompileVarDec()                //cn is a CompilationEngine class

Instead of using while expression, I called CompileclassVarDec() twice to parse classVarDec and then it worked out. I guess CompileclassVarDec() is correct and the problem is related to while expression.

I have no idea why my code output the error and could you give me any clue? If a complete parser program is needed, I will share it.

Thanks,
Ichiro
Reply | Threaded
Open this post in threaded view
|

Re: How Do I write codes for classVarDec* in the compileClass?

Ichiro
I found out a mistake by myself. It was such an easy one.

The parser for the ExpressionLess Square has been completed. I am now struggling with parsing the rest of the jack programs.