cpp-peglib/grammar/pl0.peg

38 lines
1.2 KiB
Plaintext
Raw Normal View History

2015-07-30 00:15:09 +00:00
2015-07-30 01:48:28 +00:00
program <- _ block '.' _
2015-07-30 00:15:09 +00:00
block <- const var procedure statement
2015-08-28 02:56:51 +00:00
const <- ('CONST' __ ident '=' _ number (',' _ ident '=' _ number)* ';' _)?
var <- ('VAR' __ ident (',' _ ident)* ';' _)?
procedure <- ('PROCEDURE' __ ident ';' _ block ';' _)*
2015-07-30 00:15:09 +00:00
2015-07-30 01:48:28 +00:00
statement <- (assignment / call / statements / if / while / out / in)?
2015-07-30 00:15:09 +00:00
assignment <- ident ':=' _ expression
2015-08-28 02:56:51 +00:00
call <- 'CALL' __ ident
statements <- 'BEGIN' __ statement (';' _ statement )* 'END' __
if <- 'IF' __ condition 'THEN' __ statement
while <- 'WHILE' __ condition 'DO' __ statement
out <- ('out' __ / 'write' __ / '!' _) expression
in <- ('in' __ / 'read' __ / '?' _) ident
2015-07-30 00:15:09 +00:00
condition <- odd / compare
2015-08-28 02:56:51 +00:00
odd <- 'ODD' __ expression
2015-07-30 00:15:09 +00:00
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 ')' _
2015-08-28 02:56:51 +00:00
ident <- < [a-z] [a-z0-9]* > _
2015-07-30 00:15:09 +00:00
number <- < [0-9]+ > _
~_ <- [ \t\r\n]*
2015-08-28 02:56:51 +00:00
~__ <- ![a-z0-9_] _
2015-07-30 00:15:09 +00:00