
    Ng                         d Z ddlmZmZmZmZmZmZmZm	Z	 ddl
mZ ddlmZmZmZ ddlmZmZmZmZ ddlmZ ddlmZ ddlmZ 	  G d	 d
          Zd Zedk    r
 e             dgZdS )ad  
A graphical tool for exploring the shift-reduce parser.

The shift-reduce parser maintains a stack, which records the structure
of the portion of the text that has been parsed.  The stack is
initially empty.  Its contents are shown on the left side of the main
canvas.

On the right side of the main canvas is the remaining text.  This is
the portion of the text which has not yet been considered by the
parser.

The parser builds up a tree structure for the text using two
operations:

  - "shift" moves the first token from the remaining text to the top
    of the stack.  In the demo, the top of the stack is its right-hand
    side.
  - "reduce" uses a grammar production to combine the rightmost stack
    elements into a single tree token.

You can control the parser's operation by using the "shift" and
"reduce" buttons; or you can use the "step" button to let the parser
automatically decide which operation to apply.  The parser uses the
following rules to decide which operation to apply:

  - Only shift if no reductions are available.
  - If multiple reductions are available, then apply the reduction
    whose CFG production is listed earliest in the grammar.

The "reduce" button applies the reduction whose CFG production is
listed earliest in the grammar.  There are two ways to manually choose
which reduction to apply:

  - Click on a CFG production from the list of available reductions,
    on the left side of the main window.  The reduction based on that
    production will be applied to the top of the stack.
  - Click on one of the stack elements.  A popup window will appear,
    containing all available reductions.  Select one, and it will be
    applied to the top of the stack.

Note that reductions can only be applied to the top of the stack.

Keyboard Shortcuts::
      [Space]	 Perform the next shift or reduce operation
      [s]	 Perform a shift operation
      [r]	 Perform a reduction operation
      [Ctrl-z]	 Undo most recent operation
      [Delete]	 Reset the parser
      [g]	 Show/hide available production list
      [Ctrl-a]	 Toggle animations
      [h]	 Help
      [Ctrl-p]	 Print
      [q]	 Quit

    )ButtonFrameIntVarLabelListboxMenu	ScrollbarTk)Font)	CFGEditorTreeSegmentWidgettree_to_treesegment)CanvasFrameEntryDialogShowText
TextWidget)SteppingShiftReduceParser)Tree)in_idlec                       e Zd ZdZd'dZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd(dZd Zd Zd Zd Zd Zd Zd Zd Zd  Z d! Z!d" Z"d# Z#d$ Z$d% Z%d& Z&dS ))ShiftReduceAppa  
    A graphical tool for exploring the shift-reduce parser.  The tool
    displays the parser's stack and the remaining text, and allows the
    user to control the parser's operation.  In particular, the user
    can shift tokens onto the stack, and can perform reductions on the
    top elements of the stack.  A "step" button simply steps through
    the parsing process, performing the operations that
    ``nltk.parse.ShiftReduceParser`` would use.
    r   c                 D   || _         t          ||          | _        t                      | _        | j                            d           d| _        t          | j                  | _        | j        	                    d           t          | j                  | _
        | j
        	                    d           |                     | j                   |                                  |                     | j                   |                     | j                   |                     | j                   |                     | j                   |                     | j                   t%          | j        d          | _        |                                  d| j        d<   d S )NzShift Reduce Parser Applicationr   
      tearoff text)_sentr   _parserr
   _toptitle_animating_lockr   _animateset_show_grammar_init_fonts_init_bindings_init_menubar_init_buttons_init_feedback_init_grammar_init_canvasr   _canvas_reduce_menureset
_lastoper1)selfgrammarsenttraces       Q/var/www/html/ai-engine/env/lib/python3.11/site-packages/nltk/app/srparser_app.py__init__zShiftReduceApp.__init__b   sn   
0%@@ DD		9:::  !ty))" $DI..q!!! 	### 	 	49%%%49%%%DI&&&49%%%$)$$$ !q999 	

"$    c                    t          t                      d                   | _        |                    d| j                   t	          |          | _        | j                            | j                            d                     t          dd| j                                                  | _	        t          d| j                                                  | _
        d S )	Nfont)r:   z*Fontsize	helveticabold)familyweightr;   )r>   r;   )r   r   _sysfont
option_addr   _sizer%   cgetget	_boldfont_font)r2   roots     r6   r'   zShiftReduceApp._init_fonts   s    &((6"2333/// D\\

t}))&11222[djnnFVFVWWW4:>>3C3CDDD


r8   c           
      P   t          |          x| _        }| j                            ddd           t          | j        | j        d          | _        | j                                         t          | j        ddd	d
| j        dd          | _        | j                            ddd           t          | j
                                                                                  | _        | j        D ] }| j                            dd|z             !| j                            t!          t#          | j                  d                     	 t%          | j        d          }| j                            |j                   |                    | j        j                   |                    dd           | j                            d| j                   d| _        | j                            d| j                   | j                            d| j                   d S )Nbothleft   )fillsidepadxzAvailable Reductions)r:   r   singlegroovewhitez#909090#004040z#c0f0c0)
selectmoderelief
background
foregroundr:   selectforegroundselectbackgroundrightr   rM   rL   expandend %s   )heightvertical)orient)yscrollcommand)commandy)rM   rL   z<<ListboxSelect>>z<Motion>z<Leave>)r   
_prodframepackr   rE   _prodlist_labelr   rF   	_prodlistlistr    r3   productions_productionsinsertconfigminlenr	   r%   yviewbind_prodlist_select_hover_highlight_hover_clear_hover)r2   parent	listframe
production
listscrolls        r6   r,   zShiftReduceApp._init_grammar   s   &+Fmm3)&vA>>>$O$.7M 
  
  
 	!!### O &&	
 	
 	
 	va@@@ !5!5!7!7!C!C!E!EFF+ 	? 	?JN!!%%**<>>>>ST->)?)?%D%DEEE	3"4?:FFFJN!!!@@@dn&:;;;OOcO222 	/1FGGG J(=>>>It'899999r8   c                 X   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d	| j                   | j                             d
| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j	                   | j                             d| j	                   | j                             d| j
                   | j                             d| j                   | j                             d| j        fd           | j                             d| j        fd           | j                             d| j        fd           d S )Nz<Control-q>z<Control-x>z<Alt-q>z<Alt-x>z<space>z<s>z<Alt-s>z<Control-s>z<r>z<Alt-r>z<Control-r>z<Delete>z<u>z<Alt-u>z<Control-u>z<Control-z>z<BackSpace>z<Control-p>z<Control-h>z<F1>z<Control-g>z<Control-t>-c                 ,    |                     d          S )N   r%   eas     r6   <lambda>z/ShiftReduceApp._init_bindings.<locals>.<lambda>       quuRyy r8   =c                 ,    |                     d          S )Nr   r   r   s     r6   r   z/ShiftReduceApp._init_bindings.<locals>.<lambda>   r   r8   +c                 ,    |                     d          S )N   r   r   s     r6   r   z/ShiftReduceApp._init_bindings.<locals>.<lambda>   s    quuQxx r8   )r!   rr   destroystepshiftreducer0   undo
postscripthelpedit_grammaredit_sentencer$   )r2   s    r6   r(   zShiftReduceApp._init_bindings   s   	}dl333	}dl333	y$,///	y$,/// 		y$),,,	udj)))	y$*---	}dj111	udk***	y$+...	}dk222	z4:...	udi(((	y$),,,	}di000	}di000	}di000 		}do666	}di000	vty)))	}d&7888	}d&8999 		s@@@AAA	s@@@AAA	s???@@@@@r8   c                    t          |          x| _        }|                    dd           t          |ddd| j                                      d	           t          |d
ddd| j                                      d	           t          |dddd| j                                      d	           t          |dddd| j                                      d	           d S )Nnonebottom)rL   rM   Stepz#90c0d0black)r   rU   rV   rc   rJ   rM   Shiftr   z#90f090)r   	underlinerU   rV   rc   ReduceUndoz#f0a0a0)r   _buttonframerg   r   r   r   r   r   )r2   rw   buttonframes      r6   r*   zShiftReduceApp._init_buttons   s   */--7Kf8444 I	
 	
 	
 $F$


 J	
 	
 	
 $F$


 K	
 	
 	
 $F$


 I	
 	
 	
 $F$




r8   c                    t          |          }t          |d          }|                    dd| j        d           |                    dd| j        d           |                    dd	| j        d
           |                    dd|           t          |d          }|                    dd| j        d           |                    dd| j        d           |                    dd|           t          |d          }|                    dd	| j        d           |	                                 |                    dd| j
        d           |                    dd| j        d           |	                                 |                    dd| j        d           |                    dd|           t          |d          }|                    dd| j        | j                   |	                                 |                    d| j        dd| j                    |                    d!| j        dd"| j                    |                    d#| j        dd$| j                    |                    d%| j        dd&| j                    |                    d'| j        dd(| j                    |                    d)d|           t          |d          }|                    d*d| j        d+           |                    d,d| j        d-d./           |                    d0d| j        dd1/           |                    d2d| j        d3d4/           |                    d5d	|           t          |d          }|                    d6d| j        7           |                    d8d| j        d9           |                    d:d|           |                    |;           d S )<Nr   r   zReset ParserDel)labelr   rc   acceleratorzPrint to PostscriptzCtrl-pExitr   zCtrl-xFile)r   r   menuzEdit Grammar   zCtrl-g	Edit TextzCtrl-tEditr   Spacer   zCtrl-sr   zCtrl-rr   zCtrl-uApplyShow Grammar)r   r   variablerc   Tinyr   )r   r   r   valuerc   Small   Medium   Large   Huge   ViewzNo Animation)r   r   r   r   zSlow Animationr~   r|   )r   r   r   r   r   zNormal Animationr   zFast Animationr   r   AnimateAbout)r   r   rc   InstructionsF1Help)r   )r   add_commandr0   r   r   add_cascader   r   r   add_separatorr   r   r   add_checkbuttonr&   _toggle_grammaradd_radiobuttonrB   resizer$   aboutr   rn   )	r2   rw   menubarfilemenueditmenurulemenuviewmenuanimatemenuhelpmenus	            r6   r)   zShiftReduceApp._init_menubar  s   v,,+++ Atzu 	 	
 	
 	
 	'O 	 	 	
 	
 	
 	At| 	 	
 	
 	
 	&AHEEE+++ % 	 	 	
 	
 	
 	& 	 	 	
 	
 	
 	&AHEEE+++Atyg 	 	
 	
 	
 	   Q
 	 	
 	
 	
 	a( 	 	
 	
 	
 	   Atyh 	 	
 	
 	
 	'QXFFF+++   '(	 	! 	
 	
 	
 	     ZK 	! 	
 	
 	
 	  ZK 	! 	
 	
 	
 	  ZK 	! 	
 	
 	
 	  ZK 	! 	
 	
 	
 	  ZK 	! 	
 	
 	
 	&AHEEE7A...## AQ 	$ 	
 	
 	
 	##"] 	$ 	
 	
 	
 	##$] 	$ 	
 	
 	
 	##"] 	$ 	
 	
 	
 	)q{KKK+++7aLLL Atyd 	 	
 	
 	
 	&AHEEE7#####r8   c                    t          |          x| _        }|                    dddd           t          |d| j                  | _        | j                            d           t          |d	d
          }|                    ddd
d           t          |dd| j                  | _        t          |dddd| j                  | _        | j                            d           | j                            ddd
           d S )Nxr      )rL   rM   rN   padyzLast Operation:)r   r:   rJ   r   sunkenr   )rT   borderrY   r   )rL   rM   r[   rN   z#007070z#f0f0f0)rV   rU   r:   w   rR   )anchorwidthrV   rU   r:   rZ   )r   _feedbackframerg   r   rF   _lastoper_labelr1   
_lastoper2)r2   rw   feedbackframelastoperframes       r6   r+   zShiftReduceApp._init_feedback  s+   .3Fmm;m(CCC$ 1
 
  
  
 	!!v!...mHQGGG'!!DDDiIDJ
 
 
    
 
 
 	&)))&s1=====r8   c                    t          |ddddd          | _        | j                            ddd	d
           | j                                        x}| _        g | _        g | _        |                    dddddd          | _        |	                    ddddd          | _
        |	                    ddddd          | _        | j                                        dz   }t          |dd| j                  | _        t          |dd| j                  | _        | j                            | j                   | j                            | j                   d S )NrQ   i  r   rK   r   )rU   r   closeenoughr   rT   r   rI   top)r[   rL   rM   r   r   z#c0f0f0r   )rL   outline.)dashz#408080)rL   r   StackrR   colorr:   zRemaining Text)r   _cframerg   canvasr.   _stackwidgets_rtextwidgetscreate_rectangle	_titlebarcreate_line	_exprline	_stacktoprB   rD   r   rE   _stacklabel_rtextlabel
add_widget)r2   rw   r   r;   s       r6   r-   zShiftReduceApp._init_canvas  sw   "
 
 
 	e!DDD $ 3 3 5 5500q!QY 1 
 
  ++Aq!QS+AA++Aq!QY+GGz~~!#%G94>
 
 
 &$IDN
 
 
 	 0111 011111r8   c                 	   | j         d                                         }d |D             \  }}}}| j        D ]}| j                            |           g | _        | j        D ]}| j                            |           g | _        | j                                        \  }}	}
}||	z
  dz   }| j                             | j	        ddd|dz
             | j                             | j
        d|dz  dz
  d|dz  dz
             | j                                        \  }}	}
}| j                            d	|z
  d
|	z
             | j                                        \  }}	}
}| j                            ||
z
  d	z
  d
|	z
             d	}| j                                        D ]}t          |t                     r>dd| j        dd| j        d}t'          | j         |fi |}d|                                d<   nt+          | j         |d| j                  }|                    | j                   | j                            |           | j                            |||           |                                d         dz   }d}| j                                        D ]r}t+          | j         |d| j                  }| j                            |           | j                            |||           |                                d         dz   }st7          | j                  dk    r"|| j        d                                         z  }t;          || j                                        dz             }| j                                        dz   }||t;          ||          z
  k    r|t;          ||          z   }| j        D ]}|                    d|z   |z
  d           | j                            || j                                        d         z
  d	z
  d           ||z   t;          ||          z
  dz  }| j                             | j        |d|d           | j                                        \  }}	}
}t7          | j                  dk    rK|| fd}| j        d                             |           | j        d                             | j                    | !                                 d S )Nscrollregionc              3   4   K   | ]}t          |          V  d S Nint).0cs     r6   	<genexpr>z)ShiftReduceApp._redraw.<locals>.<genexpr>  s(      ==1A======r8   r   ixr     r   rK   r   r   z#4080a0#006060)
tree_color
tree_width	node_font
node_color
leaf_color	leaf_fontz#000000r   r   r^   c                     |                                  d         |k     r|                                 d S |                                 d S )Nr   )bboxr   _redraw)widgetmidxr2   s      r6   
drag_shiftz*ShiftReduceApp._redraw.<locals>.drag_shift  s<    ;;==#d**JJLLLLLLLNNNNNr8   )"r.   splitr   r   destroy_widgetr   r   r  coordsr   r   mover   r    stack
isinstancer   rE   rF   r   r   r   
bind_click_popup_reduceappendr   remaining_textrp   r   maxr   	bind_dragr   _highlight_productions)r2   r   cx1cy1cx2cy2stackwidgetrtextwidgetx1y1x2y2rd   stackxtokattribsr  
rtextwidthrlabelwidthr  r  s                        r6   r  zShiftReduceApp._redraw  s   |N399;;=====c3  - 	5 	5KL''4444- 	5 	5KL''4444  +0022RRGbLDNE1dAEBBBDNAq1urz4QLLL  +0022RRa"fa"f---+0022RRcBhlAF333 <%%'' 	+ 	+C#t$$ Y"+"#!%"+"+!%  -T\3JJ'JJ*3w''#DL#YTZXXXd0111%%f---L##FFA666[[]]1%*FF 
<..00 	. 	.CcTTTF%%f---L##FJ:::q)A-JJ t!""Q&&d(+11333F
 VT-3355:;;&,,..3S3z;777773z;777C- 	6 	6KQWz115555cD$4$9$9$;$;A$>>BAFFFs:{;;;q@DND!T4@@@+0022RR t!""Q&&(,4 # # # # q!++J777q!,,TZ888 	##%%%%%r8   c                     |                                 d         dz   }| j                            | j        |d|d           d S )NrK   2   r   r   )r  r.   r	  r   )r2   r  r  s      r6   _draw_stack_topzShiftReduceApp._draw_stack_top  s?    {{}}Q"$DND!T4@@@@@r8   c                     | j                             dd           | j                                        D ]6}| j                            |          }| j                             |           7d S )Nr   r\   )ri   selection_clearr    reducible_productionsrl   indexselection_set)r2   prodr)  s      r6   r  z%ShiftReduceApp._highlight_productions  sp    &&q%000L6688 	0 	0D%++D11EN((////	0 	0r8   c                 X    | j         d S | j                                          d | _         d S r   )r!   r   r2   r   s     r6   r   zShiftReduceApp.destroy)  s.    9F				r8   c                     | j                             | j                   d| j        d<   d| j        d<   |                                  d S )Nz	Reset Appr   r   )r    
initializer   r1   r   r  r-  s     r6   r0   zShiftReduceApp.reset/  sC    
+++"-"$r8   c                     |                                  rdS |                                 rdS t          | j                                                  rd| j        d<   d| j        d<   d S d| j        d<   d| j        d<   d S )NTz	Finished:r   SuccessFailure)r   r   rj   r    parsesr1   r   r-  s     r6   r   zShiftReduceApp.step5  s    ;;== 
	44ZZ\\ 	44DL''))** 4*5'*3'''*5'*3'''r8   c                 >   | j         rd S | j                                        rz| j                                        d         }d| j        d<   d|z  | j        d<   | j                                        r|                                  n| 	                                 dS dS )Nre   zShift:r   z%rTF)
r#   r    r   r  r1   r   r$   rD   _animate_shiftr  )r2   r   r  s      r6   r   zShiftReduceApp.shiftB  s     	F< 	,$$&&r*C&.DOF#&*SjDOF#}  "" ##%%%%4ur8   c                     | j         rd S | j                                        }|rYd| j        d<   d|z  | j        d<   | j                                        r|                                  n|                                  |S )NReduce:r   %s)	r#   r    r   r1   r   r$   rD   _animate_reducer  )r2   r   ry   s      r6   r   zShiftReduceApp.reduceP  s     	F\((**
 	&/DOF#&*Z&7DOF#}  "" $$&&&&r8   c                 v    | j         rd S | j                                        r|                                  d S d S r   )r#   r    r   r  r-  s     r6   r   zShiftReduceApp.undo]  sC     	F< 	LLNNNNN	 	r8   c                 8    | j                                          d S r   )r   print_to_filer-  s     r6   r   zShiftReduceApp.postscriptc  s    ""$$$$$r8   c                 J    t                      rdS  | j        j        |i | dS )z
        Enter the Tkinter mainloop.  This function must be called if
        this demo is created from a non-interactive program (e.g.
        from a secript); otherwise, the demo will close as soon as
        the script completes.
        N)r   r!   mainloop)r2   argskwargss      r6   r>  zShiftReduceApp.mainloopf  s5     99 	F	D+F+++++r8   Nc                    || j                             |           | j                                         }| j                            t          |                      | j                            t          |                      | j                            t          |                      |                                  d S )N)r;   )	rB   r%   rD   rF   	configureabsrE   r@   r  )r2   r;   s     r6   r   zShiftReduceApp.resizeu  s    JNN4   z~~
CII,///  D		l 333s4yy\222 	r8   c                     	 t          | j        dt          pd                                dd           d S #  t          | j        dt          pd                                d           Y d S xY w)Nz%Help: Shift-Reduce Parser Applicationr   K   fixed)r   r:   r   )r   r!   __doc__stripr-  s     r6   r   zShiftReduceApp.help  s    		7B%%''     		7B%%''	      s	   26 3A,c                     d}d}	 ddl m}  |||                                           d S #  t          | j        ||           Y d S xY w)Nz<NLTK Shift-Reduce Parser Application
Written by Edward Loperz&About: Shift-Reduce Parser Applicationr   )Message)messager"   )tkinter.messageboxrK  showr   r!   )r2   r   ABOUTTITLErK  s        r6   r   zShiftReduceApp.about  sp    T8	.222222GE///4466666	.TYu------s	   %- Ac                 j    t          | j        | j                                        | j                   d S r   )r   r!   r    r3   set_grammarr-  s     r6   r   zShiftReduceApp.edit_grammar  s-    $)T\1133T5EFFFFFr8   c                    | j                             |           t          |                                          | _        | j                            dd           | j        D ] }| j                            dd|z             !d S )Nr   r\   r]   )r    rR  rj   rk   rl   ri   deleterm   )r2   r3   ry   s      r6   rR  zShiftReduceApp.set_grammar  s      ))) !4!4!6!677a'''+ 	? 	?JN!!%%**<>>>>	? 	?r8   c                 |    d                     | j                  }d}d}t          | j        ||| j        |           d S )N r   zEnter a new sentence to parse.)joinr   r   r!   set_sentence)r2   r   sentencer"   instrs        r6   r   zShiftReduceApp.edit_sentence  s@    88DJ''0DIx0A5IIIIIr8   c                 `    |                                 | _        |                                  d S r   )r  r   r0   )r2   r4   s     r6   rX  zShiftReduceApp.set_sentence  s"    ZZ\\


r8   c                     | j                                         r.| j                            ddd| j                   d| j        d<   n#| j                                         d| j        d<   d| j        d<   d S )	NrI   rJ   rK   )rL   rM   rN   afterr   r   zHide Grammarr   )r&   rD   rf   rg   r   r1   pack_forgetr   r-  s     r6   r   zShiftReduceApp._toggle_grammar  s    !!## 	5O  &q8K !    '5DOF##O'')))&4DOF#"$r8   c                 h   | j                                         }t          |          dk    rd S t          |d                   }| j                            | j        |                   }|r\d| j        d<   d|z  | j        d<   | j	        
                                r|                                  d S |                                  d S | j                             dd           | j                                        D ]6}| j                            |          }| j                             |           7d S )Nr   r   r7  r   r8  r\   )ri   curselectionrp   r   r    r   rl   r1   r   r$   rD   r9  r  r'  r(  r)  r*  )r2   event	selectionr)  ry   r+  s         r6   rs   zShiftReduceApp._prodlist_select  s-   N//11	y>>QFIaL!!\(():5)ABB
 	4&/DOF#&*Z&7DOF#}  "" $$&&&&& N**1e444::<< 4 4)//55,,U33334 4r8   c                    | j                                         }t          |          dk    rd S | j                            dd           |D ]0}| j                            t          |          | j                   1| j                            | j	        
                                | j	                                                   d S )Nr   r\   )r   rc   )r    r(  rp   r/   rT  r   strr   postr.   winfo_pointerxwinfo_pointery)r2   r  rk   ry   s       r6   r  zShiftReduceApp._popup_reduce  s    l88::{q  F  E***% 	V 	VJ))J)UUUUL''))4<+F+F+H+H	
 	
 	
 	
 	
r8   c                 P   | j         d         }|                                d         }t          | j                  dk    rd}n(| j        d                                         d         dz   }| j                                        }||z
  dz  |z  }|                     |||           d S )Nr   r   re   rK   r   g      ?)r   r  rp   r   r$   rD   _animate_shift_frame)r2   r  rY   rJ   dtdxs         r6   r5  zShiftReduceApp._animate_shift  s    #A& a t!""a''DD%b)..003b8D ]  Ulc!B&!!"fb11111r8   c                 @   |dk    rEd| _         |                    |d           | j                            d| j        |dz
  ||           d S | j        d= | j                            |           d| _         |                     |           | 	                                 d S )Nr   r   r   )
r#   r
  r!   r]  ri  r   r   r  r%  r  )r2   framer  rk  s       r6   ri  z#ShiftReduceApp._animate_shift_frame  s    199#$D KKAIOOB 9519fbQQQQQ
 "1%%%f---#$D    ((('')))))r8   c                    t          | j                                        d                   }| j        | d          }t	          |d         t
                    r0d|d                                                                         z   }nd|d                                         z   }| j        	                                }|dz  |z  }| 
                    |dz  ||           d S )Nre   r      g       @rK   )rp   r    r  r   r  r   r   r_   r$   rD   _animate_reduce_frame)r2   
numwidgetswidgetsydistrj  dys         r6   r9  zShiftReduceApp._animate_reduce  s    ++--b122
$j[\\2 gaj"344 	-))++22444EE**,,,E ]  S[2""267B77777r8   c                    |dk    rJd| _         |D ]}|                    d|           | j                            d| j        |dz
  ||           d S | j        t          |           d = |D ]}| j                            |           | j	        
                                d         }t          |t                    st                      t          | j        t!          |                                          d| j                  }t'          | j        ||d          }| j                                        \  }}}	}
|
|z
  dz   }| j        sd	}n(| j        d                                         d         dz   }| j                            |||           | j                            |           |                     |           |                                  d| _         d S )
Nr   r   r   re   r   r   rK   rG  r   )r#   r
  r!   r]  rp  r   rp   r   remove_widgetr    r  r  r   
ValueErrorr   r.   rd  r   rE   r   r   r  r   r  r%  r  )r2   rm  rr  rt  r  r  r   r  r  r  r  rd   r   s                r6   rp  z$ShiftReduceApp._animate_reduce_frame  s   199#$D ! # #Ar""""IOOB :EAIwPRSSSSS"CLL=??3! 3 3**62222,$$&&r*Cc4(( # ll"c#))++..idn  E 't|UG1MMMF#/4466RRR"A% :&r*//11!4r9L##FAq111%%f---   ((('')))8 $%D   r8   c                    | j                             |j                  }| j        |k    rd S |                                  d | j                                         D             }||v rqt          | j        |                                                   }| j	        | d          D ]4}t          |t                    rd|                                d<   /d|d<   5|| _        d S )Nc                 ,    g | ]}t          |          S  r   )r   ss     r6   
<listcomp>z3ShiftReduceApp._highlight_hover.<locals>.<listcomp>d  s    CCCSVVCCCr8   z#00a000r   )ri   nearestrd   rt   rv   r`  rp   rl   rhsr   r  r   r   )r2   ra  r)  rb  rhslenr  s         r6   ru   zShiftReduceApp._highlight_hoverY  s    &&uw//;%F 	 DCT^%@%@%B%BCCC	I*51557788F#16'((; 5 5k+<== 53<K%%''00+4K(( r8   c                     | j         dk    rd S d| _         | j        D ]4}t          |t                    rd|                                d<   /d|d<   5d S )Nre   r   r   )rt   r   r  r   r   )r2   ra  r  s      r6   rv   zShiftReduceApp._clear_hoverp  sp    ;"F- 	/ 	/K+'899 //6!!##G,,'.G$$		/ 	/r8   )r   r   )'__name__
__module____qualname__rH  r7   r'   r,   r(   r*   r)   r+   r-   r  r%  r  r   r0   r   r   r   r   r   r>  r   r   r   r   rR  r   rX  r   rs   r  r5  ri  r9  rp  ru   rv   rz  r8   r6   r   r   W   sR        $% $% $% $%T
E 
E 
E': ': ':R A  A  AD" " "HA$ A$ A$F> > >.2 2 2BU& U& U&nA A A
0 0 0    4 4 4      % % %	, 	, 	,   "  $. . .G G G? ? ?J J J  	% 	% 	%4 4 4(
 
 
"2 2 2 * * *"8 8 8 8% 8% 8%|  .	/ 	/ 	/ 	/ 	/r8   r   c                     ddl m} mm} d}fd|                                D             \	  }}}}}}}	}
} ||||g           ||||g           ||||g           ||||g           |||
||g           |||
|g           ||||g           ||dg           ||dg           ||dg           ||dg           ||
d	g           ||d
g           ||dg           ||dg           ||dg           ||dg           ||dg          f} | ||          }d                                }t          ||                                           dS )zP
    Create a shift reduce parser app, using a simple grammar and
    text.
    r   )CFGNonterminal
ProductionzS VP NP PP P N Name V Detc              3   .   K   | ]} |          V  d S r   rz  )r   r{  r  s     r6   r   zapp.<locals>.<genexpr>  s+      *X*Xa;;q>>*X*X*X*X*X*Xr8   Ither   mansawinwithparkdogstatuemyz*my dog saw a man in the park with a statueN)nltk.grammarr  r  r  r  r   r>  )r  r  nonterminalsSVPNPPPPNNameVDetrk   r3   r4   r  s                  @r6   appr  |  s    :999999999.L*X*X*X*X<CUCUCWCW*X*X*X'QBAq$3 	
1r2h
2Qx  
2Bx  
2Bx  
22r{##
22w
22w
2u
3  
3
1ug
1ug
1tf
1vh
1vh
1ug
1xj!!
3)K. c![!!G 8==??D7D!!**,,,,,r8   __main__r  N)rH  tkinterr   r   r   r   r   r   r	   r
   tkinter.fontr   	nltk.drawr   r   r   nltk.draw.utilr   r   r   r   
nltk.parser   	nltk.treer   	nltk.utilr   r   r  r  __all__rz  r8   r6   <module>r     sB  7 7r O N N N N N N N N N N N N N N N N N N N       G G G G G G G G G G I I I I I I I I I I I I 0 0 0 0 0 0            
b/ b/ b/ b/ b/ b/ b/ b/J'- '- '-T zCEEE'r8   