It is now possible, though still a bit ugly, to define grammars with the action codes written as Felix templates, instead of Scheme.
Here's a simple example: ///////////////////// syntax XXX { x[sbor_pri] := x[>sbor_pri] "OVER" x[>sbor_pri] =># ( ?1 / ?3 ); stmt := "WILL" sstatements "DO" ";" =># { println$ "Hello"; ??2; println$ "Bye"; }; } open syntax XXX; println$ (100.0 OVER (22.0 OVER 7.0)); WILL println$ "One"; WILL println "INNER"; DO; println$ "Two"; DO ; ////////////////// For expressions you write ... =># ( sexpr ) and for statements you write: ... =># { sstatements } and for Scheme you still write: ...=># " scheme code " There is a new expression form: ?9 which can only be used in such templates. It is replaced by the AST term corresponding to the 9'th symbol in the production, like _9 would be in Scheme. There is a new statement too: ??9; which must correspond to a nonterminal of the same type as "sstatements", a list of statements. It is replaced by the sequence of statements. If you write: ?9; it will be parsed as call ?9 (); which is not appropriate if the 9'th symbol is a list of statements. This feature does NOT replace the need for Scheme to do sophisticated stuff, but it is perfectly good for defining stuff with simple fixed templates. So you can define infix operators easily, as shown, but you cannot define a new kind of match so easily because that requires an indeterminate number of arguments. Note that "in principle" the ?9 style substitution can be used for any AST term (more precisely, any Scheme value), not just expressions. The special case for statements is simply because there's no way to parse a phrase that represents a variable number of statements: we have an AST term for that (ast_seq), and we have a nonterminal for it (sstatements), but there is no actual Felix statement or expression for it, hence the special hack. I will probably change the syntax and generalise this a bit. By far the hardest thing for me was getting the Scheme bits of the code right. Most of the work is actually done in Scheme not Ocaml. The fun bit is the same as any macro language or shell: getting stuff to evaluate at just the right time. At least with Scheme this is well defined and program control (NOT by macro expansion) but it's still tricky! Note: to use this feature, the syntax for the action template has to be open! -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_sfd2d_oct _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language