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
|
|
|
|
const <- ('CONST' _ ident '=' _ number (',' _ ident '=' _ number)* ';' _)?
|
|
|
|
var <- ('VAR' _ ident (',' _ ident)* ';' _)?
|
|
|
|
procedure <- ('PROCEDURE' _ ident ';' _ block ';' _)*
|
|
|
|
|
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
|
|
|
|
call <- 'CALL' _ ident
|
|
|
|
statements <- 'BEGIN' _ statement (';' _ statement )* 'END' _
|
|
|
|
if <- 'IF' _ condition 'THEN' _ statement
|
|
|
|
while <- 'WHILE' _ condition 'DO' _ statement
|
|
|
|
out <- '!' _ expression
|
2015-07-30 01:48:28 +00:00
|
|
|
in <- '?' _ ident
|
2015-07-30 00:15:09 +00:00
|
|
|
|
|
|
|
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]*
|
|
|
|
|