[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: are there user defined infix operators?
From: |
Uxio Prego |
Subject: |
Re: are there user defined infix operators? |
Date: |
Thu, 8 Nov 2018 22:34:46 +0100 |
> For fixity overloads (same name but different fixity), one can have the
> overloads used in C/C++: prefix and postfix (as in ++), or prefix and infix
> (as in -), but not infix and postfix. This requires extra processing, keeping
> track of the token that was before; Bison cannot do that, so the lexer must
> do it. A grammar might look like, with the lexer figuring out what to return:
> [...]
This seems very insightful, thank you.
> Take a simple example, a + b*c #, where # is the end marker. First put the a
> on the value stack, and the + on the operator stack, and then the b on the
> value stack. When the * comes by, it has higher precedence than the + on top
> of the operator stack, so it must be stacked. Then the c comes by, so put it
> on the value stack. Finally the end marker #, which has lower precedence than
> *, so let * operate on the value stack, and put back its value, b*c. Next is
> the +, and # has lower precedence, so + operates on the value stack,
> computing a + (b*c), which is put back onto the value stack. Then the
> operator stack empty, so the process is finished, and the value stack has the
> value.
> [...]
The example and explanation are worth a thousand words,
thank you very much. So I use a simple grammar like that, and
the stack data structures, and if necessary feed the lexer back
with data from the parser once the user requests some infix
operators.
I'm not going to exploit this right now, but I rest assured to know
a way to explore if I ever need to get there.
- 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 <=
- 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