Can somebody walk me through what this question is trying to ask of me?

前端 未结 1 1749
挽巷
挽巷 2021-01-25 16:29

The following programming languages question seems really unclear and what it wants me to do is not obvious to me, could somebody help me to understand it?

The question:

相关标签:
1条回答
  • 2021-01-25 17:28

    From what I can see: You are asked to write two functions

    • ifblock
    • logic_expr

    as part of a recursive descent parser.

    For the other non-terminal symbols, stmts and value you are allowed to assume the existence of pre-written functions by the same names.

    How to write a recursive descent parser should have been discussed in the lectures and tutorials, so I assume you know how that works.

    To get the next token from the input stream you can call lex() which returns a code, as listed in the codes for the terminal symbols. What you need to do is to implement the ifblock by requesting token codes by calling lex() and to evaluate and match those with the required tokens according to the language grammar. Note that the else part in the ifblock is optional according to the grammar.

    To evaluate the logical expression of the if you need to step into a function logic_expr, which you are asked to write as well, which evaluates a logical expression as defined in the grammar. Again, you may assume that the function for the non-terminal value does already exist.

    0 讨论(0)
提交回复
热议问题