FICL will do what you want. See this page in the FICL documentation: http://ficl.sourceforge.net/parsesteps.html
FICL has a lot of limitations, especially in regard to floating-point support, but if you are willing to write wrappers for C functions as necessary, it will work. Briefly, the doc says this about parsing: Unlike every other FORTH we know of, Ficl features an extensible parser chain. The Ficl parser is not a monolithic function; instead, it is comprised of a simple tokenizer and a series of parse steps. A parse step is a step in the parser chain that handles a particular kind of token, acting on the token as appropriate. Example parse steps, in terms of traditional FORTH lore, would be the "number runner" and the "colon compiler". ... Parse steps can be written as native functions, or as Ficl script functions. New parse steps can be appended to the chain at any time. > > Message: 4 > Date: Thu, 17 Sep 2009 17:53:33 +0100 > From: Paul Moore <[email protected]> > Subject: [Factor-talk] Is it possible to define new literal forms? > To: Factor <[email protected]> > Message-ID: > <[email protected]> > Content-Type: text/plain; charset=ISO-8859-1 > > This is mostly just curiosity, but is it possible to hook into > Factor's parser/lexer to define new forms of literal? I know it's > possible to write parsing words like V{ but I'm more interested in > "standalone" forms like rationals 2/3. From what I can tell, rational > syntax is hard-wired into Factor's parser as part of string>number. I > don't see an easy way to extend it. > > The background is that I'm playing with ideas around game simulation > programs, where die rolls are a common need. I can obviously write a > word dieroll ( n m -- roll ) to roll n m-sided dice and produce a > result - but where n and m are literals (as they often are) the usual > syntax is nDm (for example, 3D6) and it'd be nice to be able to > express that directly in Factor. > > Is that possible? From what I recall of old-style forths, it wasn't - > they hard coded the word splitter and numeric parsing code. What I've > been able to dig into with Factor indicates that the parser's > structure is similar, but I could easily have missed something. > > As I say, it's not a big deal (it may never even make it into real > code, it's just ideas) but if anyone can point me at an example, or > tell me it's not possible, that's be nice. > > Paul. ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Factor-talk mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/factor-talk
