title: Looping a Parsing Step in PLY Python 3
body: <p>I am currently using python 3 to parse a programming language that I am making. I am wondering how I can make a parsing rule loop.</p>
  
  <p>That may be unclear, so here is an example.</p>
  
  <p>I have the code:</p>
  
  <pre><code>def c_parse():
      def p_program(p):
          "program : actions"
          p[0] = ("PROGRAM", p[1])
  
      def p_actions(p):
          """actions : action
                     | actions action"""
          if len(p) == 3:
              p[0] = ("ACTIONS", p[1], p[2])
          elif len(p) == 2:
              p[0] = ("ACTION", p[1])
  
      def p_action(p):
          """action : function_call ';'
                    | variable_dec ';'
                    | if_statement ';'"""
          p[0] = ("ACTION_STATEMENT", p[1])
  
      ...
  </code></pre>
  
  <p>Given the input:</p>
  
  <pre><code>x = "HELLO WORLD";
  print(x);
  print(x);
  </code></pre>
  
  <p>This outputs this AST:</p>
  
  <pre><code>('PROGRAM', ('ACTIONS', ('ACTIONS', ('ACTION', ('ACTION_STATEMENT', 
  ('VARIABLE_DEC', ... ))), 
  ('ACTION_STATEMENT', ('FUNCTION_CALL', ... ))), ('ACTION_STATEMENT', 
  ('FUNCTION_CALL', ... ))))
  </code></pre>
  
  <p>Notice how the ACTIONS and ACTION_STATEMENT are extremely messy. This happens because of the recursive rule defined in the p_actions() function. Is there a way where I could just get a nice and clean AST like this:</p>
  
  <pre><code>(PROGRAM, (ACTION, (VARIABLE_DEC, ... )), (ACTION, (FUNCTION_CALL, ... )),
  (ACTION, (FUNCTION_CALL, ...)))
  </code></pre>
  
  <p>In other words, can I make the p_actions() function be able to parse an infinite amount of ACTION nodes without using recursion? Is this possible?</p>
  
  <p>BTW I'm on macOS if it matters.</p>