[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: are there user defined infix operators?
From: |
Hans Åberg |
Subject: |
Re: are there user defined infix operators? |
Date: |
Thu, 8 Nov 2018 22:33:47 +0100 |
> On 8 Nov 2018, at 21:19, Akim Demaille <address@hidden> wrote:
>
> Hi Uxio, hi Hans,
Hi Akim,
> You cannot use Bison to resolve dynamically your precedence if
> you have a free set of levels. But if you have a fixed number
> of level, say 10, then you could define ten tokens for each level,
> and give them the precedence you want. Then, in the scanner,
> map each operator to the corresponding level, storing the actual
> operator as a semantic value. The scanner could use a map for
> instance to decide to which token you map each operator.
That is also a possibility, but make it at least 20 to cover C/C++ [1], as the
10 or so that Haskell admits is too limited. But it becomes problematic if the
number of levels is large, like 1200 as in SWI-Prolog.
> That wouldn’t be of much help if you also want to play with
> associativity. Maybe using even more tokens to denote the different
> possibilities.
I recall that the Haskell interpreter Hugs [2] used something like that.
1. https://en.cppreference.com/w/cpp/language/operator_precedence
2. https://wiki.haskell.org/Hugs
- are there user defined infix operators?, Uxio Prego, 2018/11/02
- Fwd: are there user defined infix operators?, Uxio Prego, 2018/11/02
- Re: are there user defined infix operators?, Hans Åberg, 2018/11/08
- Re: are there user defined infix operators?, Hans Åberg, 2018/11/08
- Re: are there user defined infix operators?, Uxio Prego, 2018/11/08
- Re: are there user defined infix operators?, Hans Åberg, 2018/11/08
- Re: are there user defined infix operators?, Uxio Prego, 2018/11/10
- Re: are there user defined infix operators?, Hans Åberg, 2018/11/10