2007-11-26 21:56:26 -05:00
|
|
|
! Copyright (C) 2007 Chris Double.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-03-03 15:32:37 -05:00
|
|
|
USING: kernel arrays strings math.parser sequences
|
2008-03-19 21:22:14 -04:00
|
|
|
peg peg.ebnf peg.parsers memoize namespaces math ;
|
2007-11-26 21:56:26 -05:00
|
|
|
IN: peg.pl0
|
|
|
|
|
|
|
|
#! Grammar for PL/0 based on http://en.wikipedia.org/wiki/PL/0
|
2007-11-26 22:45:32 -05:00
|
|
|
|
2009-03-31 23:03:28 -04:00
|
|
|
EBNF: pl0
|
2008-04-01 22:47:30 -04:00
|
|
|
|
2009-03-31 23:03:28 -04:00
|
|
|
block = { "CONST" ident "=" number { "," ident "=" number }* ";" }?
|
|
|
|
{ "VAR" ident { "," ident }* ";" }?
|
|
|
|
{ "PROCEDURE" ident ";" { block ";" }? }* statement
|
|
|
|
statement = { ident ":=" expression
|
|
|
|
| "CALL" ident
|
|
|
|
| "BEGIN" statement { ";" statement }* "END"
|
|
|
|
| "IF" condition "THEN" statement
|
|
|
|
| "WHILE" condition "DO" statement }?
|
2008-04-28 22:15:05 -04:00
|
|
|
condition = { "ODD" expression }
|
|
|
|
| { expression ("=" | "#" | "<=" | "<" | ">=" | ">") expression }
|
2009-03-31 23:03:28 -04:00
|
|
|
expression = {"+" | "-"}? term { {"+" | "-"} term }*
|
|
|
|
term = factor { {"*" | "/"} factor }*
|
2008-04-28 22:15:05 -04:00
|
|
|
factor = ident | number | "(" expression ")"
|
|
|
|
ident = (([a-zA-Z])+) => [[ >string ]]
|
2008-04-01 22:47:30 -04:00
|
|
|
digit = ([0-9]) => [[ digit> ]]
|
2008-04-28 22:15:05 -04:00
|
|
|
number = (digit)+ => [[ 10 digits>integer ]]
|
|
|
|
program = { block "." }
|
2008-03-20 00:11:09 -04:00
|
|
|
;EBNF
|