c - How to differentiate '-' operator from a negative number for a tokenizer -
c - How to differentiate '-' operator from a negative number for a tokenizer -
i creating infix look parser, have create tokenizer. works well, except 1 thing: not how differentiate negative number "-" operator.
for example, if have:
23 / -23 the tokens should 23, / , -23, if have look like
23-22 then tokens should 23, - , 22.
i found dirty workaround if encounter "-" followed number, @ previous character , if character digit or ')', treat "-" operator , not number. apart beingness kind of ugly, doesn't work expressions like
--56 where gets next tokens: - , -56 should --56
any suggestion?
in first illustration tokens should 23, /, - , 23.
the solution evaluate tokens according rules of associativity , precedence. - cannot bind / can 23, example.
if encounter --56, split -,-,56 , rules take care of problem. there no need special cases.
c parsing token
Comments
Post a Comment