Guest User

Untitled

a guest
Feb 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=c
  2.  
  3. into:
  4.  
  5. {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}
  6.  
  7. push x : x
  8. push y : x y
  9. push array : x y []
  10. push z : x y [] z
  11. assign top : x y [] { z => 10 }
  12. shift : [{z => 10}] then {y => [{z => 10}]} then {x => {y => [{z => 10}]}}
  13.  
  14. new top is : {x => {y => [{z => 10}]}}
  15.  
  16. * now each push operation takes the stack top, if it's found in that hash then the value is
  17. pushed on instead of the token
  18.  
  19. push x : { y => [...]}
  20. push y : [{z => 10}]
  21. push array : [{z => 10}] []
  22. push w : [{z => 10}] [] w
  23. assign top : [{z => 10}] [] { w => 'a' }
  24. shift : [{w => 'a'}] then [{z => 10}] + [{w => 'a'}] == [{z => 10},{w => 'a'}]
  25.  
  26. whole thing is now {x => {y => [{z => 10}, {w => 'a'}]}}
  27.  
  28. Basic rule would be that push tries to find the var in the top Hash (if there is one).
  29. If not top hash then it pushes the new var on.
  30. Shift adds things to arrays until there are no more.
  31. Shift makes new hashes and assigns them to vars with right side as value.
Add Comment
Please, Sign In to add comment