I have a list of supported operators, my question is whether the lexer should just yield the token for the operator or raise a syntax error in case that particular operator (let's say "?") doesn't exist in the operators list?
for example, the operators list [+, -]. for the expression "1 ? 2", should the output be [number:'1', operator:'?', number:'1'] or it should raise a syntax error?
The parser should handle it instead of the tokenizer?
. { return *yytext; }
, and then if you later add a?
token to your language, you don't need to change the lexer at all. – rici Oct 31 '21 at 02:53