
a2asm.bnf

This is a mostly complete BNF description of the language
accepted by the a2asm assembler. Notice that "instruction"
and "arguments" are left undefined, as well as some other
hopefully obvious stuff.

===========================================================

program:
    line '\n'
    | program line '\n'
    ;

line:
    unlabeled_line
    | identifier unlabeled_line
    | identifier ':' unlabeled_line
    | identifier '=' i_value
    | identifier '.equ' i_value
    ;

unlabeled_line:
        /* empty */

    | instruction arguments

    | '.hibit' i_value
    | '.expand' i_value

    | '.code'                       
    | '.data'                       
    | '.bss'                        

    | '.assert' i_value

    | '.align' i_value

    | '.global' id_list
    | '.export' id_list

    | '.import' id_list
    | '.extern' id_list
    | '.zimport' id_list

    | '.byte' iv_list
    | '.word' iv_list
    | '.dbyt' iv_list
    | '.long' iv_list
    | '.int' iv_list

    | '.zero'  i_value

    | '.ascii' t_value
    | '.asciz' t_value
    | '.dci' t_value

    | '.float' f_list

    | '.space' i_value
    | '.ds' i_value

    | '.if' i_value
    | '.else'
    | '.endif'
    ;

i_value:
    const_int
    | '[' i_value ']'
    | const_int '?' i_value ':' i_value
    | '*'
    | identifier
    | i_value '+' i_value
    | i_value '-' i_value
    | '!' i_value                   
    | '~' i_value                   
    | i_value '*' i_value           
    | i_value '/' i_value           
    | i_value '%' i_value           
    | i_value '+' i_value           
    | i_value '-' i_value           
    | i_value '>>' i_value          
    | i_value '<<' i_value          
    | i_value '&&' i_value          
    | i_value '||' i_value          
    | i_value '&' i_value           
    | i_value '^' i_value           
    | i_value '|' i_value           
    | i_value '==' i_value          
    | i_value '!=' i_value          
    | i_value '<' i_value           
    | i_value '<=' i_value          
    | i_value '>' i_value           
    | i_value '>=' i_value          
    ;

const_int:
    intlit                          
    | '+' intlit                  
    | '-' intlit                  
    | charlit                       
    ;

f_value:
    i_value
    | floatlit                      
    | '+' floatlit                  
    | '-' floatlit                  
    ;

t_value:
    textlit
    | textlit textlit
    ;

id_list:
    identifier
    | id_list ',' identifier
    ;

iv_list:
    i_value
    | id_list ',' i_value
    ;

f_list:
    f_value
    | f_list ',' f_value
    ;

