On Wed, Nov 10, 2010 at 12:47 AM, Shaping <shap...@charter.net> wrote:
> I tried the first two yellow blocks in this article
>
> http://www.bluishcoder.co.nz/2007/11/embedded-grammars-in-factor.html

The syntax has changed quite a bit since that post. The example would
now be something like:

  EBNF: expr
  digit = '1' | '2' | '3' | '4'
  number = digit digit*
  expr = number (('+' | '-') number)*
  ;EBNF

Then:
  "123+456" expr

Will result in a parse tree left on the stack. The EBNF: name ...
;EBNF expression results in a word with 'name' defined that parses the
given grammar.

You can also do:

<EBNF
digit = '1' | '2' | '3' | '4'
number = digit digit*
expr = number (('+' | '-') number)*
EBNF>

This leaves a parser object on the stack which you can call 'parse' on:

"123" over parse .

Or:

"123" [EBNF
digit = '1' | '2' | '3' | '4'
number = digit digit*
expr = number (('+' | '-') number)*
EBNF] .


The [EBNF ... EBNF] creates an anonymous quotation and calls it. This
is useful for small regexp style grammars:

"123" [EBNF digit=[0-9] => [[ digit> ]] rule=digit+ EBNF] .

>
> Why have you color-coded the "parse" words in the HTML?

The blog was originally hosted on a server that linked to the factor
documentation for some of the words (like 'parse'). The links are dead
now.

Chris.
-- 
http://www.bluishcoder.co.nz

------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to