Every time I run my parser, it always has at least one unreachable 
nonterminal. Looking at the grammar that felix generates, it's easy to 
see the problem:

nonterm(_poly_3928t_6311*) elk_1 {
  -> t:TOK_TEXT
    {
       _poly_3928t_6311 *_x = new 
_poly_3928t_6311(_nt_1007_1009(FLX_FPAR_PASS ptrcompile)
      .apply(*t));
       return _x;
    }
}
nonterm(_poly_3928t_6311*) _nt_1007 {
  fun dup(x) { return new _poly_3928t_6311(*x); }
  fun del(x) { delete x; }
  -> t:TOK_TEXT
    {
       _poly_3928t_6311 *_x = new 
_poly_3928t_6311(_nt_1007_1009(FLX_FPAR_PASS ptrcompile)
      .apply(*t));
       return _x;
    }
}

If I read elkhound correctly, felix is generating the same nonterminal 
twice. The only difference are the two extra functions. Is this a bug?

Also, I've noticed that this doesn't compile:

  parse (fun () => TOK_EOF) with ...

but this does:

  val f = fun () => TOK_EOF;
  parse f with ...


Anyway, here's my program:

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

open List;
open Lexer;

union node =
  | String_node of string
  | Variable_node of string
;

union token_t =
  | TOK_EOF
  | TOK_TEXT of string
;

fun compile (s:string):list[node] = {
  val f = fun () => TOK_EOF;
  var z =
    parse f with
    | t:TOK_TEXT => list(String_node t)
    endmatch
  ;

  return
    match z with
    | case 0 => list(String_node "Error")
    | case 1 (?i) => i
    endmatch
  ;
}

fun str (n:node) =>
  match n with
  | String_node ?s => f"String_node '%S'" s
  | Variable_node ?v => "'Variable_node '%S'" v
  endmatch
;

fun str (ns:list[node]) =>
  '[' + (cat ', ' (map (str of node) ns)) + ']'
;

print $ str $ compile '';
endl;

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to