mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Added pl0.peg.
This commit is contained in:
parent
9d5b5027e3
commit
0e70fc94f8
35
grammar/pl0.peg
Normal file
35
grammar/pl0.peg
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
program <- block '.' _
|
||||||
|
|
||||||
|
block <- const var procedure statement
|
||||||
|
const <- ('CONST' _ ident '=' _ number (',' _ ident '=' _ number)* ';' _)?
|
||||||
|
var <- ('VAR' _ ident (',' _ ident)* ';' _)?
|
||||||
|
procedure <- ('PROCEDURE' _ ident ';' _ block ';' _)*
|
||||||
|
|
||||||
|
statement <- (assignment / call / statements / if / while / write)?
|
||||||
|
assignment <- ident ':=' _ expression
|
||||||
|
call <- 'CALL' _ ident
|
||||||
|
statements <- 'BEGIN' _ statement (';' _ statement )* 'END' _
|
||||||
|
if <- 'IF' _ condition 'THEN' _ statement
|
||||||
|
while <- 'WHILE' _ condition 'DO' _ statement
|
||||||
|
out <- '!' _ expression
|
||||||
|
|
||||||
|
condition <- odd / compare
|
||||||
|
odd <- 'ODD' _ expression
|
||||||
|
compare <- expression compare_op expression
|
||||||
|
compare_op <- < '=' / '#' / '<=' / '<' / '>=' / '>' > _
|
||||||
|
|
||||||
|
expression <- sign term (term_op term)*
|
||||||
|
sign <- < [-+]? > _
|
||||||
|
term_op <- < [-+] > _
|
||||||
|
|
||||||
|
term <- factor (factor_op factor)*
|
||||||
|
factor_op <- < [*/] > _
|
||||||
|
|
||||||
|
factor <- ident / number / '(' _ expression ')' _
|
||||||
|
|
||||||
|
ident <- < [a-z] ([a-z] / [0-9])* > _
|
||||||
|
number <- < [0-9]+ > _
|
||||||
|
|
||||||
|
~_ <- [ \t\r\n]*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user