Re: How Do CL's Macros Differ from Scheme's?



On 2009-10-04, Vassil Nikolov <vnikolov@xxxxxxxxx> wrote:
To clarify the analogy, consider how context-sensitive grammars
better (or more fully) describe programming languages, but are

The analogy is poor because both hygienic and non-hygienic macro systems
are practical, useful, and in actual wide use.

Whereas, context-sensitive grammars are of little help in programming
languages and are not widely used at all.

harder to deal with, so context-free grammars are used together with
additional "extra-grammatical" facilities to describe languages and
process programs written in them.

Not only is there no feasible way to represent that information in
the context-sensitive grammar, it doesn't even reflect how the
users think about the language.

What is a context-sensitive grammar? It's one in which you can have
rules that rewrite strings of several nonterminal symbols, rather
than just one. The rules can have several symbols on the left side,
not just one.

So in a context free grammar we might have a rule like:

A -> A B ;; A generates an A followed by B.

In a context sensitive grammar we might have stuff like.

A C -> A B ;; a followed by B generates A B; C is eaten.

D A -> B ;; A preceded by D generates B.

It's not even remotely obvious how to apply this to achieve
a syntactic representation of the ``extra grammatical'' stuff
found in a typical programming language.

It's also not clear that encoding that stuff in this kind of grammar would not
just constitute a convoluted representation of the same data structures which
are used to solve the problem in the conventional ways.

That it to say, suppose you solve some familiar C parsing problems using the
above kind of language. A C program which refers to a nonexistent identifier in
a primary expression is identified as syntactically ill-formed. And syntax of
the form T(x); is recognized as a declaration because T was previously declared
as a typedef name.

How would the context-sensitive rules achieve that?

A normal compiler simply makes references to a symbol table. Has x been
declared? What kind of name is T?

Wouldn't the context-sensitive rules simply build up some kind of
representation of a symbol table, within the string of grammar symbols
being pushed around? So the context which would allow T(x); to be
recognized as a declaration would actually be a symbol table
in which T is declared as a type name, only this symbol table would
look like a string of grammar symbols (to someone who doesn't know
better). Someone who does understand this context-sensitive grammar,
such as hopefully its implementor, would be able to look at the
string of grammar symbols and utter ``yes, this rule applies because
T has been declared to be a type name''.

So what would really be achieved, and how would that be better
and more complete?

Hygienic macros do bring something to the table, and so do non-hygienic
ones.
.



Relevant Pages

  • Re: The Promise of Forth
    ... any value in that, programming languages are programming languages, natural ... The idea that grammar is a "mental muscle" for programming is ... Natural languages are designed for, and address, a very different problem than a computer language. ...
    (comp.lang.forth)
  • Re: The Promise of Forth
    ... any value in that, programming languages are programming languages, natural ... The idea that grammar is a "mental muscle" for programming is ... Natural languages are designed for, and address, a very different problem than a computer language. ...
    (comp.lang.forth)
  • Re: Unix and OO Avoidance
    ... I feel the need to restore the context because in quite a few places, ... Whether functional methods and languages limit the negative impact of ... supporting structured programming, in your linguistic framework, we must ...
    (comp.object)
  • Re: About context sensitivity.
    ... I heard of Anders Heljsberg eplaining the idea of Data Programming. ... This means semantic net based Semantic ... Level context programming language available? ... > sensitivity and if some programming languages exist that target .NET. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: FORTH levels
    ... to engage the human brain in the processes of programming. ... I don't believe there is "linguistic psychology". ... languages develop into a direction that usually is less linguistic than ... Chinese "grammar" (which means much less grammar as the ancient German ...
    (comp.lang.forth)