I am currently working on a small interpreter. Here is the idea:

At the moment, you can extend the grammar by specifying a production
in an EBNF like language and action codes in Scheme.

There are two problems with this: the first is that Scheme is hard to write,
at least for me. And the second is that the Scheme must return s-expressions
matching what the Felix compiler expects: the structure of these terms is
complex, there are a lot of them, and they're not properly documented.

To make it easier the parser supports an alternative method.
Instead of

        non-terminal := production =># "scheme code";l

you can write

        non-terminal := production =># { Felix statements };
        non-terminal := production =># ( Felix expression);

Only statements and expressions can be handled like this.

However, statements in particular are limited. For example
a custom loop like

        stmt :=  "for" sname  "between" expr "and" expr "do" body =>#
        { var _2 = _4; ... ++_2; ... }

doesn't work because _2 is an sname, which is neither the correct
"part of speech" for a variable definition nor for an expression.

In Scheme, you have to construct the correct AST terms for each,
but merely using Felix code, you can't do it.

SO .. I have decided to make a grammar which allows you to write
generative code which is translated to Scheme, but which is easier to 
write. Here are some examples:

open syntax xscheme;
SCHEME "(define sqr (lambda (x) (* x x)))";
XSCHEME ( sqr 3 );
XSCHEME ( if 1 + (2 - 3) + 4 - 6 < 0 then "negative" else "non-negative" endif 
);
XSCHEME ( 1 * 2 * 3 * 4 );
XSCHEME ( (fun (x) => x + 3 * x) 23 );
XSCHEME ( (fun (x) (y) (z) => (x+y+z)) 1 2 3 );
XSCHEME ( 1,2,3,"Hello" );
XSCHEME ( let x = 4 in sqr x );
XSCHEME ( let x = 4 in x.sqr );
XSCHEME ( display "HELLO" );
XSCHEME (letrec fact = (fun (x) => if x == 1 then 1 else x * fact (x - 1) 
endif) in fact 4);
XSCHEME ( { display "Z"; display "A"; 42 } );
XSCHEME ( {var x = 1; var y = x + 1; y = y + 1; x + y } ); // 4

The XSCHEME statement is just a hack to display the result whilst building
the xscheme language. All these examples work. i find the Felix like notation
a bit easier to write than Scheme. The parser translates these code into Scheme 
though.

I have an issue at the moment though: functions with more than one argument
in Scheme. Felix notation doesn't allow these.


--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to