Fix peg.pl0 test failures
parent
9d0485cd8a
commit
1b58ba404e
|
@ -1,9 +1,54 @@
|
||||||
! Copyright (C) 2007 Chris Double.
|
! Copyright (C) 2007 Chris Double.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
!
|
!
|
||||||
USING: kernel tools.test peg peg.pl0 multiline sequences ;
|
USING: kernel tools.test peg peg.pl0 multiline sequences words assocs ;
|
||||||
IN: peg.pl0.tests
|
IN: peg.pl0.tests
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"CONST foo = 1;" \ pl0 "ebnf-parser" word-prop "block" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"VAR foo;" \ pl0 "ebnf-parser" word-prop "block" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"VAR foo,bar , baz;" \ pl0 "ebnf-parser" word-prop "block" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"foo := 5;" \ pl0 "ebnf-parser" word-prop "statement" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"BEGIN foo := 5; END" \ pl0 "ebnf-parser" word-prop "statement" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"IF 1=1 THEN foo := 5; END" \ pl0 "ebnf-parser" word-prop "statement" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"WHILE 1=1 DO foo := 5; END" \ pl0 "ebnf-parser" word-prop "statement" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"WHILE ODD 1=1 DO foo := 5; END" \ pl0 "ebnf-parser" word-prop "statement" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
"PROCEDURE square; BEGIN squ=x*x END" \ pl0 "ebnf-parser" word-prop "block" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
<"
|
||||||
|
PROCEDURE square;
|
||||||
|
BEGIN
|
||||||
|
squ := x * x
|
||||||
|
END;
|
||||||
|
"> \ pl0 "ebnf-parser" word-prop "block" swap at parse not
|
||||||
|
] unit-test
|
||||||
|
|
||||||
{ t } [
|
{ t } [
|
||||||
<"
|
<"
|
||||||
VAR x, squ;
|
VAR x, squ;
|
||||||
|
|
|
@ -7,18 +7,20 @@ IN: peg.pl0
|
||||||
#! Grammar for PL/0 based on http://en.wikipedia.org/wiki/PL/0
|
#! Grammar for PL/0 based on http://en.wikipedia.org/wiki/PL/0
|
||||||
|
|
||||||
EBNF: pl0
|
EBNF: pl0
|
||||||
block = ( "CONST" ident "=" number ( "," ident "=" number )* ";" )?
|
- = (" " | "\t" | "\n")+ => [[ drop ignore ]]
|
||||||
( "VAR" ident ( "," ident )* ";" )?
|
_ = (" " | "\t" | "\n")* => [[ drop ignore ]]
|
||||||
( "PROCEDURE" ident ";" ( block ";" )? )* statement
|
block = ( _ "CONST" - ident _ "=" _ number ( _ "," _ ident _ "=" _ number )* _ ";" )?
|
||||||
statement = ( ident ":=" expression | "CALL" ident |
|
( _ "VAR" - ident ( _ "," _ ident )* _ ";" )?
|
||||||
"BEGIN" statement (";" statement )* "END" |
|
( _ "PROCEDURE" - ident _ ";" ( _ block _ ";" )? )* _ statement
|
||||||
"IF" condition "THEN" statement |
|
statement = ( ident _ ":=" _ expression | "CALL" - ident |
|
||||||
"WHILE" condition "DO" statement )?
|
"BEGIN" - statement ( _ ";" _ statement )* _ "END" |
|
||||||
condition = "ODD" expression |
|
"IF" - condition _ "THEN" - statement |
|
||||||
expression ("=" | "#" | "<=" | "<" | ">=" | ">") expression
|
"WHILE" - condition _ "DO" - statement )?
|
||||||
expression = ("+" | "-")? term (("+" | "-") term )*
|
condition = "ODD" - expression |
|
||||||
term = factor (("*" | "/") factor )*
|
expression _ ("=" | "#" | "<=" | "<" | ">=" | ">") _ expression
|
||||||
factor = ident | number | "(" expression ")"
|
expression = ("+" | "-")? term ( _ ("+" | "-") _ term )*
|
||||||
|
term = factor ( _ ("*" | "/") _ factor )*
|
||||||
|
factor = ident | number | "(" _ expression _ ")"
|
||||||
ident = (([a-zA-Z])+) [[ >string ]]
|
ident = (([a-zA-Z])+) [[ >string ]]
|
||||||
digit = ([0-9]) [[ digit> ]]
|
digit = ([0-9]) [[ digit> ]]
|
||||||
number = ((digit)+) [[ unclip [ swap 10 * + ] reduce ]]
|
number = ((digit)+) [[ unclip [ swap 10 * + ] reduce ]]
|
||||||
|
|
Loading…
Reference in New Issue