Whatissyntaxanalysis Specicationofprogramminglanguagescontextfreegrammars Parsingcontextfreelanguagespushdownautomata TopdownparsingLL1andrecursivedescentparsing BottomupparsingLRparsin ID: 441649
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.
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 IfistheyieldofsomederivationtreeforagrammarG,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'-60;''add_expr|relational_exprLE_OPadd_expr|relational_exprGE_OPadd_expradd_expr'-60;--mult_expr|add_expr'+'mult_expr|add_expr'-'mult_exprmult_expr'-60;--unary_expr|mult_expr'*'unary_expr|mult_expr'/'unary_exprdeclarationlist'-60;--declaration|declarationlistdeclarationdeclaration'-60;--typeidlist';'idlist'-60;--idlist','ID|IDtype'-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