parrotcode: Untitled | |
Contents | Language Implementations | lolcode |
grammar lolcode::Grammar is PCT::Grammar;
rule TOP { 'HAI' <version> <statement_terminator> <block> 'KTHXBYE' <statement_terminator> [ $ || <panic: Syntax error> ] {*} }
token version { \d+ [ '.' \d+ ]? }
rule statement { | <visible> {*} #= visible | <declare> {*} #= declare | <assign> {*} #= assign | <function> {*} #= function | <ifthen> {*} #= ifthen | <expression> {*} #= bare_expression }
token statement_terminator { [ ',' | \n+ | $ ] }
rule visible { 'VISIBLE' <expression> [ <expression> ]* [$<no_newline>='!']? {*} }
rule declare { 'I' 'HAS' 'A' <variable> [ 'ITZ' <expression> ]? {*} }
rule assign { <variable> 'R' <expression> {*} }
rule function { 'HOW' 'DUZ' 'I' <variable> <statement_terminator> <block> 'IF' 'U' 'SAY' 'SO' {*} }
rule ifthen { <expression> <statement_terminator> 'O' 'RLY?' <statement_terminator> 'YA' 'RLY' <statement_terminator> <block> [ 'MEBBE' <expression> <statement_terminator> <block> ]* [ 'NO' 'WAI' <statement_terminator> $<else>=<block> ]? 'OIC' {*} }
rule switch { <expression> <statement_terminator> 'WTF?' <statement_terminator> [ 'OMG' <value> <statement_terminator> <block> ]+ [ 'OMGWTF' <statement_terminator> <block> ]? 'OIC' }
rule block { [<statement> <statement_terminator>]* {*} }
rule parameters { 'YR' <identifier> [ 'AN' 'YR' <identifier> ]* }
rule expression { | <variable> {*} #= var_or_function | <value> {*} #= value }
rule value { | <float> {*} #= float | <integer> {*} #= integer | <boolean> {*} #= boolean | <quote> {*} #= quote }
rule variable { <identifier> {*} }
token identifier { <!keyword> $<name>=( <[a..zA..Z]> \w* ) {*} }
# RT #46213 : Because PGE doesn't yet know how to do longest token matching, # order all tokens in reverse alpha order to avoid a parsing bug. token keyword { [ 'YR' | 'YA' | 'WTF?' | 'WIN' | 'WAI' | 'VISIBLE' | 'U' | 'SUM' | 'SO' | 'SMALLR' | 'SAY' | 'RLY?' | 'RLY' | 'R' | 'QUOSHUNT' | 'PRODUKT' | 'OMGWTF' | 'OMG' | 'OIC' | 'O' | 'NO' | 'MOD' | 'MEBBE' | 'KTHXBYE' | 'ITZ' | 'IF' | 'I' | 'HOW' | 'HAS' | 'GTFO' | 'FOUND' | 'FAIL' | 'DIFF' | 'BIGGR' | 'AN' | 'A' ] >> }
token integer { '-'? \d+ {*} }
token float { '-'? \d+ '.' \d+ {*} }
rule boolean { [ 'WIN' | 'FAIL' ] {*} }
rule quote { [ <.before '"'> <yarn_literal> ] {*} }
token ws { <!ww> [ | ^^ \h* BTW \h \N* \n+ | ^^ \h* OBTW .*? ^^ \h* TLDR \n+ | \h+ ]* }
|