diff options
author | 2011-06-20 17:59:39 +0800 | |
---|---|---|
committer | 2011-06-22 19:53:01 +0800 | |
commit | d346fde50e1ef43c00ae2a76449b3f9dc0207ccb (patch) | |
tree | eaa8514cb11637eac922b602ebc479c05ec8f86a | |
parent | Walker: support shortcut capability for logic or (diff) | |
download | libbash-d346fde50e1ef43c00ae2a76449b3f9dc0207ccb.tar.gz libbash-d346fde50e1ef43c00ae2a76449b3f9dc0207ccb.tar.bz2 libbash-d346fde50e1ef43c00ae2a76449b3f9dc0207ccb.zip |
Walker: support shortcut capability for logic and
-rw-r--r-- | bashast/libbashWalker.g | 12 | ||||
-rw-r--r-- | scripts/binary_arithmetic.bash | 1 | ||||
-rw-r--r-- | scripts/binary_arithmetic.bash.result | 1 |
3 files changed, 13 insertions, 1 deletions
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g index 99d7f53..d6a6dca 100644 --- a/bashast/libbashWalker.g +++ b/bashast/libbashWalker.g @@ -972,7 +972,17 @@ arithmetics returns[int value] $value = (arithmetics(ctx) != 0); } }) - |^(LOGICAND l=arithmetics r=arithmetics) { $value = l && r; } + |^(LOGICAND l=arithmetics { + if(!l) + { + skip_next_token_or_tree(ctx); + $value = 0; + } + else + { + $value = (arithmetics(ctx) != 0); + } + }) |^(PIPE l=arithmetics r=arithmetics) { $value = l | r; } |^(CARET l=arithmetics r=arithmetics) { $value = l ^ r; } |^(AMP l=arithmetics r=arithmetics) { $value = l & r; } diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash index 114655a..577ddbc 100644 --- a/scripts/binary_arithmetic.bash +++ b/scripts/binary_arithmetic.bash @@ -64,3 +64,4 @@ FOO058="$((${FOO056}+=10))" ARRAY=(1 2 3 4 5) FOO059="$((100**0))" FOO060="$((FOO059||FOO059++))" +FOO061="$((0&&FOO059++))" diff --git a/scripts/binary_arithmetic.bash.result b/scripts/binary_arithmetic.bash.result index 740548d..926b23a 100644 --- a/scripts/binary_arithmetic.bash.result +++ b/scripts/binary_arithmetic.bash.result @@ -59,5 +59,6 @@ FOO057=100 FOO058=111 FOO059=1 FOO060=1 +FOO061=0 PARTIAL=5 value=111 |