Hi Alan,

My way of specifying syntax is outlined here:

http://www.romanredz.se/papers/CSP2009.Mouse.pdf

and described with all details here:

http://mousepeg.sourceforge.net/Mouse-1.2.manual.pdf

The main idea is to place semantic actions in a separate file (Java class in this case), so that it does not obscure the grammar. The grammar contains only the names of actions in curly brackets. This style was used with yacc++ by my colleague Bertil Steinholtz to produce very clear code. He could also use different semantic files to produce different semantics for the same grammar.

--  Roman

On 2010-11-15 15:32, Alan Post wrote:
I'm implementing a packrat parser in Scheme.  I'm at the point of
writing a bootstrap parser in Scheme for PEG, and my bootstrap
parser is basically working.

I haven't yet decided on the syntax for embedding code in the
parser.  My only example for doing this is peg/leg:

   http://piumarta.com/software/peg/peg.1.html

which encloses code in {} brackets and permits references to parts
of the parse tree with<>:

   { action }
      Curly braces surround actions.  The action is arbitray C  source
      code  to  be executed at the end of matching.  Any braces within
      the action must be properly nested.  Any  input  text  that  was
      matched  before  the action and delimited by angle brackets (see
      below) is made available within the action as  the  contents  of
      the character array yytext.  The length of (number of characters
      in) yytext is available in the variable yyleng.  (These variable
      names are historical; see lex(1).)

   <   An opening angle bracket always matches (consuming no input) and
      causes the parser to begin accumulating matched text.  This text
      will be made available to actions in the variable yytext.

   >   A  closing angle bracket always matches (consuming no input) and
      causes the parser to stop accumulating text for yytext.

What else is out there?  Is this something reasonably standard or does
every tool do something different?

-Alan
_______________________________________________
PEG mailing list
[email protected]
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to