factor/extra/peg/pl0/pl0.factor

27 lines
1.0 KiB
Factor
Raw Normal View History

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
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
EBNF: pl0
2008-03-19 21:06:21 -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 |
2008-03-19 21:06:21 -04:00
"WHILE" condition "DO" statement )?
condition = "ODD" expression |
expression ("=" | "#" | "<=" | "<" | ">=" | ">") expression
2008-03-19 21:06:21 -04:00
expression = ("+" | "-")? term (("+" | "-") term )*
term = factor (("*" | "/") factor )*
factor = ident | number | "(" expression ")"
ident = (([a-zA-Z])+) [[ >string ]]
digit = ([0-9]) [[ digit> ]]
number = ((digit)+) [[ unclip [ swap 10 * + ] reduce ]]
program = block "."
;EBNF