/* Grammar of a mini procedural programming language */ Grammar minilang; Lexer l = 'a'..'z'|'A'..'Z'|'_'; d = '0'..'9'; id = l (l|d)*; int = d+; str = '"' (Any - '"')* '"'; blank = ' ' | '\n' | '\t'; Parser Ignored blank; prog = s*; s = {assign:} id '=' e ';' | {print:} 'print' '(' e ')' ';' | {print_str:} 'print' '(' str ')' ';' | {println:} 'println' '(' ')' ';' | {while:} 'while' '(' c ')' stmts | {if:} 'if' '(' c ')' [then:]stmts else? ; stmts = '{' s* '}' ; else = 'else' stmts; e = {lit:} int | {par:} '(' e ')' | {var:} id | {read:} 'read' '(' ')' Unary {neg:} '-' e Left {mul:} [left:]e '*' [right:]e | {div:} [left:]e '/' [right:]e Right {add:} [left:]e '+' [right:]e | {sub:} [left:]e '-' [right:]e ; c = {eq:} [left:]e '=' [right:]e | {ne:} [left:]e '!=' [right:]e | {lt:} [left:]e '<' [right:]e | {le:} [left:]e '<=' [right:]e | {gt:} [left:]e '>' [right:]e | {ge:} [left:]e '>=' [right:]e Unary {not:} 'not' c Left {and:} [left:]c '&&' [right:]c Left {or:} [left:]c '||' [right:]c ;