Search code examples
compiler-construction

how to determine the '*' character is an operator or a punctuator at the step of lexical analysis


I am about to write a compiler for c, and by referencing google I found that the star character is in both the definitions of operator and punctuator. I think it should be decided at the step of parsing as we can not judge until we look around it.But I have to generate a token for that star character before parsing.


Solution

  • But I have to generate a token for that star character before parsing.

    So do. Just generate a * token when you see a *. You don't need to know how the * is going to be used in order to generate a token for it.