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

Re: Syntax extension of infix languages



On 15 Dec 2001, Eric Kidd wrote:
> Let me clarify--
>
> I'm interested in syntax extension that's powerful enough to add new
> statements and declarations to the language.  A simple example might be
> an 'unless' statement in Dylan:
>
>  define macro unless
>    { unless (?:expression) ?:body end }
>      => { if (~?expression) ?body end }
>  end macro unless;
>
> A more complicated example might be implementing 'lex' or 'yacc' as a
> compile-time macro.
>
> This is a much more annoying problem than defining new operators.
>

Restricting to operator syntax does limit the language, but
it does provide a slight extension to s-expression syntax and
it may still give you most of what you want:

(define-outfix-operator unless sselnu)  ;; extend the parser

(define-macro unless EXPR BODY sselnu   ;; use extended syntax
  `(if ,EXPR ,BODY))                    ;; to define a macro

unless (= x 0) (display (/ x 0)) sselnu ;; and now use the macro

OR

unless x = 0 display{x/0} sselnu  ;; syntax is more readable when
                                  ;; = / display are operators
                                  ;; and {} is new outfix with {..X}-> ..X

Here I'm assuming your operator grammar allows outfix operators
(in which the outfix operators can not be overloaded, hence the
sselnu).

---Tim---