factor/extra/peg/pl0/pl0.factor

30 lines
1.1 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.
2007-11-29 05:42:46 -05:00
USING: kernel arrays strings math.parser sequences peg peg.ebnf memoize ;
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-29 05:42:46 -05:00
MEMO: ident ( -- parser )
2007-11-26 21:56:26 -05:00
CHAR: a CHAR: z range
CHAR: A CHAR: Z range 2array choice repeat1
[ >string ] action ;
2007-11-29 05:42:46 -05:00
MEMO: number ( -- parser )
2007-11-26 21:56:26 -05:00
CHAR: 0 CHAR: 9 range repeat1 [ string>number ] action ;
2007-11-27 22:07:23 -05:00
<EBNF
program = block '.' .
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 ] .
condition = 'odd' expression |
expression ('=' | '#' | '<=' | '<' | '>=' | '>') expression .
expression = ['+' | '-'] term {('+' | '-') term } .
term = factor {('*' | '/') factor } .
factor = ident | number | '(' expression ')'
EBNF>