Search code examples
c++parsingcompiler-constructiontokenliterals

How is 0xe+foo parsed?


How is 0xe+foo parsed?

I know that it is parsed as a whole preprocessing number, but i dont get why, because, how can the operator "+" be a pp-number?

pp-number : 
digit
. digit
pp-number digit
pp-number identifier-nondigit 
pp-number ’ digit 
pp-number ’ nondigit 
pp-number e sign
pp-number E sign
pp-number p sign
pp-number P sign
pp-number .

Here is no "+", so thats why i thought it is parsed as:

0xe + foo

What am I missing? I know the rule of maximum match, but how is the "+" sign a pp-number?

If I would have x+++++y it is parsed as x ++ ++ + y, which makes sense, but how is then 0xe+foo not parsed as 0xe + foo?


Solution

  • + matches sign in the production you quoted.