Perl 6 / Parrot Parrot Compiler Toolkit #11

calc example - grammar

grammar Calc::Grammar;

token TOP { <statement> }

rule statement { <term> <addop> <term> }

token term { \d+ }

token addop { '+' | '-' }

TOP regex indicates where parsing begins

rule parses spaces, token doesn't

For more, read S05, see other grammar examples

Copyright © 2009
http://www.pmichaud.com/2009/pres/