/
OutlineoftheLecture OutlineoftheLecture

OutlineoftheLecture - PDF document

min-jolicoeur
min-jolicoeur . @min-jolicoeur
Follow
378 views
Uploaded On 2016-08-11

OutlineoftheLecture - PPT Presentation

Whatissyntaxanalysis Specicationofprogramminglanguagescontextfreegrammars Parsingcontextfreelanguagespushdownautomata TopdownparsingLL1andrecursivedescentparsing BottomupparsingLRparsin ID: 441649

Whatissyntaxanalysis? Specicationofprogramminglanguages:context-freegrammars Parsingcontext-freelanguages:push-downautomata Top-downparsing:LL(1)andrecursive-descentparsing Bottom-upparsing:LR-parsin

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "OutlineoftheLecture" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

OutlineoftheLecture Whatissyntaxanalysis? Specicationofprogramminglanguages:context-freegrammars Parsingcontext-freelanguages:push-downautomata Top-downparsing:LL(1)andrecursive-descentparsing Bottom-upparsing:LR-parsing Y.N.Srikant Parsing Derivations E)E!E+EE+E)E!idid+E)E!idid+idisaderivationoftheterminalstringid+idfromE Inaderivation,aproductionisappliedateachstep,toreplaceanonterminalbytheright-handsideofthecorrespondingproduction Intheaboveexample,theproductionsE!E+E,E!id,andE!id,areappliedatsteps1,2,and,3respectively Theabovederivationisrepresentedinshortas,E)id+id,andisreadasSderivesid+id Y.N.Srikant Parsing DerivationTrees Derivationscanbedisplayedastrees Theinternalnodesofthetreeareallnonterminalsandtheleavesareallterminals CorrespondingtoeachinternalnodeA,thereexistsaproduction2P,withtheRHSoftheproductionbeingthelistofchildrenofA,readfromlefttoright Theyieldofaderivationtreeisthelistofthelabelsofalltheleavesreadfromlefttoright If istheyieldofsomederivationtreeforagrammarG,thenS) andconversely Y.N.Srikant Parsing DerivationTreeExample Y.N.Srikant Parsing LeftmostandRightmostDerivations:AnExample Y.N.Srikant Parsing EquivalentUnambiguousGrammar Y.N.Srikant Parsing AmbiguityExample2(contd.) Y.N.Srikant Parsing FragmentofC-Grammar(Statements) program�--VOIDMAIN'('')'compound_stmtcompound_stmt�--'{''}'|'{'stmt_list'}'|'{'declaration_liststmt_list'}'stmt_list�--stmt|stmt_liststmtstmt�--compound_stmt|expression_stmt|if_stmt|while_stmtexpression_stmt�--';'|expression';'if_stmt�--IF'('expression')'stmt|IF'('expression')'stmtELSEstmtwhile_stmt�--WHILE'('expression')'stmtexpression�--assignment_expr|expression','assignment_expr Y.N.Srikant Parsing FragmentofC-Grammar(ExpressionsandDeclarations) relational_expr�--add_expr|relational_expr'add_expr|relational_expr&#x'-60;�''add_expr|relational_exprLE_OPadd_expr|relational_exprGE_OPadd_expradd_expr&#x'-60;�--mult_expr|add_expr'+'mult_expr|add_expr'-'mult_exprmult_expr&#x'-60;�--unary_expr|mult_expr'*'unary_expr|mult_expr'/'unary_exprdeclarationlist&#x'-60;�--declaration|declarationlistdeclarationdeclaration&#x'-60;�--typeidlist';'idlist&#x'-60;�--idlist','ID|IDtype&#x'-60;�--INT_TYPE|FLOAT_TYPE|CHAR_TYPE Y.N.Srikant Parsing PDA-Examples L=f0n1njn0gM=(fq0;q1;q2;q3g;f0;1g;fZ;0g;;q0;Z;fq0g),whereisdenedasfollows(q0;0;Z)=f(q1;0Z)g,(q1;0;0)=f(q1;00)g,(q1;1;0)=f(q2;)g,(q2;1;0)=f(q2;)g,(q2;;Z)=f(q0;)g (q0;0011;Z)`(q1;011;0Z)`(q1;11;00Z)`(q2;1;0Z)`(q2;;Z)`(q0;;) (q0;001;Z)`(q1;01;0Z)`(q1;1;00Z)`(q2;;0Z)`error (q0;010;Z)`(q1;10;0Z)`(q2;0;Z)`error Y.N.Srikant Parsing

Related Contents


Next Show more