grammar PIR::Grammar;

rule io_op {
  #                   
  # IO ops            
  #                   
  close               <var>
| fdopen              <var> \, <simple_expr> \, [ <string_constant> | <string_reg> | <id> ]
| getstdin            <var>
| getstdout           <var>
| getstderr           <var>
| setstdout           <var>
| setstderr           <var>
| pioctl              <var> \, <var> \, <simple_expr> \, <simple_expr>
| open                <var> \, <var> [ \, <var> ]?
| printerr            <simple_expr>
| print               <simple_expr>
| print               <var> \, <simple_expr>
| read                <var> \, <simple_expr>
| readline            <var> \, <var>
| peek                <var> [ \, <var> ]?
| stat                <var> \, <var> \, <simple_expr>
| seek                <var> \, <simple_expr> \, <simple_expr> [ \, <simple_expr> ]?
| tell                <var> \, <var> [ \, <var> ]?
| socket              <var> \, <simple_expr> \, <simple_expr> \, <simple_expr> \, <simple_expr>
| sockaddr            <var> \, <simple_expr> \, <simple_expr>
| connect             <var> \, <var> \, <simple_expr>
| recv                <var> \, <var> \, <simple_expr>
| send                <var> \, <var> \, <simple_expr>
| poll                <var> \, <var> \, <simple_expr> \, <simple_expr> \, <simple_expr>
| bind                <var> \, <var> \, <simple_expr>
| listen              <var> \, <var> \, <simple_expr>
| accept              <var> \, <var>
}

rule math_op {
  #
  # Math ops
  #
  abs                 <var>
| add                 <var> \, <simple_expr> [ \, <simple_expr> ]?
| cmod                <var> \, <simple_expr> \, <simple_expr>
| dec                 <arg_hack> #
| div                 <arg_hack> #
| fdiv                <arg_hack> #
| ceil                <arg_hack> #
| floor               <arg_hack> #
| inc                 <arg_hack> #
| mod                 <arg_hack> #
| mul                 <arg_hack> #
| neg                 <arg_hack> #
| pow                 <arg_hack> #
| sub                 <arg_hack> #
| sqrt                <arg_hack> #
  # Transcedental math. ops; shouldn't these go into a lib?
| acos                <arg_hack> #
| asec                <arg_hack> #
| asin                <arg_hack> #
| atan                <arg_hack> #
| cos                 <arg_hack> #
| cosh                <arg_hack> #
| exp                 <arg_hack> #
| ln                  <arg_hack> #
| log10               <arg_hack> #
| log2                <arg_hack> #
| sec                 <arg_hack> #
| sech                <arg_hack> #
| sin                 <arg_hack> #
| sinh                <arg_hack> #
| tan                 <arg_hack> #
| tanh                <arg_hack> #
  # other math ops    
| gcd                 <arg_hack> #
| lcm                 <arg_hack> #
| fact                <arg_hack> #
}

rule string_op {
  #                   
  # String ops        
  #                   
  ord                 <arg_hack> #
| chr                 <arg_hack> #
| chopn               <arg_hack> #
| concat              <var> \, <simple_expr> [ \, <simple_expr> ]?
| n_concat            <arg_hack> #
| repeat              <arg_hack> #
| n_repeat            <arg_hack> #
| length              <arg_hack> #
| bytelength          <arg_hack> #
| pin                 <arg_hack> #
| unpin               <arg_hack> #
| substr              <arg_hack> #
| index               <arg_hack> #
| sprintf             <arg_hack> #
| new # ??            <arg_hack> #
| stringinfo          <arg_hack> #
| upcase              <arg_hack> #
| downcase            <arg_hack> #
| titlecase           <arg_hack> #
| join                <arg_hack> #
| split               <arg_hack> #
| charset             <arg_hack> #
| charsetname         <arg_hack> #
| find_charset        <arg_hack> #
| trans_charset       <arg_hack> #
| encoding            <arg_hack> #
| find_encoding       <arg_hack> #
| trans_encoding      <arg_hack> #
| is_cclass           <arg_hack> #
| find_cclass         <arg_hack> #
| find_not_cclass     <arg_hack> #
| escape              <arg_hack> #
| compose             <arg_hack> #
}
