1 ! Copyright (C) 2007 Chris Double.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: math.parser multiline peg.ebnf strings ;
6 ! Grammar for PL/0 based on https://en.wikipedia.org/wiki/PL/0
10 block = { "CONST" ident "=" number { "," ident "=" number }* ";" }?
11 { "VAR" ident { "," ident }* ";" }?
12 { "PROCEDURE" ident ";" { block ";" }? }* statement
13 statement = { ident ":=" expression
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 "." }