On Sat, 2007-08-25 at 13:12 -0700, Erick Tryzelaar wrote:

> syntax foo {
>   satom := [ sexpr ] =># (List::list _2);
>   satom := lpar "from" sname in sexpr "endfrom" rpar =># ( List::map
> (fun x => x + 1) _5);
> }

> As you can see, I've got a long way to go. First off, this errors out with 
> this:

> 
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> syntax foo   {
>    0:   satom := lpar "from" sname in sexpr "endfrom" rpar =># ( List
> :: map ( fun x
> Syntax Error before token 67 in ./comprehensions.flx, line 2 col 77
> => x + 1 ) _5 ) ; }
>    0: <<save syntax ./comprehensions.flx.syncache>> open syntax foo ;
> val xs = List :: list (
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> Dyp.Syntax_error
> PARSE ERROR
> Unknown exception Parsing File

> It seems it doesn't like the embedded function. 

It's right. Lambdas cannot be polymorphic. You must write

        ( fun (x:int) => x + 1 )

Try this:

//////////////////////////////////
#import <flx.flxh>

syntax foo {
  //satom := [ sexpr ] =># (List::list _2);
  satom := lpar "from" sname in sexpr "endfrom" rpar =># 
  ( List::map (fun (x:int) => x + 1) _5);
}

open syntax foo;
open List;

var x = list (1,2,3,4);
var y = (from i in x endfrom);
println y;

//////////////////////////////////////////
[EMAIL PROTECTED]:/work/felix/svn/felix/felix/trunk$ f s
WHA?? Parent 4048 of 4051 does not exist??
WHA?? Parent 1778 of 1783 does not exist??
[2, 3, 4, 5]
//////////////////////////////////////////

It works! Lol :)


This works too:

//////////////////////////////
#import <flx.flxh>

#keyword from
#keyword endfrom

syntax foo {
  //satom := [ sexpr ] =># (List::list _2);
  satom := from sname in sexpr endfrom =># 
  ( List::map (fun (x:int) => x + 1) _4);
}

open syntax foo;
open List;

var x = list (1,2,3,4);
var y = from i in x endfrom;
println y;

var z = from i in from j in x endfrom endfrom;
println z;
///////////////////////////

(Note: no brackets needed in this version).

This doesn't work if you put "from" and "endfrom"
in the grammar rule .. that SHOULD work. Strings are supposed
to match identifiers and keywords, including user defined 
keywords. So you can write 

        "("

instead of lpar for example.

When from, endfrom are NOT keywords, it fails with an
ambiguity .. that puzzled me for a while, until I realised
this parse:

from i in (from j in x endfrom endfrom)

is perfectly valid, where endfrom in both cases is treated
as a variable name. Using #keyword prevents that.

BTW: I want to get rid of #keyword, and instead have
keywords that are scoped. i.e. local to a subparse.

For plain old identifiers, this could be done by 
a hook in the parser that translates identifiers using
a dynamically varying table. Symbols could be handled the
same way (i.e. sequences of special characters #$%^&*).

In general, however, we want to invent something like:

        q"x=$(x)"

feature.. or ..

        32.0i // complex number
        32.0 i // 32 multiplied by variable i

which requires a proper user extensible lexer. I have the
lexer -- it's a slight reworking of the flx_dfa.ipk code
used to generate Felix 'reglex' and 'regmatch' stuff.

But there are a LOT of details to work out, and to be
practical this needs dynamically loaded Ocaml code,
so we'll have to wait for 3.11.

That will be fun .. well have a language with mixed 

        Ocaml, C/C++, Felix and Scheme

all rolled together .. :)


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to