هياكل البيانات والخوارزميات (DSA27) · الأسبوع 15

The Principles of Language Translation (Lecture 15)

هذه اختبارات للتدريب الذاتي، تُحفظ إجاباتك على هذا الجهاز فقط ولا تُرسل إلى أحد. الأسئلة والشرح بالإنجليزية لغة المقرر.

النتيجة: 0 / 22 · أُجيب: 0

  1. W15-M01 تذكّر

    The job of the lexer is to:

  2. W15-M02 تطبيق

    tokenize("12+3") returns a list of how many tokens?

  3. W15-M03 تذكّر

    calculate("3 + * 4") fails. Which stage rejects it?

  4. W15-M04 تذكّر

    "AST" stands for:

  5. W15-M05 تعليل

    In the grammar, * binds more tightly than + because:

  6. W15-M06 تطبيق

    calculate("2 + 3 * 4 - 1") returns:

  7. W15-M07 تطبيق

    The root of the AST of 2 * 3 + 4 is:

  8. W15-M08 تطبيق

    The root of the AST of (1 + 2) * (3 - 4) is:

  9. W15-M09 تعليل

    1 - 2 - 3 evaluates to -4 because subtraction is:

  10. W15-M10 تعليل

    A student writes expr right-recursively: parse a term; if the next token is + or -, return BinOp(op, term, self.expr()). What does it give for 8 - 4 - 2?

  11. W15-M11 تعليل

    The rule expr := expr '+' term | term is turned directly into a method whose first line is left = self.expr(). On the input 3 it:

  12. W15-M12 تذكّر

    In recursive descent, the EBNF repetition ( … )* becomes:

  13. W15-M13 تطبيق

    Parsing 1 + 2 * 3, how many times is factor called?

  14. W15-M14 تطبيق

    The tree our parser builds for -5 + 2 is:

  15. W15-M15 تذكّر

    evaluate visits the nodes of the tree in:

  16. W15-M16 تطبيق

    The post-order sequence of the AST of (3 + 4) * 2 is:

  17. W15-M17 تعليل

    parse raises ValueError if tokens are left over after expr returns. Without that check:

  18. W15-M18 تطبيق

    Each pair of parentheses costs the parser about three Python frames. With Python's default limit of 1,000 frames, roughly how deeply can calculate nest parentheses?

  19. W15-M19 تطبيق

    The time of calculate on an expression of n tokens is:

  20. W15-M20 تعليل

    calculate("1 + 1 + … + 1") with n numbers: how deep does the recursion of evaluate go?

  21. W15-M21 تذكّر

    When you run a .py file, CPython:

  22. W15-M22 تعليل

    Compared with the Week 6 route (shunting-yard, then evaluate_postfix), the main advantage of building a tree is that:

18 درجات

أسئلة المقال

5 أسئلة مقالية (18 درجة). اكتب إجابتك أولًا، ثم اعرض الإجابة النموذجية ونقاط التصحيح، وقدّر درجتك بأمانة: كل نقطة تساوي درجة تقريبًا.

مجموع درجات المقال: 0 / 18

  1. W15-E1 تذكّر 4 درجات

    Name the three stages of a translator, with the input and output of each. For each, give an input that it — and only it — rejects, and the exception our calculator raises. How does a compiler differ from an interpreter?

  2. W15-E2 تعليل 4 درجات

    "Precedence is the shape of the grammar." Explain this sentence using the three rules of our grammar and the tree of 3 + 4 * 2. How do parentheses override precedence? Where would you add a rule for a tighter operator such as ^?

  3. W15-E3 تعليل 4 درجات

    What is associativity? Explain why expr must use a loop that makes the tree so far the left child. Describe what goes wrong with a right-recursive expr and with a left-recursive one, with an input for each.

  4. W15-E4 تعليل 3 درجات

    Compare the two routes from infix tokens to a value: shunting-yard plus evaluate_postfix, and Parser plus evaluate. Give their costs, one advantage of each, and the connection between the postfix list and the tree.

  5. W15-E5 تعليل 3 درجات

    "In a recursive-descent parser, the call stack is the parser's stack." Explain. What decides how deep it grows, and what happens when it grows too deep?