[Toybox] [PATCH] Fix the operator precedence in expr.
Andy Chu
andychup at gmail.com
Mon Mar 14 21:29:32 PDT 2016
This fixes 3 tests, and the delta in expr.c is +11 lines -- all
comments. The actual code is shorter.
It's a bit unnatural to me but I tried to compress the code, following
the existing style.
I'm going to fix the type coercion problems too, which will piggyback
on this change. Basically the OPS lookup table needs have another
field to specify coercion rules for the operation. The type
conversion has to be done with respect to the operation being
evaluated rather than globally up front.
# fails with type error, '21' should be coerced to integer and then added to 3
expr ab21xx : '[^0-9]*\([0-9]*\)' + 3
# segfaults because '3' is coerced to integer at parse time, and we
pass NULL to regexec
expr 3 : '\(.\)'
-----
expr now uses the precedence table specified by POSIX, implemented using
the "precedence climbing" algorithm. See the references at the top of
eval_expr().
This fixes 3 of 4 failing tests.
I also added more tests for correct behavior and for syntax errors.
This includes a new test exposing a segfault, related to type coercion.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-the-operator-precedence-in-expr.patch
Type: text/x-patch
Size: 8628 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20160314/45d343a2/attachment-0004.bin>
More information about the Toybox
mailing list