Question

I must keep the information of a token for my lexical analyzer, for example its row and column. If I come across some source code like this: \t \t int myInt; , how can I know the column of the token ? Because I don't know how many columns does a \t take. Thanks

Was it helpful?

Solution

Experimental evidence suggests that gcc, at least, simply counts the tab character as a single character.

If you wanted to find the column number where the text is conventionally displayed, you would have to choose a tab width (probably 8 or 4) and round up to the first matching tab stop. But the problem is of course that different users choose different tab widths, and having the compiler arbitrarily choosing a tab width of its own would likely just add to the confusion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top