Thanks for your answer. I already integrated such an extension. S -> expression expression -> expr(expression)expression -> int int -> /\d+/ expr(X) -> binop("+", X, X)expr(X) -> binop("-", X, X)expr(X) -> binop("*", X, X)expr(X) -> binop("/", X, X) binop(Op, X, Y) -> X Op Y
It works pretty well, I pushed the fun as to implement currying and few more features, like self references, inheritance and so on.... it may save a lot writing without necessarily extending the underlying algorithm. > Date: Tue, 23 Sep 2014 10:48:38 -0400 > From: a3m...@uwaterloo.ca > To: peg@lists.csail.mit.edu > Subject: Re: [PEG] integer encoding // computational model > > On 09/23/14 09:29, Abdelkader Belloundja wrote: > > 3) Sum ( Succ X ) ( Y ) = Succ ( X + Y ) > > > > The third rule explicitly states a transformation. Could anyone imagine > > to carry to same amount of meaning in a context-free grammar rule. And > > if so, how !? > > > > I end up with these alternatives : > > > > 1) try to stick to the grammar formalism ( the grammar's grammar if you > > will ) and find another interpretation for it, that would closely > > ressemble parsing but being synthetical instead of analytical. > > > > 2) Incrementally extend the grammar formalism to introduce things like > > replacement patterns, and make the algorithm support the enhancements. > > I'm not sure if it will be useful to your "encoding computation as PEGs" > project, but I've thought a couple times about doing something like > replacement patterns as an extension to the PEG formalism. It would be > more broadly useful for things like programming language grammars: e.g. > a comma-separated list of FOOs as: > > List<FOO> := FOO ( "," FOO )* > > which would save you from writing List_Expr and List_Param and who knows > how many other rules with the same structure. If you made the parameters > dynamic you could even write a PEG for indentation-based block > structures (depending on the other features you support), e.g.: > > Space<N> := "\t"{N} > IfExpr<N> := "if" Expr "\n" > Space<N+1> Expr > ( Space<N> "else\n" > Space<N+1> Expr )? > > > > _______________________________________________ > PEG mailing list > PEG@lists.csail.mit.edu > https://lists.csail.mit.edu/mailman/listinfo/peg
_______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg