Version française
Home     About     Download     Resources     Contact us    
Browse thread
Felix 1.0.20 released
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Felix 1.0.20 released
Felix version 1.0.20 is now stablised and 1.0.21 has been
opened as the development version. Felix is an Algol like
language with a strong functional subsystem and ML like typing.
Available with BSD like FFAU licence from

http://felix.sf.net

This version integrates Scott McPeaks Elkhound GLR parser

http://www.cs.berkeley.edu/~smcpeak/elkhound/

directly in the language. 

A complete (but trivial) working example is given below
to indicate the what the integration looks like.

----------------------------------------------

include "std";
 
// the input string
data := "1+2+3$";
 
// a type for tokens
union token_t =
  | TOK_EOF
  | TOK_PLUS
  | TOK_INT of int
;
 
// a token stream generator
var i = 0;
fun get_token():token_t =
{
  ch := data.[i to i+1];
  ++i;
  tok :=
    match ch with
    | "$" => TOK_EOF
    | "+" => TOK_PLUS
    | "1" => TOK_INT 1
    | "2" => TOK_INT 2
    | "3" => TOK_INT 3
    endmatch
  ;
  return tok;
}
 
// a type for expression terms
union expr_t =
  | Integer of int
;
 
// a grammar for expressions
nonterm expr : expr_t =
| xx:expr TOK_PLUS y:TOK_INT =>
  match xx with
  | Integer ?i => Integer (i+y)
  endmatch
 
| y:TOK_INT => Integer y
;
 
// a parser for our example
var z : 1 + int =
  parse (the get_token) with
  | e: expr => match e with | Integer ?i => i endmatch
  endmatch
;
 
// print the result
match z with
| case 1 => { print "Error"; }
| case 2 (?i) => { print i; }
endmatch;
endl;

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net