Refutable pattern

Claude Pache claude.pache at
Fri Feb 1 11:58:28 PST 2013

Le 1 févr. 2013 à 20:00, Andreas Rossberg <rossberg at> a écrit :

> On 1 February 2013 18:24, Brandon Benvie <brandon at> wrote:
>> A postfix '?' would require backtracking when the next '}' is found...I
>> think?
> Yeah. I admit that I don't remember much of the earlier discussions on
> respective parsing difficulties. Naively, it would seem to me that a
> prefix '?' should actually be easier to parse.
> /Andreas


I've do some analysis when there could be an ambiguity between a postfix "?" and the conditional operator (? :).


In the proposed grammar, it seems to me that a postfix "?" can appear in Pattern in the following positions only:

(1) inside a Pattern, before the following tokens:   ": , ] }" (colon, comma, closing bracket, closing brace) and apparently before another postfix-"?" (although it would be of no practical use);
(2) at the end of a Pattern.

In case (1), there is no ambiguity with the conditional operator. In case (2), one has to further analyse where a Pattern could appear.


More generally, let's suppose that "?" can be either an infix (that is to say, between two sub-expressions) when used as part of the conditional operator, or a suffix in our case. We have experience with a somewhat symmetrical case, namely tokens that can be either infix or prefix in expressions; these are: 
	+ - / ( [
and I think they don't pose much problem, except we can't rely on ASI when such a token appears at the beginning of line.

It seems to me that the problems we would meet are the following two cases:

(A) When "?" is followed by a token that can be either prefix or infix ("+ - / ( ["), there is ambiguity, because in

	expression ? + expression 

one cannot decide if it means "expression (infix-?) (prefix-+) expression" or "expression (suffix-?) (infix-+) expression".

(B) When "?" appears at the end of the line, we cannot rely on ASI (a situation symmetrical to one of "+ - / ( [" appearing at the beginning of a line).


For parsing purpose, when we encounter a "?", maybe one could just look ahead the next token: if it might be the beginning of an expression, we decree that "?" is part of the conditional operator. We have to determine which token can appear at the beginning of an expression to see if it is reasonable solution.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list