Not Quite Perl Not Quite Perl - A lightweight Perl 6 #23

Compiler with operator precedence parsing

grammar ABC::Grammar is HLL::Grammar {
    rule TOP { <EXPR> }

    token term:sym<value>    { <integer> }

    token circumfix:sym<( )> { '(' <.ws> <EXPR> ')' }

    token prefix:sym<->  { '-'  <O(':prec<3>, :assoc<unary>, :pirop<neg>')> }
    token infix:sym<*>   { '*'  <O(':prec<2>, :pirop<mul>')> }
    token infix:sym</>   { '/'  <O(':prec<2>, :pirop<div>')> }
    token infix:sym<+>   { '+'  <O(':prec<1>, :pirop<add>')> }
    token infix:sym<->   { '-'  <O(':prec<1>, :pirop<sub>')> }
}
Copyright © 2010
http://www.pmichaud.com/2010/pres/