Skip to main content

The Safe Expression Evaluator

Challenge on lesson: Checkpoint: The Unbreakable Evaluator

Assemble the module into one hardened component: an evaluator for tiny integer expressions that CANNOT exhibit UB on any input. The boilerplate declares: ``c /* grammar: NUMBER op NUMBER (op: + - *) input: the expression string; out: the result returns 0 ok, -1 on ANY problem: syntax, too long (numbers must fit int), intermediate or final overflow (int arithmetic), unknown op. All arithmetic is saturating (Module 14 rules); no UB anywhere. */ int eval_expr(const char *s, int *out); /* saturating helpers from this module's practice (implement them here) */ int sat_add2(int a, int b); int sat_mul2(int a, int b); `` Grammar: whitespace allowed around tokens; numbers are unsigned decimal (fit int, checked); exactly one operator; nothing else.

Difficulty: intermediate

Back to lesson: Checkpoint: The Unbreakable Evaluator