title: Ambiguity resolution when making a C++ parser
body: <p>I wrote a LALR(1) parser for C++17. I found <strong>156</strong> ambiguities, some of them I can resolve it according to standard but the others I can't.</p>
  
  <p>For example:
  Shift-Reduce conflict occurs while parsing "<em>operator+ &lt; ......</em>" when a <strong>less-than</strong> is encountered:</p>
  
  <p>We may parse it as:</p>
  
  <p>(1)</p>
  
  <p><em>template-id -> operator-function-id  <strong>·</strong> &lt; ...... ></em></p>
  
  <p>or:</p>
  
  <p>(2)</p>
  
  <p><em>unqualified-id -> operator-function-id  <strong>·</em></strong>
  where (1) need shifting but (2) need reducing.</p>
  
  <p>However, the standard have:</p>
  
  <p><em>After name lookup (3.4) finds that a name is a template-name or that an operator-function-id or a literaloperator-id refers to a set of overloaded functions any member of which is a function template, if this is followed by a &lt;, the &lt; is always taken as the delimiter of a template-argument-list and never as the less-than operator. When parsing a template-argument-list, the first non-nested >137 is taken as the ending delimiter rather than a greater-than operator.</em></p>
  
  <p>So we choose to shift.</p>
  
  <p>Unfortunately, there are many ambiguities I can't find the resolution. Here I list some of them(Some of them can clearly make choice but I just can't find the proof):</p>
  
  <ol>
  <li>Are there some portion in standard that indicates "shifting" is the default choice when ambiguity occurs?</li>
  </ol>
  
  <p><strong>Declarator</strong></p>
  
  <p>(1)when a noptr-declarator is parsed and a left-paren is encountered, I should reduce it according to:</p>
  
  <p><em>ptr-declarator -> noptr-declarator  <strong>·</em></strong> </p>
  
  <p>or shift the left-paren to satisfy:</p>
  
  <p><em>declarator -> noptr-declarator <strong>·</strong> parameters-and-qualifiers</em></p>
  
  <p><em>parameters-and-qualifiers ->  <strong>·</strong> left-paren parameter-declaration-clause right-paren......</em></p>
  
  <p>(2)when a declarator-id is parsed and a left-bracket is encountered, I should reduce it according to:</p>
  
  <p><em>noptr-declarator -> declarator-id  <strong>·</em></strong> 
  <em>noptr-declarator -> noptr-declarator <strong>·</strong> \left-bracket ?constant-expression \right-bracket ?attribute-specifier-seq</em></p>
  
  <p>or shift the left-square to satisfy:</p>
  
  <p><em>noptr-declarator -> declarator-id ·attribute-specifier-seq</em></p>
  
  <p>(attribute-specifier-seq is [[.......]])</p>