title: AntLR4 : Build A function
body: <p>I've been trying to build a function: <code>concat('A','B') OR concat('A',9)</code></p>
  
  <p>Here is a sample grammar I have written :</p>
  
  <pre><code>    LPAREN : '(' ;
      RPAREN : ')' ;
      FUNCTIONNAME : 'CONCAT' ;
      ARGUMENTS : TEXT (',' TEXT)* ;
      TEXT : ('a'..'z' | '0'..'9' | 'A'..'Z')+; 
      allFunction : FUNCTIONNAME LPAREN ARGUMENTS (',' ARGUMENTS)* RPAREN ;
  </code></pre>
  
  <p>But not able to build a tree properly.</p>
  
  <p><strong>Update1</strong>:</p>
  
  <p>Here is the Tree:</p>
  
  <pre><code>  0 null
  -- 11 CONCAT
  -- 4 (
  -- 13 2,5
  -- 5 ) 
  </code></pre>
  
  <p>and the grammar : </p>
  
  <pre><code>allFunction : FUNCTIONNAME LPAREN ARGUMENTS RPAREN;
  </code></pre>
  
  <p><strong>Update2</strong> :</p>
  
  <p>Grammar:</p>
  
  <pre><code>allfunction : COMMA | FUNCTIONNAME LPAREN ARGUMENTS (COMMA ARGUMENTS)* RPAREN ;
  </code></pre>
  
  <p>Parsed output: </p>
  
  <p>CONCAT(A,B,C)</p>
  
  <pre><code>[@0,0:5='CONCAT',&lt;8&gt;,1:0]
  [@1,6:6='(',&lt;1&gt;,1:6]
  [@2,7:11='A,B,C',&lt;9&gt;,1:7]
  [@3,12:12=')',&lt;2&gt;,1:12]
  [@4,13:14='\n\n',&lt;7&gt;,1:13]
  [@5,15:14='&lt;EOF&gt;',&lt;-1&gt;,3:0]
  </code></pre>
  
  <p><strong>Update3</strong> :</p>
  
  <p>I have been tring to build a function : 
  <code>CONCAT(TEXT,TEXT)</code> -(Input limited to 2 params). This works fine.
  I have implemented IF function : <code>IF(TEXT,TEXT,TEXT)</code> - This also works fine.</p>
  
  <p>The problem is,
  I have to modify it to: <code>IF(BOOLEAN,INT,INT)</code> - But with existing grammar for any parameter in IF, it can accept UNSIGNED_INT including the first parameter.</p>
  
  <p><strong>Grammar</strong>: </p>
  
  <p>Here is the link: 
  <a href="https://ufile.io/undqs" rel="nofollow noreferrer">https://ufile.io/undqs</a> or  <a href="https://files.fm/u/7c44aaee" rel="nofollow noreferrer">https://files.fm/u/7c44aaee</a></p>