bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about arithmetic expression grammar


From: Chet Ramey
Subject: Re: Question about arithmetic expression grammar
Date: Sat, 15 Oct 2016 22:57:04 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

On 10/10/16 9:57 AM, Stephane Chazelas wrote:

> Now, if we look at the C spec, the way +++ is parsed is down to
> tokenisation that will also go for the longest operator first.
> 
> There --test+++3 would be tokenised as -- test ++ + 3 which
> would lead to a syntax error as test++ isn't an lvalue.
> 
> bash works differently.
> 
> From what I understand from past discussions on the subject here
> bash doesn't treat it as a syntax error and tries instead to tokenise
> those incorrect ++/-- into multiple + or - operators if possible.

This is more or less correct.  Bash doesn't treat a token as a post-
increment or post-decrement unless the previous token is a string.  Since
the previous token is a number (based on the evaluation of the pre-
increment), these are treated as a sequence of unary pluses.

In this case, we can add some additional error checking.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]