Update peg.pl0 to use range pattern syntax
This allows removing the words for ident and number, replacing them with EBNF expressions.db4
parent
68388fbed9
commit
39c228db6d
|
@ -1,18 +1,10 @@
|
|||
! Copyright (C) 2007 Chris Double.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel arrays strings math.parser sequences
|
||||
peg peg.ebnf peg.parsers memoize namespaces ;
|
||||
peg peg.ebnf peg.parsers memoize namespaces math ;
|
||||
IN: peg.pl0
|
||||
|
||||
#! Grammar for PL/0 based on http://en.wikipedia.org/wiki/PL/0
|
||||
MEMO: ident ( -- parser )
|
||||
[
|
||||
CHAR: a CHAR: z range ,
|
||||
CHAR: A CHAR: Z range ,
|
||||
] choice* repeat1 [ >string ] action ;
|
||||
|
||||
MEMO: number ( -- parser )
|
||||
CHAR: 0 CHAR: 9 range repeat1 [ string>number ] action ;
|
||||
|
||||
<EBNF
|
||||
program = block "."
|
||||
|
@ -28,4 +20,7 @@ condition = "ODD" expression |
|
|||
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 ]]
|
||||
EBNF>
|
||||
|
|
Loading…
Reference in New Issue