=head1 NAME pir.pg - A PIR grammar for PGE. TODO: 1. fix Heredocs parsing 2. Test and fix things Some rules/tokens have names in capitals; these represent the C token. Each such token has also a rule with the same name in lowercase, which does reports a syntax error if the token was not read. For instance, will match a string constant, but will report an error if there was no STRING_CONST token. =cut grammar PIR::Grammar; token TOP { ^ [ $ | ] {*} } rule program { <.NL>* [ <.NL> ]* [ <.NL> | ] {*} } token compilation_unit { | {*} #= expansion | {*} #= sub_def | {*} #= const_def | {*} #= pragma } =head2 Sub defs, sub pragmas, sub body and parameters =cut rule sub_def { '.sub' * <.nl> * * [ '.end' | ] {*} } rule sub_id { | {*} #= IDENT | {*} #= STRING_CONST | } =head3 sub_pragmas =cut rule sub_pragma { | ':load' | ':init' | ':immediate' | ':postcomp' | ':main' | ':anon' | ':lex' | {*} #= vtable_pragma | {*} #= multi_pragma | {*} #= outer_pragma } rule vtable_pragma { ':vtable' ? {*} } rule parenthesized_string { '(' <.right_paren> {*} } rule multi_pragma { ':multi' <.left_paren> ? <.right_paren> {*} } rule left_paren { '(' | } rule right_paren { ')' | } rule outer_pragma { ':outer' <.left_paren> <.right_paren> {*} } rule multi_types { [ ',' ]* } rule multi_type { | {*} #= pir_type | '_' {*} #= any_type | {*} #= keylist | {*} #= ident | {*} #= string_constant } rule param_decl { '.param' <.nl> {*} } rule parameter { | [ '=>' ]? | } rule parameter_flags { [ | ':unique_reg' ]* } =head2 PIR instructions =cut rule labeled_pir_instr { [