Skip to content

Parenthesis priority parsing walkthrough

Adam Dernis edited this page May 21, 2020 · 3 revisions

< indicates the active_node

 x+(3x+5*x)
^
----------
state_: Begin
cache_: ""
parenthesis_depth: 0
x+(3x+5*x)
^
----------
state_: Variable
cache_: ""
parenthesis_depth: 0
x+(3x+5*x)
 ^
----------
   + <
   |
   x
state_: Nary operator
cache_: ""
parenthesis_depth: 0
x+(3x+5*x)
  ^
----------
    +
  /   \
 x     () <
state_: Begin
cache_: ""
parenthesis_depth: 1
x+(3x+5*x)
   ^
----------
    +
  /   \
 x     () <
state_: Integer
cache_: "3"
parenthesis_depth: 1
x+(3x+5*x)
    ^
----------
        +
      /    \
    x       () 
             |
             * <
           /   \
          3     x
state_: Variable
cache_: ""
parenthesis_depth: 1
x+(3x+5*x)
     ^
----------
        +
      /    \
    x       () 
             |
             + <
             | 
             *
           /   \
          3     x    
state_: Nary operator
cache_: ""
parenthesis_depth: 1
x+(3x+5*x)
      ^
----------
        +
      /    \
    x       () 
             |
             + <
             | 
             *
           /   \
          3     x    
state_: Integer
cache_: "5"
parenthesis_depth: 1
x+(3x+5*x)
       ^
----------
         +
      /      \
    x         () 
               |
               + 
            /     \
          *        * <
        /   \        
       3     x    
state_: Nary operator
cache_: ""
parenthesis_depth: 1
x+(3x+5*x)
        ^
----------
         +
      /      \
    x         () 
               |
               + 
            /     \
          *        * <
        /   \      |  
       3     x     x
state_: Variable
cache_: ""
parenthesis_depth: 1
x+(3x+5*x)
         ^
----------
         +
      /      \
    x         () <
               |
               + 
            /     \
          *        * 
        /   \      |  
       3     x     x
state_: Value
cache_: ""
parenthesis_depth: 0
x+(3x+5*x)
          ^
----------
         +
      /      \
    x         ()
               |
               + 
            /     \
          *        * 
        /   \      |  
       3     x     x
state_: Done
cache_: ""
parenthesis_depth: 0
Clone this wiki locally