Skip to main content
Golfed 3 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip -s, 152 150 148 139 137 126 125 123123 120 bytes

YaRs" ("R';')R`\["R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\[)`;]`{c." pointer to"X#b}{[b"is"g@>2a]}Vy^s

Takes the declaration as a command-line input. Try it online!Try it online!

We want the whole declaration to be parenthesized (this helps with the loop later on), so we change type ...; into type (...). Then, observe that no reordering is done with the descriptions of functions and arrays, so we can perform all those replacements first without affecting the final output.

Y                         Yank into y variable...
 a                        The result of a (the cmdline arg)...
  R s                     Replace the space
   " ("                    with " ("
  R ';                    Replace the semicolon
   ')                      with a closing paren
  R `\[(\d+)]`            Replace digits in square brackets
   ` array of \1`          with " array of <digits>"
  R "()"                  Replace function parens
   " function returning"   with " function returning"

If our original input was float *((*p()))[16];, we now have float (*((*p function returning)) array of 16)16;.

L#a                     Loop len(a) times (enough to complete all replacements):
 Y                      Yank into y variable...
  y                     The result of y...
   R `\((\**)(.+)\[)`;]`  Replace open paren, 0 or more asterisks (group 1), 1 or more
                        characters (group 2), and close paren or semicolon
    {                    with this callback function (b = group 1, c = group 2):
     c .                 The stuff in the middle, concatenated to...
      " pointer to"      that string
       X #b              repeated len(asterisks) times
    }
float (*((*p function returning)) array of 16)16;
float ((*p function returning)) array of 16 pointer to
float (*p function returning) array of 16 pointer to
float p function returning pointer to array of 16 pointer to

Pip -s, 152 150 148 139 137 126 125 123 bytes

YaRs" ("R';')R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\)`{c." pointer to"X#b}{[b"is"g@>2a]}Vy^s

Takes the declaration as a command-line input. Try it online!

We want the whole declaration to be parenthesized (this helps with the loop later on), so we change type ...; into type (...). Then, observe that no reordering is done with the descriptions of functions and arrays, so we can perform all those replacements first without affecting the final output.

Y                         Yank into y variable...
 a                        The result of a (the cmdline arg)...
  R s                     Replace the space
   " ("                    with " ("
  R ';                    Replace the semicolon
   ')                      with a closing paren
  R `\[(\d+)]`            Replace digits in square brackets
   ` array of \1`          with " array of <digits>"
  R "()"                  Replace function parens
   " function returning"   with " function returning"

If our original input was float *((*p()))[16];, we now have float (*((*p function returning)) array of 16).

L#a                   Loop len(a) times (enough to complete all replacements):
 Y                    Yank into y variable...
  y                   The result of y...
   R `\((\**)(.+)\)`  Replace open paren, 0 or more asterisks (group 1), 1 or more
                      characters (group 2), and close paren
    {                  with this callback function (b = group 1, c = group 2):
     c .               The stuff in the middle, concatenated to...
      " pointer to"    that string
       X #b            repeated len(asterisks) times
    }
float (*((*p function returning)) array of 16)
float ((*p function returning)) array of 16 pointer to
float (*p function returning) array of 16 pointer to
float p function returning pointer to array of 16 pointer to

Pip -s, 152 150 148 139 137 126 125 123 120 bytes

YaRs" ("R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)[);]`{c." pointer to"X#b}{[b"is"g@>2a]}Vy^s

Takes the declaration as a command-line input. Try it online!

We want the whole declaration to be parenthesized (this helps with the loop later on), so we change type ... into type (.... Then, observe that no reordering is done with the descriptions of functions and arrays, so we can perform all those replacements first without affecting the final output.

Y                         Yank into y variable...
 a                        The result of a (the cmdline arg)...
  R s                     Replace the space
   " ("                    with " ("
  R `\[(\d+)]`            Replace digits in square brackets
   ` array of \1`          with " array of <digits>"
  R "()"                  Replace function parens
   " function returning"   with " function returning"

If our original input was float *((*p()))[16];, we now have float (*((*p function returning)) array of 16;.

L#a                     Loop len(a) times (enough to complete all replacements):
 Y                      Yank into y variable...
  y                     The result of y...
   R `\((\**)(.+)[);]`  Replace open paren, 0 or more asterisks (group 1), 1 or more
                        characters (group 2), and close paren or semicolon
    {                    with this callback function (b = group 1, c = group 2):
     c .                 The stuff in the middle, concatenated to...
      " pointer to"      that string
       X #b              repeated len(asterisks) times
    }
float (*((*p function returning)) array of 16;
float ((*p function returning)) array of 16 pointer to
float (*p function returning) array of 16 pointer to
float p function returning pointer to array of 16 pointer to
Golfed 2 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip -s, 152 150 148 139 137 126 125125 123 bytes

YaRs" ("R';')R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\)`{c." pointer to"X#b}y^:s[y@1"is"y@>2y@0]{[b"is"g@>2a]}Vy^s

Takes the declaration as a command-line input. Try it online!Try it online!

y^:s{[b"is"g@>2a]}Vy^s
               y^s  Split y on spaces
{ and assign back         }V     Use the resulting list as arguments to ythis function:
 [      This    ]        Return a list of:
 y@1 b  Element 1                2nd argument (the variable name)
   "is"               That string
 y@>2  Elements 2 and following g@>2           All arguments after the 2nd
 y@0   Element 0      a          1st argument (the type)
]      Print              The resulting list is printed, joining on spaces (-s flag)

Pip -s, 152 150 148 139 137 126 125 bytes

YaRs" ("R';')R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\)`{c." pointer to"X#b}y^:s[y@1"is"y@>2y@0]

Takes the declaration as a command-line input. Try it online!

y^:s   Split y on spaces and assign back to y
[      This list:
 y@1   Element 1 (the variable name)
 "is"  That string
 y@>2  Elements 2 and following
 y@0   Element 0 (the type)
]      Print, joining on spaces (-s flag)

Pip -s, 152 150 148 139 137 126 125 123 bytes

YaRs" ("R';')R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\)`{c." pointer to"X#b}{[b"is"g@>2a]}Vy^s

Takes the declaration as a command-line input. Try it online!

{[b"is"g@>2a]}Vy^s
               y^s  Split y on spaces
{            }V     Use the resulting list as arguments to this function:
 [          ]        Return a list of:
  b                   2nd argument (the variable name)
   "is"               That string
       g@>2           All arguments after the 2nd
           a          1st argument (the type)
                    The resulting list is printed, joining on spaces (-s flag)
Golfed 1 byte
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip -s, 152 150 148 139 137 126126 125 bytes

YaRs" ("R';')R`\[(\d+)\]``]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\)`{c." pointer to"X#b}y^:s[y@1"is"y@>2y@0]

Takes the declaration as a command-line input. Try it online!Try it online!

Y                         Yank into y variable...
 a                        The result of a (the cmdline arg)...
  R s                     Replace the space
   " ("                    with " ("
  R ';                    Replace the semicolon
   ')                      with a closing paren
  R `\[(\d+)\]`]`            Replace digits in square brackets
   ` array of \1`          with " array of <digits>"
  R "()"                  Replace function parens
   " function returning"   with " function returning"

Pip -s, 152 150 148 139 137 126 bytes

YaRs" ("R';')R`\[(\d+)\]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\)`{c." pointer to"X#b}y^:s[y@1"is"y@>2y@0]

Takes the declaration as a command-line input. Try it online!

Y                         Yank into y variable...
 a                        The result of a (the cmdline arg)...
  R s                     Replace the space
   " ("                    with " ("
  R ';                    Replace the semicolon
   ')                      with a closing paren
  R `\[(\d+)\]`           Replace digits in square brackets
   ` array of \1`          with " array of <digits>"
  R "()"                  Replace function parens
   " function returning"   with " function returning"

Pip -s, 152 150 148 139 137 126 125 bytes

YaRs" ("R';')R`\[(\d+)]`` array of \1`R"()"" function returning"L#aYyR`\((\**)(.+)\)`{c." pointer to"X#b}y^:s[y@1"is"y@>2y@0]

Takes the declaration as a command-line input. Try it online!

Y                         Yank into y variable...
 a                        The result of a (the cmdline arg)...
  R s                     Replace the space
   " ("                    with " ("
  R ';                    Replace the semicolon
   ')                      with a closing paren
  R `\[(\d+)]`            Replace digits in square brackets
   ` array of \1`          with " array of <digits>"
  R "()"                  Replace function parens
   " function returning"   with " function returning"
Golfed 11 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
Loading
Golfed 2 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
Loading
Golfed 9 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
Loading
Golfed 9 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
Loading
Golfed 2 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
Loading
Golfed 2 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
Loading
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141
Loading