JL iydZddlmZmZmZmZmZmZmZm Z ddl m Z ddl m Z mZmZddlmZmZmZmZddlmZddlmZddlmZGd d Zd Zed k(red gZy)a A graphical tool for exploring the recursive descent parser. The recursive descent parser maintains a tree, which records the structure of the portion of the text that has been parsed. It uses CFG productions to expand the fringe of the tree, and matches its leaves against the text. Initially, the tree contains the start symbol ("S"). It is shown in the main canvas, to the right of the list of available expansions. The parser builds up a tree structure for the text using three operations: - "expand" uses a CFG production to add children to a node on the fringe of the tree. - "match" compares a leaf in the tree to a text token. - "backtrack" returns the tree to its state before the most recent expand or match operation. The parser maintains a list of tree locations called a "frontier" to remember which nodes have not yet been expanded and which leaves have not yet been matched against the text. The leftmost frontier node is shown in green, and the other frontier nodes are shown in blue. The parser always performs expand and match operations on the leftmost element of the frontier. You can control the parser's operation by using the "expand," "match," and "backtrack" 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: - If the leftmost frontier element is a token, try matching it. - If the leftmost frontier element is a node, try expanding it with the first untried expansion. - Otherwise, backtrack. The "expand" button applies the untried expansion whose CFG production is listed earliest in the grammar. To manually choose which expansion to apply, click on a CFG production from the list of available expansions, on the left side of the main window. The "autostep" button will let the parser continue applying applications to the tree until it reaches a complete parse. You can cancel an autostep in progress at any time by clicking on the "autostep" button again. Keyboard Shortcuts:: [Space] Perform the next expand, match, or backtrack operation [a] Step through operations until the next complete parse [e] Perform an expand operation [m] Perform a match operation [b] Perform a backtrack operation [Delete] Reset the parser [g] Show/hide available expansions list [h] Help [Ctrl-p] Print [q] Quit )ButtonFrameIntVarLabelListboxMenu ScrollbarTk)Font) CFGEditorTreeSegmentWidgettree_to_treesegment) CanvasFrame EntryDialogShowText TextWidget)SteppingRecursiveDescentParser)Tree)in_idlec6eZdZdZd3dZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZd4dZdZdZdZdZdZdZdZdZdZdZdZdZdZ d Z!d!Z"d"Z#d4d#Z$d$Z%d%Z&d&Z'd'Z(d(Z)d)Z*d*Z+d+Z,d,Z-d-Z.d.Z/d/Z0d0Z1d1Z2d2Z3y)5RecursiveDescentAppa A graphical tool for exploring the recursive descent parser. The tool displays the parser's tree and the remaining text, and allows the user to control the parser's operation. In particular, the user can expand subtrees on the frontier, match tokens on the frontier against the text, and backtrack. A "step" button simply steps through the parsing process, performing the operations that ``RecursiveDescentParser`` would use. cr||_t|||_t|_|jj d|j |j|jt|j|_ |jjdd|_ d|_ t|j|_ |jjd|j|j|j|j|j!|j|j#|j|j%|j|jj'|j|j(j+d|j,y)Nz$Recursive Descent Parser Applicationrz )_sentr_parserr _toptitle_init_bindings _init_fontsr_animation_framesset_animating_lock _autostep _show_grammar _init_menubar _init_buttons_init_feedback _init_grammar _init_canvas initialize_canvasbind _configure)selfgrammarsenttraces [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/app/rdparser_app.py__init__zRecursiveDescentApp.__init__Xs@ 5guE D  >?  #"( !2 ""1% $DII. q! 499% 499% DII& 499% $))$  + -9c|ttd|_|jd|jt ||_|j j |jjdtdd|j j|_ td|j j|_ |j jd kr|j jd z }n|j jd z}tdd||_ y) Nfontr7z*Fontsize helveticabold)familyweightr9)r<r9r) r r_sysfont option_addr_sizer"cgetget _boldfont_font_bigfont)r/rootbigs r3r zRecursiveDescentApp._init_fontss&(6"23  /D\  t}}))&12[djjnnFVW4::>>3CD ::>> a **.."Q&C**.."Q&CKSI r5c  t|x|_}|jjdddt|j|jd|_|j jt |jddd d |jd d |_|jjdddt|jjj|_ |jD]!}|jjdd|z#|jjt!t#|jdt#|jdkDrvt%|jd}|jj|j&|j|jj(|jdd|jj+d|j,y)Nbothleftr>)fillsidepadxzAvailable Expansions)r7textsinglegroovewhitez#909090#004040z#c0f0c0) selectmoderelief background foregroundr7selectforegroundselectbackgroundrightrrMrLexpandendz %s)heightvertical)orient)yscrollcommand)commandy)rMrLz<>)r _prodframepackrrD_prodlist_labelrrE _prodlistlistrr0 productions _productionsinsertconfigminlenr r"yviewr-_prodlist_select)r/parent listframe production listscrolls r3r)z!RecursiveDescentApp._init_grammars&+Fm3) &vA>$ OO$..7M  !!# OO &&   va@ !5!5!7!C!C!EF++ @J NN ! !%&:*= ? @ ST->->)?%DE t  !B &"4??:FJ NN ! ! ! @   dnn&:&:  ; OOcO 2 /1F1FGr5c|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j |jjd |j |jjd |j |jjd |j |jjd |j |jjd |j |jjd|j |jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjd|j|jjd|jy)Nz z zemzz bzz z z azz zzz z zz z )rr-destroyr\match backtrackautostepcancel_autostepstepreset postscripthelp edit_grammar edit_sentencer/s r3rz"RecursiveDescentApp._init_bindingss }dll3 }dll3 z4<<0 sDKK( sDJJ' y$**- }djj1 sDNN+ y$..1 }dnn5 }dnn5 }dnn5 sDMM* ($--8 }d&:&:; y$)), z4::. }doo6 }dii0 vtyy) }d&7&78 }d&8&89r5ct|x|_}|jddddt|ddd|j jd t|d dd|j jd t|d ddd|j jd t|dddd|jjd t|dddd|jjd y)Nnonebottomr>rLrMrNpadyStepz#90c0d0black)rOrVrWrcrKrMAutostepExpandrz#90f090)rO underlinerVrWrcMatch Backtrackz#f0a0a0) r _buttonframerfrrr~r\r|r})r/rr buttonframes r3r'z!RecursiveDescentApp._init_buttonss*/-7Kf8!!D  II  $F$   MM  $F$   KK   $F$   JJ   $F$   NN   $F$ r5cd|_|jj\}}}}|jdz }d||||fz|jd<|j y)Nrz %d %d %d %d scrollregion)r$_cframerr_r,_redraw)r/eventx1y1x2y2s r3r.zRecursiveDescentApp._configuresW<<446RR \\A '4BB7G'G ^$ r5ct|x|_}|jddddt|d|j|_|j jdt|d d }|jdd d d t|dd|j|_t|dddd|j|_|j jd|jjddd y)NxrrrzLast Operation:)rOr7rKrsunkenr)rUborderrZr)rLrMr\rNz#007070z#f0f0f0)rWrVr7wrS)anchorwidthrWrVr7r[)r_feedbackframerfrrE_lastoper_label _lastoper1 _lastoper2)r/rr feedbackframe lastoperframes r3r(z"RecursiveDescentApp._init_feedbacks.3Fm;m(C$  1   !!v!.mHQG '!!D iIDJJ       &) &s1=r5ct|dddd|_|jjdddd |jjx}|_d|_g|_d|_y) NrR r>r)rV closeenoughrrUrrJtop)r\rLrMr)rrrfcanvasr,_tree _textwidgets _textline)r/rrrs r3r*z RecursiveDescentApp._init_canvas&sk"     e!D $ 3 3 55 r5ct|}t|d}|jdd|jd|jdd|jd|jdd |jd |j d d| t|d}|jd d|j d|jdd|jd|j dd| t|d}|jdd |jd|j|jdd|jd|jdd|jd|j|jdd|jd|j dd| t|d}|jdd|j|j|j|j!d|j"dd|j$ |j!d!|j"dd"|j$ |j!d#|j"dd$|j$ |j!d%|j"dd&|j$ |j!d'|j"dd(|j$ |j d)d| t|d}|j!d*d|j&d+|j!d,d|j&dd-.|j!d/d|j&dd0.|j!d1d|j&d2d3.|j d4d | t|d}|jd5d|j(6|jd7d|j*d8|j d9d| |j-|:y);Nr)tearoffz Reset ParserDel)labelrrc acceleratorzPrint to PostscriptzCtrl-pExitrzCtrl-xFile)rrmenuz Edit GrammarrzCtrl-g Edit TextzCtrl-tEditrSpacerzCtrl-mrzCtrl-erzCtrl-bApply Show Grammar)rrvariablercTinyr)rrrvaluercSmall MediumLargeHugeViewz No Animation)rrrrzSlow Animation-)rrrrrzNormal Animation=zFast Animationr>+AnimateAbout)rrrc InstructionsF1Help)r)r add_commandrrr{ add_cascaderrr add_separatorr|r\r}add_checkbuttonr%_toggle_grammaradd_radiobuttonrAresizer!aboutrrm) r/rrmenubarfilemenueditmenurulemenuviewmenu animatemenuhelpmenus r3r&z!RecursiveDescentApp._init_menubar7s*v,+ Atzzu   'OO  At||   &AHE+ %%  &&  &AHE+Atyyg    Q    a(    DNNPX   'QXF+   ''(( !    ZZKK !    ZZKK !    ZZKK !    ZZKK !    ZZKK !  &AHE7A. ## A8N8NVW $  ##"++ $  ##$++ $  ##"++ $  )q{K+7aL Atyyd   &AHE 7 #r5cz|D]}|j|}t|tr|j}|SN)subtrees isinstancer r)r/widgettreelocis r3_getzRecursiveDescentApp._gets= *A__&q)F * f/ 0\\^F r5c|j}|j%|jj|j|jD]}|jj||j %|jj |j d|jj f}d|jj df}dd||d}|jj}t||fi||_|jj|jddd|jj f}|jjdx}}|jD cgc]} t|| |j c} |_|jD]e}|jj|d d |j#d ||j%dz dz t'||j%d }g|j)d |dz d |dz d|_|j+|j-|j/ycc} w)Nr:r;#000000r>) tree_color tree_width node_font leaf_fontrrrr8rrixi.)dash)r,rrdestroy_widgetrrdeleterArCrtreer add_widgetrrrrEmovebboxrn create_line_highlight_nodes_highlight_prodlist_position_text) r/rtwidgethelvr;attribsrrrdwords r3rzRecursiveDescentApp._redraws :: ! LL ' ' 3(( 1G LL ' ' 0 1 >> % LL   /djjnn../djjnn..7#   ||  "(AA   B2djjnn../\\..033BF** :>Jvt$** 5 (( *G LL # #GQ 2 LLFW\\^A%66: ;Aw||~a()A *  ++E1q5$AC+P    " ! s:I'cd|j|j|jyr)rrrrs r3 _redraw_quickz!RecursiveDescentApp._redraw_quicks&    " r5cd|jj df}|jjddD]@}d|j |j |d<||j |j |d<B|jjddD]!}d|j |j |d<#y)Nr:r;r#20a050colorr7z#008080)rArCrfrontierrr)r/r;rs r3rz$RecursiveDescentApp._highlight_nodessdjjnn..7||,,.r2 :G6?DIIdjj' *7 359DIIdjj' *6 2 :||,,.qr2 @G6?DIIdjj' *7 3 @r5c|jjdd|jj}|jj }|j }t t|D]}|||vrh|||vr#|jj|d||zn"|jj|d||z|jj|r|jj|d||zy)Nrr] %sz %s (TRIED)) rhrrexpandable_productionsuntried_expandable_productionsrkrangerorl selection_set)r/ expandableuntriedrjindexs r3rz'RecursiveDescentApp._highlight_prodlists a'\\88: ,,==?'' 3{+, IE5!Z/u%0NN))%U9K1KLNN))%UAS1ST,,U3%%eU[5G-GH Ir5ct|j}|t|jjz }|j d|}|j j d}tdt|D]m}|j|}||}d|d<d|d<|j|j d|j dz d|j ddz}ott||D]R}|j|}d|d<|j||j dz d|j ddz}T|jjr|jD]}d|d< tdt|D]}|j|}||}|j d|j d z d z } t| |jjj d |j d z dz} |jd| y) Nr#006040r r>rz#a0a0a0z#00a000rr$@)rorrremaining_text _tree_leavesrrrrrcurrently_completemaxrrr) r/numwords num_matchedleavesxmaxrrleafrdys r3rz"RecursiveDescentApp._position_textstzz?T\\%@%@%B!CC ""$\k2zz #q#f+& )A&&q)F!9D'F7O%DM KK Aq)991 =;;=#b(D  )s6{H- )A&&q)F'F7O KKv{{}Q// 3;;=#b(D  ) << * * ,,, -#,  -q#f+& A&&q)F!9Dq!DIIKN2T9BR,,.335a8499;q>IBNOB IIa   r5Nc| |j}t|tr-g}|jD]}||j |z }|S|gSr)rrr rr)r/rrchilds r3rz RecursiveDescentApp._tree_leaves9sV <::D d- .F 3$++E22 3M6Mr5cnd|_|jy|jjd|_yNr)r$rr{r/rws r3r{zRecursiveDescentApp.destroyHs- 99    r5cd|_|jj|jd|jd<d|j d<|j y)NrzReset ApplicationrO)r$rr+rrrrr%s r3rzRecursiveDescentApp.resetOsD  +"5"$ r5c|jjdk(r|jjd|jrd|_yd|_|j y)Nrr>r)r!rCr"r$_stepr%s r3r~zRecursiveDescentApp.autostepVsK  ! ! % % '1 ,  " " & &q ) >>DNDN JJLr5cd|_yr$)r$r%s r3rz#RecursiveDescentApp.cancel_autostep_s r5c2d|_|jyr$)r$r)r%s r3rzRecursiveDescentApp.stepds r5c2d|_|jyr$)r$_matchr%s r3r|zRecursiveDescentApp.matchhs r5c2d|_|jyr$)r$_expandr%s r3r\zRecursiveDescentApp.expandls r5c2d|_|jyr$)r$ _backtrackr%s r3r}zRecursiveDescentApp.backtrackps r5ct|jry|jrna|jjr|j rn6|j rn%d|j d<d|jd<d|_|jjrd|_|jdxxdz cc<yy)NFinishedrOr'rz [COMPLETE PARSE]) r#r/r untried_matchr-r1rrr$rrs r3r)zRecursiveDescentApp._stepts     <<>  \\ ' ' )dkkm  __  &0DOOF #&(DOOF #DN << * * ,DN OOF #'= = # -r5c|jry|jj}|jj}|d|jd<||j d<|j jdd|jj|}|j j||j|dyd|jd<d|j d<y)NExpand:rOrr]Tz(all expansions tried)F) r#rr r\rrrhselection_clearrkrr_animate_expand)r/rw old_frontierrvrs r3r/zRecursiveDescentApp._expands    ||,,. \\ " >&/DOOF #&(DOOF # NN * *1e 4%%++B/E NN ( ( /  a 1&/DOOF #&>DOOF #r5c,|jry|jj}|jj}|3d|jd<||j d<|j |dyd|jd<d|j d<y)NzMatch:rOrTz(failed)F)r#rr r|rr_animate_match)r/rwr9r:s r3r-zRecursiveDescentApp._matchs    ||,,. \\   ! >&.DOOF #&(DOOF #    Q 0&.DOOF #&0DOOF #r5c.|jry|jjr|jj}|jj dD]}||} d|j d<d|j d<t|tr-|j|jj dy|j|jj dyd|_ d|j d<d|j d<y)NrrrOr'Tr3F) r#rr}rr rrrr_animate_backtrack_animate_match_backtrackr$)r/rweltrs r3r1zRecursiveDescentApp._backtracks     << ! ! #,,##%C\\**,Q/ !f &1DOOF #&(DOOF ##t$'' (=(=(?(BC--dll.C.C.Ea.HIDN&0DOOF #&(DOOF #r5cd}d} ddlm}|||jy#t|j||YyxYw)NzANLTK Recursive Descent Parser Application Written by Edward Loperz+About: Recursive Descent Parser Applicationr)Message)messager)tkinter.messageboxrBshowrr)r/rwABOUTTITLErBs r3rzRecursiveDescentApp.aboutsC U > . 2 E / 4 4 6 . TYYu -s %Acd|_ t|jdtxsdj ddy#t|jdtxsdj dYyxYw)Nrz*Help: Recursive Descent Parser Applicationr'Kfixed)rr7)r)r$rr__doc__stripr%s r3rzRecursiveDescentApp.helpsb   <B%%'     <B%%'  s 0:1A-cFd|_|jjyr$)r$r print_to_filer%s r3rzRecursiveDescentApp.postscripts ""$r5cRtry|jj|i|y)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)rrmainloop)r/argskwargss r3rPzRecursiveDescentApp.mainloops% 9  D+F+r5c||jj||jj}|jj t | |j j t | |jj t | |jj t |dz |jy)N)r9r>) rAr"rCrE configureabsrDr?rFr)r/r9s r3rzRecursiveDescentApp.resizes   JJNN4 zz~~ CI,/   D l 3 s4y\2 s4!8}%56 r5c|jjr9|jjddd|jd|j d<n)|jj d|j d<d|jd<y) NrJrKr>)rLrMrNafterrrOz Hide Grammarr')r%rCrerfrr pack_forgetrr%s r3rz#RecursiveDescentApp._toggle_grammarsv    ! ! # OO &q8K8K ! '5DOOF # OO ' ' )&4DOOF #"$r5c|jj}t|dk7ryt|d}|jj }|jj |j|}|rjd|jd<||jd<|jjdd|jj||j|dy|jjdd|jjD]8}|jj|}|jj|:y)Nrrr6rOr])rh curselectionrointrr r\rkrrr7rr8r r)r/r selectionrr9rtprods r3rqz$RecursiveDescentApp._prodlist_selectsNN//1 y>Q  IaL!||,,. \\(():):5)AB &/DOOF #&0DOOF # NN * *1e 4 NN ( ( /  a 1 NN * *1e 4 ;;= 4))//5,,U3 4r5c |j|j|}|j}t|jt }|j j }|D]}||} t|j||jdddd|j}d|jd<|jjdd\}} |jjdd\} } |j|| z | | z |rY|jj|dd|jd|jjdz d||_n |jj!|||j#r||jj%dz z|j#djddz z |j#djddz z } |j#D]} | j| d|j'||r|jj)|n|j+t-|j.j1dd Dcgc]1}d d t3d |z|j.j1z zz3}}|jd dz|jj5|j6d z }|dkDrJ|j8D]}|jd||jj|j6d||j;||ycc}w)NrRr>)r leaf_colorrr node_colorrrr rrrgray%drrr)rrrrrr rrrr,rDrErrrrr replace_childrr _makeroomrr{rr!rCr[coordsrr_animate_expand_frame)r/r oldwidgetoldtreerrrroldxoldynewxnewydxsubtreercolorsr rs r3r8z#RecursiveDescentApp._animate_expand)sIIdjj'2 ""$W^^-/@AA||  " A7D % LL nnjj  #, w}}++-bq1 t||~**,Ra0 t D4K-  LL # #FAq 1 KKV\\^002155q 9DJ NN  * *7F ; ?? ,,.&&(1,-//#A&++-a0145//#A&++-a0145  "??, $ R# $ v  LL ' ' 0 OO 411557B?  Sa$*@*@*D*D*F!FGG H  [[]1  "T\\%8%8%H%K K 6,, $ Q# $ LL  dnna 4 ""662 s"6M;c$|j}t|tsy|jj |}|j|dzd}|rF|j d|dj dz dz}|D]}|j |d|dkDr\|j|dz }td|j d|j dz dz}|j |d|j|y)z@ Make sure that no sibling tree bbox's overlap. Nrr>rr) rrrr rrrrrrd)r/treesegrrr rsiblingsrmsiblinglsiblings r3rdzRecursiveDescentApp._makeroomjs!&"34 !''0OO%eaik2 "Yq\%6%6%8%;;b@B$ $ R# $ 19(3HQ *W\\^A->>CDB LLQ  vr5c2t|dkDrd|_|d|d<|jD]1}t|tr|d|j d<*|d|d<3|j jd|j||ddyd|d<|jD]+}t|trd|j d<'d|d<-|jd|j d<d|_|jr|jyy)Nrrr 2r) ror#rrr rrrWrfrr$r))r/rrorns r3rfz)RecursiveDescentApp._animate_expand_frames v;?#$D $QiF7O!??, 1g'89/5ayGMMOG,'-ayGG$  1 IIOOB : :FF12J O%F7O!??, /g'89/6GMMOG,'.GG$  /    &-FLLN7 ##$D ~~ r5c L|jjdk(rg}ngd}|td|jjdzDcgc]1}ddtd|z|jjz zz3c}z }|j |j |j g}|djD]C}t|tr |j|j3|j|E|j||ycc}w)Nr)#a00000rrxrrbr) r!rCrr[rrrrrrr appendr_animate_backtrack_frame)r/rrorwidgetsrns r3r>z&RecursiveDescentApp._animate_backtracks  ! ! % % '1 ,F6F1d4488:Q>?  Sa4+A+A+E+E+G!HII J   99TZZ188:;qz**, (G'#45w}}/w'  ( %%gv6 s6D!ct|dkDrBd|_|D] }|d|d< |jjd|j||ddy|dj D]&}|dj ||j(|jd|_|jr|jyy)Nrrr rv) ror#rrWrzr remove_childr{rr$r))r/r{rors r3rzz,RecursiveDescentApp._animate_backtrack_frames v;?#$D ! ,"()w , IIOOB = =wqr S!!*--/ ! ''/  !    #$D ~~ r5cl|j|j|}|jj}|j d|j dz dzt d|j jz }|j|j j||y)Nrrr) rrrrrrrr!rC_animate_match_backtrack_frame)r/rrnoder s r3r?z,RecursiveDescentApp._animate_match_backtracks4::w/}}$$&iik!nv{{}Q//"4 t%%))+9   ++D,B,B,F,F,H&RTUr5cJ|j|j|}|jdjd|jdz dz t d|j j z }|j|j j ||y)Nrrrr)rrrrrr!rC_animate_match_frame)r/rrr s r3r<z"RecursiveDescentApp._animate_matchs4::w/"'')!,v{{}Q/??$F# t%%))+K   !!$"8"8"<"<">Kr5c |dkDrFd|_|jd||jjd|j|dz ||yd|d<|j d|_|j r|jyy)Nrrrrr )r#rrrWrrr$r)r/framerr s r3rz(RecursiveDescentApp._animate_match_framess 19#$D KK2  IIOOB 9 9519fb Q'F7O    #$D ~~ r5c@|dkDrFd|_|jd||jjd|j|dz ||y|j j ||jd|_|jr|jyy)Nrrr) r#rrrWrrrr}r{r$r)rs r3rz2RecursiveDescentApp._animate_match_backtrack_frames 19#$D KK2  IIOOD77FB  MMO ( ( 0 NN #$D ~~ r5cvt|j|jj|jyr)r rrr0 set_grammarr%s r3rz RecursiveDescentApp.edit_grammars%$))T\\113T5E5EFr5c|jj|t|j|_|j j dd|jD]!}|j jdd|z#y)Nrr]r )rrrirjrkrhrrl)r/r0rts r3rzRecursiveDescentApp.set_grammarsl   ) !4!4!67 a'++ ?J NN ! !%%**< > ?r5cdj|j}d}d}t|j|||j|y)N rzEnter a new sentence to parse.)joinrrr set_sentence)r/rwsentencerinstrs r3rz!RecursiveDescentApp.edit_sentences888DJJ'0DIIx0A0A5Ir5cN|j|_|jyr)splitrr)r/rs r3rz RecursiveDescentApp.set_sentences^^%  r5)rr)4__name__ __module__ __qualname__rKr4r r)rr'r.r(r*r&rrrrrrrr{rr~rrr|r\r}r)r/r-r1rrrrPrrrqr8rdrfr>rzr?r<rrrrrrr5r3rrMs$:TJ""HH:B)`>."A$N+Z @I$ D  >*$ ( .&% , %,42?3B4.7( VL  G?J r5rcddlm}|jd}dj}t ||j y)zV Create a recursive descent parser demo, using a simple grammar and text. r)CFGaD # Grammatical productions. S -> NP VP NP -> Det N PP | Det N VP -> V NP PP | V NP | V PP -> P NP # Lexical productions. NP -> 'I' Det -> 'the' | 'a' N -> 'man' | 'park' | 'dog' | 'telescope' V -> 'ate' | 'saw' P -> 'in' | 'under' | 'with' zthe dog saw a man in the parkN) nltk.grammarr fromstringrrrP)rr0r1s r3apprs= !nn G + 0 0 2D&//1r5__main__rN)rKtkinterrrrrrrr r tkinter.fontr nltk.drawr r rnltk.draw.utilrrrr nltk.parser nltk.treer nltk.utilrrrr__all__rr5r3rsW9vONNGGII5mm`28 zE 'r5