Long ago I made various parsers (most of them in Fortran or assembler) for
expressions with infix notation. I always used push-down automata with two
or more stacks. Now I am playing with macros in Racket that allow infix
notation embedded in Racket without explicitly using push-down automata.
However, I encounter a contradiction in my desires as explained below. I
have looked at 'Infix expressions for PLT Scheme' available in planet and
made by Jens Axel Søgaard. In his approach a+b is evaluated as though
written as (+ a b). However:
#lang at-exp scheme
(require (planet soegaard/infix))
(define a+b 4)
(define a 1) (define b 2)
@${a+b} ; evaluates to 3
A Racket variable can contain characters such as +, -, * etc.
This makes @${a+b} confusing
(not necessarily ambiguous, though, depending on syntax and semantics.
In my own toy I require variables and operators to be separated by spaces.
So I write (infix b ^ 2 - 4 * a * c), not (infix b^2-4*a*c).
In my toy b^2-4*a*c is read as a single variable.
Of course notation b^2-4*a*c is attractive.
b ^ 2 - 4 * a * c looks rather ugly,
but allows unambiguous discrimination between operators and variables.
Furthermore my infix can be required within #lang racket.
It does not need at-exp.
I allow:
(require (rename-in racket (+ plus)))
(infix 1 plus 2) ; expanded to (+ 1 2)
My infix accepts procedure and macro calls of the form:
(infix list('a, 'b ,'c)) and
(infix if(test, then-case, else-case))
Even more attractive than b^2-4*a*c would be b^2-4ac,
but this would delimit variables to consist of one character only.
One one hand I want an attractive notation. On the other hand I want easy
embedding in Racket allowing the use of Racket variables in my infix
expressions
and allowing renames of operators. The two hands contradict each other.
I am not sure how to proceed.
Opinions and suggestions are very welcome.
Thanks, Jos Koot
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.