[Fwd: Language Syntax Suggestion]

Hans-Dieter Dreier Ursula.Dreier@ruhr-uni-bochum.de
Thu, 11 Mar 1999 00:14:23 +0100



Matthew Tuck schrieb:

> Hans-Dieter Dreier wrote:
>
> >> Perhaps you're confused by my use of extensions here.  What I meant was
> >> that  you create a new sort of tree node that can appear in the tree.
> >> This subtree would be simpler than the corresponding full form subtree,
> >> but shorter.
> > Shorthands are thus implemented by special node types? I wouldn't do this,
> > because it's not compatible. A parser has to know that node type to be
> > able to process the shorthand. I would consider such an implementation
> > rather as a language extension.
>
> No they're compatible.  ASTs are augmented by the extension definitions
> used in the file to allow expansions as necessary.  How a textual parser
> will handle extensions with no defined parse shorthands is another
> question.

If some program can't handle something decently anymore because it has no
definition for it, I'd call that incompatible. What else?

> > Example: If we take ...
> > while x do something end
> > ... as a shorthand for ...
> > do if not x then break; something end
> > then the AST should be (in LISP-speak): (do (; (if (not x) break)
> > something)  The pattern would be: (do (; (if (<condition> break) <body>)
> > This would be displayed as
> > do if not <condition> then break; <body> end
> > When expanding <condition>, double negations would have to be removed,
> > _or_ there have to be two patterns, one including the "not" and one
> > without "not".
>
> I'm not sure how exactly the "while" comes into this, you don't seem to
> have represented it.

Either "while" or "do" is a noise word here (like "if x then ..." where either
if or then is a noise word). A loop is just one construct, so it is represented
by one node. It has just one parameter, the loop body. It's an endless loop.
Breaks are handled separately inside, so you can have any number of them at any
place as long as it's inside a loop. Other loop constructs (for, do..while,
while..od, you name it) can be viewed as special (crippled) cases of an endless
loop with breaks, so nothing else is needed. Keep it simple.

> > The advantage of this approach would be that neither the front end nor the
> > compiler would *have to* know the shorthand; everyone could roll their own
> > without compromising portability.
>
> Well whether the compiler will see shorthands is not important.  They
> could get expanded out in a preprocessing step, or we might leave some
> known ones there for efficiency reasons.

If they have an efficiency impact inside the generated code, can they really be
regarded as mere shorthands?Aren't they true extensions then, rather? Otherwise
the compiler could achieve hte same by optimisation.
Where do you draw the border between language extension and shorthand?

> Usually the user will define the extensions somehow - then a view may
> need to know how to represent it - the more automatic the better,
> although this would reduce programmer control over syntax.  Views might
> be able to define their own extensions.  This means the front-end is
> fairly extension/shorthand independent, although there will need to be
> some framework for handling them, especially for textual views.

How would you define the term "view"?

> >> A higher-order function is a function that can take code as a
> >> parameter.  A first-order function could only take data.
> >
> > Similar to passing a function reference? Or are the parameters included
> > (like lazy evaluation) ?
>
> Yes, a func/proc that takes a func/proc reference/object.

So no (actual) parameters are included? Then it's nothing special, since I
regard references as data.


Regards

Hans-Dieter Dreier