How to handle comments using API

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

How to handle comments using API

twitu
I found the API difficult to implement if followed to the word. Particularly while handling comments.

The hasMoreCommands() returns a boolean but it must know the content of the line to determine if it is a comment or not. This effectively makes advance() function useless.

How do i resolve this issue ?
Reply | Threaded
Open this post in threaded view
|

Re: How to handle comments using API

cadet1620
Administrator
Yes, strict implementation of this interface requires hasMoreCommands() to read lines and strip comments and whitespace and only return when it has found a non-blank line or end of file.

I combined hasMoreCommands() into advance() and had advance() return true/false so that my pass1/pass2 loops can simple be "while(parser.advance()) {"

Another thing that I've seen students do, especially in languages like Python that make list manipulation really simple, is to read the entire source file into a list, then strip all the comments and whitespace, then delete any blank lines that may result.

I don't like this pre-stripping because if you later wish to modify your assembler to add source line number information to error messages, or generate a listing file, you have lost all that info.

--Mark