title: LBNF, C function declaration / definition, reduce reduce conflict
body: <p>I'm trying to represent in LBNF that C/C++ function declarations have the following (approximate) form (<code>&lt;sym&gt;</code> denotes optionallity, and [rule] is a zero-or-more list):</p>
  
  <pre><code>type ident ( [type &lt;id&gt;] );
  </code></pre>
  
  <p>While function definitions have the form:</p>
  
  <pre><code>type ident ( [type id] ) { [stmt] }
  </code></pre>
  
  <p>Currently, I have the following LBNF:</p>
  
  <pre><code>entrypoints Program ;
  Program.   Program ::= [TopDef] ;
  
  FnDef.     TopDef ::= Type Ident "(" [Arg] ")" Block ;
  FnDecl.    TopDef ::= Type Ident "(" [Par] ")" ";" ;
  separator nonempty TopDef "" ;
  
  Param.     Par ::= Type ;
  NParam.    Par ::= Type Ident ;
  separator Par "," ;
  
  Arg.       Arg ::= Type Ident;
  separator  Arg "," ;
  
  -- Types ---------------------------------------------------
  
  Int.       Type ::= "int" ;
  --- more types...
  separator  Type "," ;
  </code></pre>
  
  <p>Which causes reduce/reduce conflicts as expected.
  Is there a way to solve this in the parser / lexer?</p>
  
  <p>I could solve it with the following grammar:</p>
  
  <pre><code>FnDef.     TopDef ::= Type Ident "(" [Arg] ")" Block ;
  FnDecl.    TopDef ::= Type Ident "(" [Arg] ")" ";" ;
  separator nonempty TopDef "" ;
  
  Arg.       Arg ::= Type Ident;
  Arg.       Arg ::= Type;
  separator  Arg "," ;
  </code></pre>
  
  <p>And then check in the type checker that function definitions have identifiers for each argument, but this feels less satisfying...</p>
  
  <p>How is this typically handled in a language like C ?</p>