In the kaleidoscope parser / AST example at LLVM, the enum is given all negative values. Why the minus sign ?
enum Token {
tok_eof = -1,
// commands
tok_def = -2, tok_extern = -3,
// primary
tok_identifier = -4, tok_number = -5
};
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A common C idiom with enums is to use negative values to mean one set of conditions and positive values to mean another set. For example, error conditions from the parser might be all positive values, while normal conditions have all negative values, and maybe zero is the “undefined” case. So in your code testing for any error is as simple as
tok >= 0.