rule TOP { ^ <statement_list> [ $ || <panic: 'Syntax error'> ] {*} }

rule statement_list { <statement>? [ ';' <statement>? ]* {*} }

rule statement { | <if_statement> {*} #= if_statement | <while_statement> {*} #= while_statement | <for_statement> {*} #= for_statement | <compound_statement> {*} #= compound_statement | <string> {*} #= string # | 'break' # | 'continue' # | 'halt' # | 'return' [ '(' <expression> ')' ]? | <expression> {*} #= expression }

rule if_statement { 'if' '(' <expression> ')' <statement> [ 'else' <statement> ]? {*} }

rule while_statement { 'while' '(' <expression> ')' <statement> {*} }

rule for_statement { 'for' '(' <expression> ';' <expression> ';' <expression> ')' <statement> {*} }

rule compound_statement { '{' <statement_list> '}' {*} }

token string { '"' <string_literal: '"'> '"' {*} }

## create operator precedence parser rule 'expression' is optable { ... }

## recognize terms token term { | <float> {*} #= float | <integer> {*} #= integer | <variable> {*} #= variable }

token float { [ | \d+ '.' \d* | '.' \d+ ] {*} }

token integer { \d+ {*} }

token variable { $<name>=[ <[a..z]> <[_a..z0..9]>* ] [ '(' <expression> ')' {*} #= call | <.null> {*} #= var ] }

## vim: expandtab sw=4


parrot