1 ! Copyright (C) 2007 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel arrays strings math.parser sequences
4 peg peg.ebnf peg.parsers memoize namespaces math ;
7 #! Grammar for PL/0 based on http://en.wikipedia.org/wiki/PL/0
11 block = { "CONST" ident "=" number { "," ident "=" number }* ";" }?
12 { "VAR" ident { "," ident }* ";" }?
13 { "PROCEDURE" ident ";" { block ";" }? }* statement
14 statement = { ident ":=" expression
16 | "BEGIN" statement { ";" statement }* "END"
17 | "IF" condition "THEN" statement
18 | "WHILE" condition "DO" statement }?
19 condition = { "ODD" expression }
20 | { expression ("=" | "#" | "<=" | "<" | ">=" | ">") expression }
21 expression = {"+" | "-"}? term { {"+" | "-"} term }*
22 term = factor { {"*" | "/"} factor }*
23 factor = ident | number | "(" expression ")"
24 ident = (([a-zA-Z])+) => [[ >string ]]
25 digit = ([0-9]) => [[ digit> ]]
26 number = (digit)+ => [[ 10 digits>integer ]]
27 program = { block "." }