0
votes

I'm trying to wrap my head around how to handle C-style multiline comments (/* */) with a recursive descent parser. Because these comments can appear anywhere, how do you account for them? For example, suppose you're parsing a sentence into word tokens, what do we do if there's a comment inside a word?

Ex.

This is a sentence = word word word word

vs

This is a sen/*sible*/tence = ???

Thanks!

1
Did you write a lexer/tokenizer first? You could just ignore anything between /* and */ when breaking your program text into tokens. - eigenchris

1 Answers

1
votes

In C, like pretty well every other programming language, a comment is effectively whitespace; a comment cannot occur within a token.

So comments cannot interrupt the parsing of a token, and thus only need to be recognized and ignored.