[Toybox] [PATCH] expr

Daniel Verkamp daniel at drv.nu
Tue Jun 4 01:09:52 PDT 2013


This half-baked implementation of expr has been sitting on my disk for
a little while now, but I find myself struggling to find time to
finish it, so I'm posting it in the hopes that someone will pick it
up.

The expression is evaluated using a recursive descent parser; the core
of the evaluator is parse_op(), which uses a table to determine
operator behavior and precedence.

All numeric values are represented as 'long', which is only 32 bits on
32-bit hosts; it may be interesting to use 'long long' instead.

What's left to do:
- Flesh out the help text.
- Write more comprehensive test cases.
- Decide what to do about integer overflow (the current code can
execute undefined signed overflow behavior with large inputs; GNU
coreutils expr detects this and prints an appropriate error).
- Implement the : operator - yes, in fine 'cat -v' tradition, POSIX
expr can match regular expressions.

I have done some minimal testing while writing the command, but it
could use some real-world testing (I think the Linux kernel build
contains a few expr invocations, but I have not tried it with this
implementation).

Feel free to fold, spindle, or mutilate as desired.

Thanks,
-- Daniel Verkamp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: expr.patch
Type: application/octet-stream
Size: 6611 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20130604/0bfe44e3/attachment-0006.obj>


More information about the Toybox mailing list