辅导CSCI3136程序、 写作Python,Java,c/c++程序

” 辅导CSCI3136程序、 写作Python,Java,c/c++程序Assignment 7Consider the grammar in Figure 1 where the terminal int denotes an integer and the terminal idS AtomsAtoms Atoms Atom AtomsAtom 0 AtomAtom idAtom intAtom ( Atoms )Figure 1: A simplified grammar for Scheme.denotes an identifier. The only other terminals in this grammar are the quote , the left parenthesis(, and the right parenthesis ).Scheme, a derivative of Lisp, is a list based language where all programs are represented bylists. For example, a simple Scheme program( + 1 2 )adds two numbers together and prints out the result. A scheme interpreter, /local/bin/scheme,is available on timberlea.cs.dal.ca. Feel free to give it a try. A program, which is zero or moreatoms is executed by evaluating each of the atoms. An atom is either an integer, an identifier, ora list. The evaluation of an integer is the integer, and the evaluation of an identifier, for now, issimply the identifier. The evaluation of a quoted atom is simply the atom itself. E.g., the evaluationof ( 1 2 3 ) is ( 1 2 3 ).A list is evaluated by evaluating the first atom of the list and treating the result as a function.Then each of the remaining atoms of the list is evaluated, and passed as parameters to the function.For example, the evaluation of ( + 1 2 ), treats + as a function, and passes 1 and 2 to the function.Applying + to 1 and 2 yields the result 3. Whereas, the evaluation of ( + 1 ( * 2 3 ) ), evaluates+ and 1 as before, but then evaluates ( * 2 3 ), yielding 6, which is then passed to the + function,which yields the result of 7.1. [8 marks] Consider the following L-attributed grammar, based on the grammar specifiedin Figure 1. Describe and justify what it is computing. Be sure to explain the purpose ofthe attributes, and what each of the semantic rules is doing. Your description must includea succinct summary of the purpose of this attribute grammar. I.e., Be sure to state what itis supposed to do, not just how it is doing it. 辅导CSCI3136作业、 写作Python,Java,c/c++程序CSCI3136 Summer 2020 Assignment 7Symbol Attribute TypeAtoms calls: int synthesizedcallable: bool synthesizedsymbol table: Symbol Table inheritedAtom calls: int synthesizedcallable: bool synthesizedsymbol table: Symbol Table inheritedIn the attribute grammar below, the symbol indicates a semantic rule that operates oninherited attributes, and the symbol indicates a semantic rule that operates on synthesizedattributes.S Atoms1 Atoms1.symbol table = getSymbolTable() print(Atoms1.calls)Atoms Atoms.calls = 0 Atoms.callable = falseAtoms Atom1 Atoms1 Atom1.symbol table = Atoms.symbol table Atoms1.symbol table = Atoms.symbol table Atoms.calls = Atom1.calls + Atoms1.calls Atoms.callable = Atom1.callableAtom 0 Atom1 Atom1.symbol table = Atom.symbol table Atom.calls = 0 Atom.callable = falseAtom id Atom.calls = 0 Atom.callable = Atom.symbol table.isFunction(id)Atom int Atom.calls = 0 Atom.callable = falseAtom ( Atoms1 ) Atoms1.symbol table = Atom.symbol table if Atoms1.callable then Atom.calls = Atoms1.calls + 1 Atom.callable = Atoms1.callable2. [8 marks] Suppose you wanted to construct an abstract syntax tree from parse tree derivedby using the grammar specified in Figure 1. Give an S-attributed grammar that creates anabstract syntax tree composed of the following kinds of tree nodes as illustrated in the UMLdiagram below.2CSCI3136 Summer 2020 Assignment 7All that is required is to create an abstract syntax tree. Observe that all you will need formost types of nodes is just the constructor (as shown) but for ListASTNode two methodsare provided to prepend and append nodes to a list. You will need one of these methods,depending on how you structure your attribute grammar.Please provide both the semantic rules and the attributes using notation similar to that inquestion 1.Provide a brief explanation of how the grammar works.3. [9 marks] Suppose that the base ASTNode class had a setNesting(int n) method that setsthe nesting level of the node in the abstract syntax tree. The nesting level is simply the numberof parentheses surrounding the symbol contained in the node. E.g., for ((a) b (c (d e)))the outer list is at nesting 0; the atoms (a), b, and (c (d e)) are at nesting 1; atoms a, c,and (d e) are at nesting 2; and atoms d and e are at nesting 3.Extend the S-attributed grammar from Question 2 into an L-attributed grammar that alsosets the nesting level of each node in the abstract syntax tree as it is created.Provide a brief explanation of how the grammar works.3CSCI3136 Summer 2020 Assignment 7Marking Scheme1. Marking scheme for Question 14 points 3 points 2 points 1 point 0 pointsAttributesUse of attributesproperly explainedUse of attributessomewhat explainedNo proper explanationof attributesRules All semanticrules explainedMost semanticrules explainedSome semanticrules explainedFew semanticrules explainedNo semanticrules explainedDescriptionPurpose ofgrammar isdescribedAttempt madeTo describepurposeNo attemptto describepurpose2. Marking scheme for Question 24 points 3 points 2 points 1 point 0 pointsAttributesAppropriateattributesspecifiedSomewhatappropriateattributesspecifiedAttributes notspecifiedRules Semantic rulesare correctMost semanticrules are correctSome semanticrules are correctFew semanticrules are correctNo semanticrules specifiedExplanationFunction ofgrammarExplainedFunction ofgrammar poorlyexplainedFunction ofgrammar notexplained3. Marking scheme for Question 34 points 3 points 2 points 1 point 0 pointsAttributesAppropriateattributesspecifiedSomewhatappropriateattributesspecifiedAttributes notspecifiedRules Semantic rulesare correctMost semanticrules are correctSome semanticrules are correctFew semanticrules are correctNo semanticrules specifiedExplanationFunction ofgrammarexplainedFunction ofgrammar poorlyexplainedFunction ofgrammar notexplainedNotationNotation differentiatesbetweensynthesized andinheritedattributesNotation doesnot differentiatebetweensynthesizedand inheritedattributes4CSCI3136: Assignment 7Summer 2020Student Name Login ID Student Number Student SignatureMarkQuestion 1 /8Question 2 /8Question 3 /9Total /25Comments:Assignments are due by 9:00am on the due date. Assignments must be submitted electronicallyvia Brightspace. Please submit a PDF for the written work. You can do your work on paperand then scan in and submit the assignment.Plagiarism in assignment answers will not be tolerated. By submitting their answers to thisassignment, the authors named above declare that its content is their original work and thatthey did not use any sources for its preparation other than the class notes, the textbook, andones explicitly acknowledged in the answers. Any suspected act of plagiarism will be reportedto the Facultys Academic Integrity Officer and possibly to the Senate Discipline Committee.The penalty for academic dishonesty may range from failing the course to expulsion from theuniversity, in accordance with Dalhousie Universitys regulations regarding academic integrity.如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导