
    /h                         S r SSKJrJrJrJrJrJrJrJ	r	  SSK
Jr  SSKJrJrJr  SSKJrJrJrJr  SSKJr  SSKJr  SSKJr    " S	 S
5      rS r\S:X  a  \" 5         S/rg)a  
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                       \ rS rSrSrS(S jrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS)S jrS rS rS rS rS rS rS rS r S  r!S! r"S" r#S# r$S$ r%S% r&S& r'S'r(g)*ShiftReduceAppW   a  
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.
c                 :   X l         [        X5      U l        [        5       U l        U R                  R                  S5        SU l        [        U R                  5      U l        U R                  R                  S5        [        U R                  5      U l
        U R                  R                  S5        U R                  U R                  5        U R                  5         U R                  U R                  5        U R                  U R                  5        U R                  U R                  5        U R!                  U R                  5        U R#                  U R                  5        [%        U R&                  SS9U l        U R+                  5         SU R,                  S'   g )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       M/var/www/auris/envauris/lib/python3.13/site-packages/nltk/app/srparser_app.py__init__ShiftReduceApp.__init__b   s.   
0@ D			9:  !tyy)" $DII.q! 	# 	 	499%499%DII&499%$))$ !q9 	

"$    c                    [        [        5       S   S9U l        UR                  SU R                  5        [	        U5      U l        U R
                  R                  U R                  R                  S5      5        [        SSU R
                  R                  5       S9U l	        [        SU R
                  R                  5       S9U l
        g )	Nfont)r<   z*Fontsize	helveticabold)familyweightr=   )r@   r=   )r   r   _sysfont
option_addr   _sizer&   cgetget	_boldfont_font)r3   roots     r7   r(   ShiftReduceApp._init_fonts   s    &(6"23/ D\


t}}))&12[djjnnFVW4::>>3CD
r:   c                 f   [        U5      =U l        nU R                  R                  SSSS9  [        U R                  U R                  SS9U l        U R
                  R                  5         [        U R                  SSS	S
U R                  SSS9U l        U R                  R                  SSSS9  [        U R                  R                  5       R                  5       5      U l        U R                   H"  nU R                  R                  SSU-  5        M$     U R                  R                  [!        [#        U R                  5      S5      S9   [%        U R                  SS9nU R                  R                  UR&                  S9  UR                  U R                  R(                  S9  UR                  SSS9  U R                  R+                  SU R,                  5        SU l        U R                  R+                  SU R0                  5        U R                  R+                  SU R2                  5        g )Nbothleft   )fillsidepadxzAvailable Reductions)r<   r   singlegroovewhitez#909090#004040z#c0f0c0)
selectmoderelief
background
foregroundr<   selectforegroundselectbackgroundrightr   rP   rO   expandend %s   )heightvertical)orient)yscrollcommand)commandy)rP   rO   z<<ListboxSelect>>z<Motion>z<Leave>)r   
_prodframepackr   rG   _prodlist_labelr   rH   	_prodlistlistr!   r4   productions_productionsinsertconfigminlenr	   r&   yviewbind_prodlist_select_hover_highlight_hover_clear_hover)r3   parent	listframe
production
listscrolls        r7   r-   ShiftReduceApp._init_grammar   s   &+Fm3)&vA>$OO$..7M 
 	!!# OO &&	
 	va@ !5!5!7!C!C!EF++JNN!!%%**<> ,ST->->)?%DE "4??:FJNN!!!@dnn&:&:;OOcO2 	/1F1FG J(=(=>It'8'89r:   c                    U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  S	U R
                  5        U R                   R                  S
U R
                  5        U R                   R                  SU R
                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  4S j5        U R                   R                  SU R                  4S j5        U R                   R                  SU R                  4S j5        g )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                 $    UR                  S5      $ )N   r&   eas     r7   <lambda>/ShiftReduceApp._init_bindings.<locals>.<lambda>       quuRyr:   =c                 $    UR                  S5      $ )Nr   r   r   s     r7   r   r      r   r:   +c                 $    UR                  S5      $ )N   r   r   s     r7   r   r      s    quuQxr:   )r"   ru   destroystepshiftreducer1   undo
postscripthelpedit_grammaredit_sentencer%   )r3   s    r7   r)   ShiftReduceApp._init_bindings   s;   		}dll3		}dll3		y$,,/		y$,,/ 			y$)),		udjj)		y$**-		}djj1		udkk*		y$++.		}dkk2		z4::.		udii(		y$)),		}dii0		}dii0		}dii0 			}doo6		}dii0		vtyy)		}d&7&78		}d&8&89 			s@A		s@A		s?@r:   c           	      n   [        U5      =U l        nUR                  SSS9  [        USSSU R                  S9R                  SS	9  [        US
SSSU R
                  S9R                  SS	9  [        USSSSU R                  S9R                  SS	9  [        USSSSU R                  S9R                  SS	9  g )Nnonebottom)rO   rP   Stepz#90c0d0black)r   rX   rY   rf   rM   rP   Shiftr   z#90f090)r   	underlinerX   rY   rf   ReduceUndoz#f0a0a0)r   _buttonframerj   r   r   r   r   r   )r3   rz   buttonframes      r7   r+   ShiftReduceApp._init_buttons   s    */-7Kf84 II	
 $F$
 JJ	
 $F$
 KK	
 $F$
 II	
 $F$
r:   c                    [        U5      n[        USS9nUR                  SSU R                  SS9  UR                  SSU R                  SS9  UR                  SS	U R                  S
S9  UR                  SSUS9  [        USS9nUR                  SSU R                  SS9  UR                  SSU R                  SS9  UR                  SSUS9  [        USS9nUR                  SS	U R                  SS9  UR                  5         UR                  SSU R                  SS9  UR                  SSU R                  SS9  UR                  5         UR                  SSU R                  SS9  UR                  SSUS9  [        USS9nUR                  SSU R                  U R                  S9  UR                  5         UR!                  SU R"                  SSU R$                  S 9  UR!                  S!U R"                  SS"U R$                  S 9  UR!                  S#U R"                  SS$U R$                  S 9  UR!                  S%U R"                  SS&U R$                  S 9  UR!                  S'U R"                  SS(U R$                  S 9  UR                  S)SUS9  [        USS9nUR!                  S*SU R&                  SS+9  UR!                  S,SU R&                  S-S.S/9  UR!                  S0SU R&                  SS1S/9  UR!                  S2SU R&                  S3S4S/9  UR                  S5S	US9  [        USS9nUR                  S6SU R(                  S79  UR                  S8SU R*                  S9S9  UR                  S:SUS9  UR-                  US;9  g )<Nr   r   zReset ParserDel)labelr   rf   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   variablerf   Tinyr   )r   r   r   valuerf   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   rf   InstructionsF1Help)r   )r   add_commandr1   r   r   add_cascader   r   r   add_separatorr   r   r   add_checkbuttonr'   _toggle_grammaradd_radiobuttonrD   resizer%   aboutr   rq   )	r3   rz   menubarfilemenueditmenurulemenuviewmenuanimatemenuhelpmenus	            r7   r*   ShiftReduceApp._init_menubar  s    v,+ Atzzu 	 	
 	'OO 	 	 	
 	At|| 	 	
 	&AHE+ %% 	 	 	
 	&& 	 	 	
 	&AHE+Atyyg 	 	
 	 Q

 	 	
 	a( 	 	
 	 Atyyh 	 	
 	'QXF+   ''((	 	! 	
 	   ZZKK 	! 	
 	  ZZKK 	! 	
 	  ZZKK 	! 	
 	  ZZKK 	! 	
 	  ZZKK 	! 	
 	&AHE7A.## AQ 	$ 	
 	##"]] 	$ 	
 	##$]] 	$ 	
 	##"]] 	$ 	
 	)q{K+7aL Atyyd 	 	
 	&AHE7#r:   c           	         [        U5      =U l        nUR                  SSSSS9  [        USU R                  S9U l        U R
                  R                  SS9  [        US	S
S9nUR                  SSS
SS9  [        USSU R                  S9U l        [        USSSSU R                  S9U l        U R                  R                  SS9  U R                  R                  SSS
S9  g )Nxr      )rO   rP   rQ   padyzLast Operation:)r   r<   rM   r   sunkenr   )rW   borderr\   r   )rO   rP   r^   rQ   z#007070z#f0f0f0)rY   rX   r<   w   rU   )anchorwidthrY   rX   r<   r]   )r   _feedbackframerj   r   rH   _lastoper_labelr2   
_lastoper2)r3   rz   feedbackframelastoperframes       r7   r,   ShiftReduceApp._init_feedback  s    .3Fm;m(C$ 1

 
 	!!v!.mHQG'!!DiIDJJ
    
 	&)&s1=r:   c           	         [        USSSSSS9U l        U R                  R                  SSS	SS
9  U R                  R                  5       =o l        / U l        / U l        UR                  SSSSSSS9U l        UR                  SSSSSS9U l
        UR                  SSSSSS9U l        U R                  R                  5       S-   n[        USSU R                  S9U l        [        USSU R                  S9U l        U R                  R%                  U R                   5        U R                  R%                  U R"                  5        g )NrT   i  r   rN   r   )rX   r   closeenoughr   rW   r   rL   top)r^   rO   rP   r   r   z#c0f0f0r   )rO   outline.)dashz#408080)rO   r   StackrU   colorr<   zRemaining Text)r   _cframerj   canvasr/   _stackwidgets_rtextwidgetscreate_rectangle	_titlebarcreate_line	_exprline	_stacktoprD   rF   r   rG   _stacklabel_rtextlabel
add_widget)r3   rz   r   r=   s       r7   r.   ShiftReduceApp._init_canvas  sB   "
 	e!D $ 3 3 5500q!QY 1 
  ++Aq!QS+A++Aq!QY+Gzz~~!#%G94>>
 &$IDNN
 	 0 01 0 01r:   c                 
   U R                   S   R                  5       nS U 5       u  p#pEU R                   H  nU R                  R	                  U5        M      / U l        U R
                   H  nU R                  R	                  U5        M      / U l        U R                  R                  5       u  ppX-
  S-   nU R                   R                  U R                  SSSUS-
  5        U R                   R                  U R                  SUS-  S-
  SUS-  S-
  5        U R                  R                  5       u  ppU R                  R                  S	U-
  S
U	-
  5        U R                  R                  5       u  ppU R                  R                  XJ-
  S	-
  S
U	-
  5        S	nU R                  R                  5        H  n[        U[         5      (       aH  SSU R"                  SSU R$                  S.n['        U R                   U40 UD6nSUR)                  5       S'   O [+        U R                   USU R$                  S9nUR-                  U R.                  5        U R                  R1                  U5        U R                  R3                  UX5        UR                  5       S   S-   nM     SnU R                  R5                  5        Hq  n[+        U R                   USU R$                  S9nU R
                  R1                  U5        U R                  R3                  UUU5        UR                  5       S   S-   nMs     [7        U R
                  5      S:  a  XR
                  S   R9                  5       -  n[;        XR                  R9                  5       S-   5      nU R                  R9                  5       S-   nX[;        UU5      -
  :  a  U[;        UU5      -   nU R
                   H  nUR                  SU-   U-
  S5        M     U R                  R                  X@R                  R                  5       S   -
  S	-
  S5        X-   [;        UU5      -
  S-  nU R                   R                  U R<                  USUS5        U R                  R                  5       u  pp[7        U R
                  5      S:  aM  UU 4S jnU R
                  S   R?                  U5        U R
                  S   R-                  U R@                  5        U RC                  5         g )Nscrollregionc              3   8   #    U  H  n[        U5      v   M     g 7fN)int).0cs     r7   	<genexpr>)ShiftReduceApp._redraw.<locals>.<genexpr>  s     =1As   r   ixr     r   rN   r   r   z#4080a0#006060)
tree_color
tree_width	node_font
node_color
leaf_color	leaf_fontz#000000r   r   ra   c                 t    U R                  5       S   U:  a  UR                  5         g UR                  5         g )Nr   )bboxr   _redraw)widgetmidxr3   s      r7   
drag_shift*ShiftReduceApp._redraw.<locals>.drag_shift  s'    ;;=#d*JJLLLNr:   )"r/   splitr   r   destroy_widgetr   r   r  coordsr   r   mover   r!   stack
isinstancer   rG   rH   r   r   r   
bind_click_popup_reduceappendr   remaining_textrs   r   maxr   	bind_dragr   _highlight_productions)r3   r   cx1cy1cx2cy2stackwidgetrtextwidgetx1y1x2y2rg   stackxtokattribsr  
rtextwidthrlabelwidthr  r  s                        r7   r  ShiftReduceApp._redraw  sS   ||N399;==3  --KLL''4 .--KLL''4 .  ++002GbLDNNE1dAEBDNNAq1urz4QL  ++002a"fa"f-++002chlAF3 <<%%'C#t$$"+"#!%"+"+!% -T\\3J'J*3w'#DLL#YTZZXd001%%f-LL##FF6[[]1%*F# (( 
<<..0CcTF%%f-LL##FJ:q)A-J	 1 t!!"Q&((+1133F
 V--335:;&&,,.33z;7773z;77C--KQWz115 .c$4$4$9$9$;A$>>BAFs:{;;q@DNND!T4@++002 t!!"Q&(,4 # q!++J7q!,,TZZ8 	##%r:   c                     UR                  5       S   S-   nU R                  R                  U R                  USUS5        g )NrN   2   r   r  )r  r/   r  r   )r3   r  r  s      r7   _draw_stack_topShiftReduceApp._draw_stack_top  s5    {{}Q"$DNND!T4@r:   c                     U R                   R                  SS5        U R                  R                  5        H9  nU R                  R                  U5      nU R                   R                  U5        M;     g )Nr   r_   )rl   selection_clearr!   reducible_productionsro   indexselection_set)r3   prodr6  s      r7   r  %ShiftReduceApp._highlight_productions  sU    &&q%0LL668D%%++D1ENN((/ 9r:   c                 b    U R                   c  g U R                   R                  5         S U l         g r   )r"   r   r3   r   s     r7   r   ShiftReduceApp.destroy)  s&    99			r:   c                     U R                   R                  U R                  5        SU R                  S'   SU R                  S'   U R                  5         g )Nz	Reset Appr   r   )r!   
initializer    r2   r   r  r;  s     r7   r1   ShiftReduceApp.reset/  s=    

+"-"$r:   c                 &   U R                  5       (       a  gU R                  5       (       a  g[        U R                  R	                  5       5      (       a  SU R
                  S'   SU R                  S'   g SU R
                  S'   SU R                  S'   g )NTz	Finished:r   SuccessFailure)r   r   rm   r!   parsesr2   r   r;  s     r7   r   ShiftReduceApp.step5  sn    ;;==ZZ\\DLL'')***5'*3'*5'*3'r:   c                 d   U R                   (       a  g U R                  R                  5       (       a  U R                  R                  5       S   nSU R                  S'   SU-  U R
                  S'   U R                  R                  5       (       a  U R                  5         gU R                  5         gg)Nrh   zShift:r   z%rTF)
r$   r!   r   r  r2   r   r%   rF   _animate_shiftr  )r3   r   r*  s      r7   r   ShiftReduceApp.shiftB  s    <<,,$$&r*C&.DOOF#&*SjDOOF#}}  ""##%  r:   c                 0   U R                   (       a  g U R                  R                  5       nU(       ab  SU R                  S'   SU-  U R                  S'   U R
                  R                  5       (       a  U R                  5         U$ U R                  5         U$ )NReduce:r   %s)	r$   r!   r   r2   r   r%   rF   _animate_reducer  )r3   r   r|   s      r7   r   ShiftReduceApp.reduceP  s|    \\((*
&/DOOF#&*Z&7DOOF#}}  ""$$&  r:   c                     U R                   (       a  g U R                  R                  5       (       a  U R                  5         g g r   )r$   r!   r   r  r;  s     r7   r   ShiftReduceApp.undo]  s/    <<LLN r:   c                 8    U R                   R                  5         g r   )r   print_to_filer;  s     r7   r   ShiftReduceApp.postscriptc  s    ""$r:   c                 \    [        5       (       a  gU R                  R                  " U0 UD6  g)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)r3   argskwargss      r7   rS  ShiftReduceApp.mainloopf  s%     99		D+F+r:   Nc                 f   Ub  U R                   R                  U5        U R                   R                  5       nU R                  R	                  [        U5      * S9  U R                  R	                  [        U5      * S9  U R                  R	                  [        U5      * S9  U R                  5         g )N)r=   )	rD   r&   rF   rH   	configureabsrG   rB   r  )r3   r=   s     r7   r   ShiftReduceApp.resizeu  s    JJNN4 zz~~

CI,/  D	l 3s4y\2 	r:   c                      [        U R                  S[        =(       d    SR                  5       SSS9  g !   [        U R                  S[        =(       d    SR                  5       SS9   g = f)Nz%Help: Shift-Reduce Parser Applicationr   K   fixed)r   r<   r   )r   r"   __doc__stripr;  s     r7   r   ShiftReduceApp.help  s[    			7B%%'			7B%%'	s	   25 3A*c                 |    SnSn SSK Jn  U" X#S9R                  5         g !   [        U R                  X25         g = f)Nz<NLTK Shift-Reduce Parser Application
Written by Edward Loperz&About: Shift-Reduce Parser Applicationr   )Message)messager#   )tkinter.messageboxrc  showr   r"   )r3   r   ABOUTTITLErc  s        r7   r   ShiftReduceApp.about  s:    T8	.2E/446	.TYY-s   ! ;c                 v    [        U R                  U R                  R                  5       U R                  5        g r   )r   r"   r!   r4   set_grammarr;  s     r7   r   ShiftReduceApp.edit_grammar  s%    $))T\\113T5E5EFr:   c                    U R                   R                  U5        [        UR                  5       5      U l        U R
                  R                  SS5        U R                   H"  nU R
                  R                  SSU-  5        M$     g )Nr   r_   r`   )r!   rk  rm   rn   ro   rl   deleterp   )r3   r4   r|   s      r7   rk  ShiftReduceApp.set_grammar  sg      ) !4!4!67a'++JNN!!%%**<> ,r:   c                     SR                  U R                  5      nSnSn[        U R                  X$U R                  U5        g )N r   zEnter a new sentence to parse.)joinr    r   r"   set_sentence)r3   r   sentencer#   instrs        r7   r   ShiftReduceApp.edit_sentence  s6    88DJJ'0DIIx0A0A5Ir:   c                 N    UR                  5       U l        U R                  5         g r   )r  r    r1   )r3   r5   s     r7   rs  ShiftReduceApp.set_sentence  s    ZZ\


r:   c                    U R                   R                  5       (       a6  U R                  R                  SSSU R                  S9  SU R
                  S'   O)U R                  R                  5         SU R
                  S'   SU R                  S'   g )	NrL   rM   rN   )rO   rP   rQ   afterr   r   zHide Grammarr   )r'   rF   ri   rj   r   r2   pack_forgetr   r;  s     r7   r   ShiftReduceApp._toggle_grammar  sy    !!##OO  &q8K8K !  '5DOOF#OO'')&4DOOF#"$r:   c                 |   U R                   R                  5       n[        U5      S:w  a  g [        US   5      nU R                  R                  U R                  U   5      nU(       ab  SU R                  S'   SU-  U R                  S'   U R                  R                  5       (       a  U R                  5         g U R                  5         g U R                   R                  SS5        U R                  R                  5        H9  nU R                  R                  U5      nU R                   R!                  U5        M;     g )Nr   r   rI  r   rJ  r_   )rl   curselectionrs   r   r!   r   ro   r2   r   r%   rF   rK  r  r4  r5  r6  r7  )r3   event	selectionr6  r|   r8  s         r7   rv   ShiftReduceApp._prodlist_select  s    NN//1	y>QIaL!\\(():):5)AB
&/DOOF#&*Z&7DOOF#}}  ""$$& NN**1e4::<))//5,,U3 =r:   c                    U R                   R                  5       n[        U5      S:X  a  g U R                  R	                  SS5        U H0  nU R                  R                  [        U5      U R                  S9  M2     U R                  R                  U R                  R                  5       U R                  R                  5       5        g )Nr   r_   )r   rf   )r!   r5  rs   r0   rn  r   strr   postr/   winfo_pointerxwinfo_pointery)r3   r  rn   r|   s       r7   r  ShiftReduceApp._popup_reduce  s    ll88:{q   E*%J))J)U &LL'')4<<+F+F+H	
r:   c                 2   U R                   S   nUR                  5       S   n[        U R                  5      S:X  a  SnO#U R                  S   R                  5       S   S-   nU R                  R                  5       nX2-
  S-  U-  nU R                  XAU5        g )Nr   r   rh   rN   r   g      ?)r   r  rs   r   r%   rF   _animate_shift_frame)r3   r  r\   rM   dtdxs         r7   rF  ShiftReduceApp._animate_shift  s    ##A& a t!!"a'D%%b)..03b8D ]] lc!B&!!"b1r:   c                 :   US:  aE  SU l         UR                  US5        U R                  R                  SU R                  US-
  X#5        g U R
                  S	 U R                  R                  U5        SU l         U R                  U5        U R                  5         g )Nr   r   r   )
r$   r  r"   rz  r  r   r   r  r1  r  )r3   framer  r  s       r7   r  #ShiftReduceApp._animate_shift_frame  s    19#$D KKAIIOOB 9 9519fQ
 ""1%%%f-#$D    ('')r:   c                    [        U R                  R                  5       S   5      nU R                  U* S  n[	        US   [
        5      (       a%  SUS   R                  5       R                  5       -   nOSUS   R                  5       -   nU R                  R                  5       nUS-  U-  nU R                  US-  X%5        g )Nrh   r      g       @rN   )rs   r!   r  r   r  r   r   rb   r%   rF   _animate_reduce_frame)r3   
numwidgetswidgetsydistr  dys         r7   rK  ShiftReduceApp._animate_reduce  s    ++-b12
$$j[\2 gaj"344))+2244E**,,E ]] S[2""2677r:   c                    US:  aN  SU l         U H  nUR                  SU5        M     U R                  R                  SU R                  US-
  X#5        g U R
                  [        U5      * S 2	 U H  nU R                  R                  U5        M      U R                  R                  5       S   n[        U[        5      (       d
  [        5       e[        U R                  [!        UR#                  5       5      SU R$                  S9n['        U R                  XbSS9nU R(                  R+                  5       u  pxpX-
  S-   nU R
                  (       d  S	nO#U R
                  S   R+                  5       S   S-   nU R                  R-                  XLU5        U R
                  R/                  U5        U R1                  U5        U R3                  5         SU l         g )
Nr   r   r   rh   r  r   rN   r^  r   )r$   r  r"   rz  r  r   rs   r   remove_widgetr!   r  r  r   
ValueErrorr   r/   r  r   rG   r   r   r  r   r  r1  r  )r3   r  r  r  r  r*  r   r%  r&  r'  r(  rg   r   s                r7   r  $ShiftReduceApp._animate_reduce_frame  s   19#$D !Ar" "IIOOB : :EAIwS""CL=?3!**62 ",,$$&r*Cc4(( l"c#))+.idnnE 't||U1MF#//446RR"A%%&&r*//1!4r9LL##Fq1%%f-   ('')8 $%D r:   c                    U R                   R                  UR                  5      nU R                  U:X  a  g U R	                  5         U R                   R                  5        Vs/ s H  n[        U5      PM     nnX$;   al  [        U R                  U   R                  5       5      nU R                  U* S   H2  n[        U[        5      (       a  SUR                  5       S'   M-  SUS'   M4     X l        g s  snf )Nz#00a000r   )rl   nearestrg   rw   ry   r~  r   rs   ro   rhsr   r  r   r   )r3   r  r6  sr  rhslenr#  s          r7   rx   ShiftReduceApp._highlight_hoverY  s    &&uww/;;% 	 &*^^%@%@%BC%BSV%B	C**515578F#116'(;k+<==3<K%%'0+4K(	  <  Ds   #C2c                     U R                   S:X  a  g SU l         U R                   H2  n[        U[        5      (       a  SUR	                  5       S'   M-  SUS'   M4     g )Nrh   r   r   )rw   r   r  r   r   )r3   r  r#  s      r7   ry   ShiftReduceApp._clear_hoverp  sS    ;;"--K+'899/6!!#G,'.G$	 .r:   )r%   r$   rG   r   r/   r   r   r   rH   rw   r2   r   r   r!   ri   rl   rk   ro   r0   r   r   r    r'   rD   r   r   r   rB   r   r"   )r   r   ))__name__
__module____qualname____firstlineno__r_  r8   r(   r-   r)   r+   r*   r,   r.   r  r1  r  r   r1   r   r   r   r   r   rS  r   r   r   r   rk  r   rs  r   rv   r  rF  r  rK  r  rx   ry   __static_attributes__ r:   r7   r   r   W   s    $%T
E':R AD"HA$F>.2BU&nA
04%	,"$.G?J	%4(
"2 *"8 8%|.	/r:   r   c                    ^ SSK Jn JmJn  SnU4S jUR	                  5        5       u	  p4pVpxpnU" X5U/5      U" X[U/5      U" XUU/5      U" XDU/5      U" XJXV/5      U" XJU/5      U" XgU/5      U" US/5      U" US/5      U" US/5      U" US/5      U" U
S	/5      U" US
/5      U" US/5      U" US/5      U" US/5      U" US/5      U" US/5      4nU " X<5      nSR	                  5       n[        X5      R                  5         g)zD
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   4   >#    U  H  nT" U5      v   M     g 7fr   r  )r   r  r  s     r7   r  app.<locals>.<genexpr>  s     *XCWa;q>>CWs   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   rS  )r  r  nonterminalsSVPNPPPPNNameVDetrn   r4   r5   r  s                  @r7   appr  |  s<    :9.L*X<CUCUCW*X'QBA$3 	12h2Qx 2Bx 2Bx 22{#22w22w2u3 31ug1ug1tf1vh1vh1ug1xj!3)K. !!G 8==?D7!**,r:   __main__r  N)r_  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__r  r:   r7   <module>r     s]   7r O N N  G G I I 0  
b/ b/J'-T zE'r:   