Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion simple grammar example
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Aldo Calpini  
View profile  
 More options Jun 9 2004, 10:17 am
Newsgroups: perl.perl6.language
From: d...@perl.it (Aldo Calpini)
Date: Wed, 09 Jun 2004 16:17:33 +0200
Local: Wed, Jun 9 2004 10:17 am
Subject: simple grammar example
hello gentlemen,

I'm preparing a talk about Perl6 for the Italian Perl Workshop, and I
would like to have a slide comparing a BNF (yacc/bison) grammar to a
Perl6 one, to show how powerful in parsing/lexing Perl6 regexen are.

so I ask your assistance in helping me putting up a simple, yet
impressive enough, sample.

I've taken this bison example (an RPN calculator, stripped down version
from http://www.gnu.org/software/bison/manual/html_node/Rpcalc-Rules.html):

  input:    /* empty */
          | input line
  ;

  line:     '\n'
          | exp '\n'
  ;

  exp:      NUM
          | exp exp '+'
          | exp exp '-'
          | exp exp '*'
          | exp exp '/'
  ;
  %%

and this is my attempt at a "port" to Perl6:

  grammar RPN {
      rule input { <line>* }
      rule line { <exp>? \n }
      rule exp {
          [ NUM
          | <exp> <exp> <'+'>
          | <exp> <exp> <'-'>
          | <exp> <exp> <'*'>
          | <exp> <exp> <'/'>
          ]
      }

      rule NUM { \d+ } # could be more complex, I know :-)
  }

  if $data ~~ RPN.input { say "valid RPN data" }

am I missing something obvious here? will the above code work in Perl6?
do you have perhaps a better example, or just an idea about what to show?

cheers,
Aldo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.