grammar PIR::Grammar;

# This file contains helper rules to handle
# the PASM instruction arguments. Many instructions
# share the same 'format' of arguments (i.e. instructions
# taking an int constant and a string constant). Handling
# syntax checking in a central place may make the generated
# parser shorter.
#
# Having these rules in a separate file makes compiling 
# faster.
#

rule arg_string {
    <id> 
  | <string_constant> 
  | <string_reg>   
}

rule arg_int {
    <id> 
  | <int_constant> 
  | <int_reg>   
}

rule arg_int_var {
  [ <id> | <int_reg> ]
}

rule arg_pmc_var {
    <id>
  | <pmc_reg> 
}

rule arg_exp_exp_lab {
  <simple_expr> 
  [ \, | <syntax_error: '\',\' expected'> ]
  <simple_expr> 
  [ \, | <syntax_error: '\',\' expected'> ]
  <id> 
}

rule isXX_args {
  [ <int_reg> | <id> ]
  [ ','           | <syntax_error: '\',\' expected'> ]
  [ <simple_expr> | <syntax_error: 'simple expr expected'> ]
  [ ','           | <syntax_error: '\',\' expected'> ]
  [ <simple_expr> | <syntax_error: 'simple expr expected'> ]
}

rule arg_get_params { 
  <param_flag_list> <arg_pmc_var_list>?
}

rule param_flag_list {
  [ \" | \' | <syntax_error: '\'"\' expected'> ]
  [ \(      | <syntax_error: '\'(\' expected'> ]
  <pasm_param_flags>?
  [ \)      | <syntax_error: '\')\' expected'> ]  
  [ \" | \' | <syntax_error: 'closing quote expected'> ]
  [ \, | <syntax_error: '\',\' expected'> ]   
}

rule arg_pmc_var_list {
  <id> | <pmc_reg> [ \, <id> | <pmc_reg> ]*
}


rule arg_hack {
  [ <simple_expr> [ \, <simple_expr> ]* ]?
}

# FIX the flags
rule pasm_param_flags {
  <int_constant> [ \, <int_constant> ]*
}

# fix the arguments
rule arg_set_args {
  <arg_hack>
}

rule arg_set_returns {
  <arg_hack>
}

rule arg_get_results {
  <arg_hack>
}
