Begin Expression Arguments Rule

If Python is in the "begin_expr" state and the expression being evaluated is a function call, then prepend the function call arguments to the "Arguments" stack.

if the following are true:
  • expression state at time t = "begin_expr"
  • the expression at time t = function call with name: name and arguments: args

then arguments stack at time (t + 1) = [ args, arguments stack at time t ]

For example, if the following are true:
  • expression state at time 1 = "begin_expr"
  • the expression at time 1 = __add__(5, 2)

then arguments stack at time (1 + 1) = [ [ 5, [ 2, [ ] ] ], arguments stack at time 1 ]


Notice that the list of arguments became 1 new element of the Arguments stack. Why didn't we just set the Arguments stack equal to the arguments list? If an argument (child) is also a function call, then the child has its own arguments (grandchildren). When it is time for the grandchildren to be added to the Arguments stack, they are added as a separate element to the stack. This way, the grandchildren are separated from the children. If there are more levels of descendents, more elements will be created in the Arguments stack.

Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

Comments

Please log in to add comments