Function clipboard: copy This challenge is related to some of the MATL language's features, as part of the May 2018 Language of the Month event. Associated challenge: Function clipboard: paste.



Introduction

MATL has several clipboards, where  you can store values (copy) to be retrieved later (paste). Some clipboards are automatic, which means that copying is automatically triggered by certain events. This challenge focuses on one of the automatic clipbards, called the function-input clipboard, or simply function clipboard.

This clipboard stores the inputs to the four most recent calls to normal, input-taking functions. Normal functions are the most common type of functions in MATL. Input-taking means that the function takes at least one input (functions that do not take any input are not considered by the function clipboard).

This is best explained with the following examples, which use two normal functions:


+, which pops two numbers from the stack and pushes their sum.
U, which pops one number and pushes its square.


Example 1:

3 2 + 6 + 12 4 U + +


produces the result 39. The code is interpreted as follows:


Number literals such as 3 or 12 get pushed to the stack 
Functions such as + pop their inputs and push their outputs to the stack.


The function calls, in chronological order, are:


3 2 + gives 5
5 6 + gives 11
4 U gives 16
12 16 + 28
11 28 + gives 39.


The clipboard can be viewed as a list of four lists. Each inner list contains the inputs to a function call, with most recent calls first. Within each inner list, inputs are in their original order.

So after running the code the clipboard contents are (in Python notation):

[[11, 28], [12, 16], [4], [5, 6]]


Example 2:

10 20 U 30 +


leaves numbers 10 and 430 on the stack. The stack is displayed bottom to top at the end of the program.

The function calls are


20 U gives 400
400 30 + gives 430


Since there have been only two function calls, some of the inner lists defining the clipboard will be empty. Note also how 10 is not used as input to any function. 

Thus, the clipboard contents after running the code are:

[[400, 30], [20], [], []]


Example 3 (invalid):

10 20 + +


is considered invalid, because an input to the second + is missing (in MATL this would implicitly trigger user input).

The challenge

Input: a string S with number literals, + and U, separated by spaces.

Output: the contents of the function clipboard after evaluating the string S.

Clarifications:


You may use any two consistent symbols to represent those functions, other than digits. Also, you can use any consistent symbol as separator, instead of space.
Only the two indicated functions will be considered.
The input string will contain at least one number literal and at least one function. 
All numbers will be positive integers, possibly with more than one digit.
It is possible that some number literals are not used by any function, as in the example 2.
The input is guaranteed to be valid code, without requiring additional numbers. So a string as in example 3 will never occur.
Trailing empty inner lists in the output can be ommited. So the result in example 2 can be [[400, 30], [20]]
Any reasonable, unambiguous output format is acceptable. For example, a string with comma as inner separator and semicolon as outer separator: 400,30;20;;.


Additional rules:


Input and output can be taken by any reasonable means.
Programs or functions are allowed, in any programming language. Standard loopholes are forbidden.
Shortest code in bytes wins.


Test cases

Input
Output

3 2 + 6 + 12 4 U + +
[[11, 28], [12, 16], [4], [5, 6]]

15 3 4 + 2 U 8 + U +
[[7, 144], [12], [4, 8], [2]]

3 6 9 12 + + 10 8 U 6
[[8], [6, 21], [9, 12], []]

8 41 12 25 4 5 33 7 9 10 + + + + + + + +
[[41, 105], [12, 93], [25, 68], [4, 64]]

10 1 1 + U U U U U
[[65536], [256], [16], [4]]
Bash, 43 bytes

sed s/+/rdnFPrp+/g\;s/U/p2^/g|dc|tac|sed 4q

Try it online!
This prints the clipboard in the following format, note the usage of \x0F as the separator.
item_1\x0Fitem_2
item_3
.
.
item_m\x0Fitem_n

The key idea is to pass this into dc, a stack-based language, such that the required stack items will be printed.
The input is piped to sed where every + is replaced with rdnFPrp+, which in dc prints the second number on the stack followed by \x0F and then the top number before performing addition. sed also replaces every U with p2^, print the top stack element and square it.

The first substitution command s replaces all, as is denoted by the global flag g, +s with rdnFPrp+. In dc, r swaps the top two stack items, d duplicates the top item, n prints it without a newline, F pushes 15 onto the stack and P prints it as a character (which is the delimiter), r swaps again, p prints the top stack item and then + performs addition on the top two stack items.
We have another command, and in sed, commands are separated by either semicolons or newlines, of which the first option is chosen. Simply having ; will make bash interpret that as the end of the sed command, so it is escaped with a \.
In the last substitution command, U is replaced globally with p2^. In dc, p prints, and 2^ raises it to the second power.

The result of sed is eval'ed as dc code, printing the entire clipboard.

The pipe to dc makes dc interpret that as dc code. Now, the most recent calls are at the bottom and the older ones at the top.

Since the lines are in reverse order, tac (reverse cat) is used to fix that.
And finally, sed picks the first 4 lines from tac.

This is a shorter way of doing head -4. sed performs the commands to every line of the input one at a time. If there are no commands, nothing is done to the input, and it is returned as it is. 4q tells sed to perform the command q on line 4. When sed is processing line 4 of the input, the first three inputs have already been printed. The command q quits the program, so it prints the fourth line and quits, thus performing the equivalent of head -4.