]> gitweb.factorcode.org Git - factor.git/blob - extra/peg/pl0/pl0.factor
calendar.format: make duration>human-readable more human readable
[factor.git] / extra / peg / pl0 / pl0.factor
1 ! Copyright (C) 2007 Chris Double.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: math.parser multiline peg.ebnf strings ;
4 IN: peg.pl0
5
6 ! Grammar for PL/0 based on https://en.wikipedia.org/wiki/PL/0
7
8 EBNF: pl0 [=[
9
10 block       =  { "CONST" ident "=" number { "," ident "=" number }* ";" }?
11                { "VAR" ident { "," ident }* ";" }?
12                { "PROCEDURE" ident ";" { block ";" }? }* statement
13 statement   =  {  ident ":=" expression
14                 | "CALL" ident
15                 | "BEGIN" statement { ";" statement }* "END"
16                 | "IF" condition "THEN" statement
17                 | "WHILE" condition "DO" statement }?
18 condition   =  { "ODD" expression }
19              | { expression ("=" | "#" | "<=" | "<" | ">=" | ">") expression }
20 expression  = {"+" | "-"}? term { {"+" | "-"} term }*
21 term        = factor { {"*" | "/"} factor }*
22 factor      = ident | number | "(" expression ")"
23 ident       = (([a-zA-Z])+)   => [[ >string ]]
24 number      = ([0-9])+        => [[ string>number ]]
25 program     = { block "." }
26 ]=]