On 15 Jun 2015 9:38 pm, "Matt Oliveri" <[email protected]> wrote:
>
> On Sun, Jun 14, 2015 at 10:47 AM, Keean Schupke <[email protected]> wrote:
> >
> > data Program = Prog [Declaration]
> > data Declaration = Decl Variable Expression
> > data Variable = Var String
> > data Expression = Apply Expression Expression | Abstract Variable
Expression
> > | Variable
> >
> > Taking the above program abstract syntax, it seems obvious to me that
> > parsers should output these elements.
> >
> > For example if we have the following syntax for an abstraction:
> >
> > '\', {space}, var, {space}, '.', {space}, expression
> >
> > This clearly relates to the "Abstract Variable Expression" value
> > constructor.
> >
> > This might be in combinators:
> >
> > auto const lam_tok = tokenize(accept(is_char('\\')));
> > auto const var_tok = tokenize(accept(is_alpha) &&
many(accept(is_alnum)));
> > auto const dot_tok = tokenize(accept(is_char('.')));
> >
> > auto const abs = all(return_abs, discard(lam_tok) && var_tok,
> > discard(dot_tok) && expr);
> >
> > So to integrate this with the abstract syntax, we need to assert that:
> >
> > typename abs::value_type
> >
> > Is "Abstract Variable Expression" from the AST.
> >
> > So I would consider the AST itself determines the grammar,
>
> No. If you had chosen a different surface syntax for lambda
> abstraction, you'd need a different parser too, but the AST hasn't
> changed. What I think you're pointing out is that in practice the AST
> structure will lead to a sensible grammar. But clearly the grammar is
> not uniquely determined by the AST structure.

Yes I agree with this. What I was saying is that the AST is the important
thing and we should define the language in terms of the AST (hence the
grammar is a tree grammar, and incorporates typing). The surface syntax is
just a representation issue and is defined by the parser. So as you say I
could have two different parsers for the abstraction.

So an a typed AST defines part of the grammar (the structure) and for each
internal or leaf node can define a parser. The AST plus the parsers define
the grammar.

Keean.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to