有人可以引导我解决这个问题要问我的吗? [英] Can somebody walk me through what this question is trying to ask of me?

查看:91
本文介绍了有人可以引导我解决这个问题要问我的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下编程语言问题似乎真的很不清楚,它对我的​​要求并不明显,有人可以帮助我理解它吗?

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?

问题:

递归下降解析器的一部分,用于一组简单的语言规则.使用任何编程语言进行实施;如果不是通用语言,请在注释中记下该语言.您应该为每个非终结符实现函数,并使用以下描述部分类C语言的规则.

Implement part of a recursive descent parser for a simple set of language rules. Use any programming language for the implementation; if it isn’t a common language, please make a note of which language it is in a comment. You should implement functions for each of the nonterminal symbols and, using the following rules that describe part of a C-like language.

<ifblock> --> if(<logic_expr>){<stmts>} [else {<stmts>}]

<logic_expr> --> <value> == <value> | <value> != <value>

您可以承担以下功能:

  • lex(),一个词法分析器,它将下一个标记的代码放置在全局变量下一个标记中

  • lex(), a lexical analyser which places a code for the next token in the global variable next token

stmts()

value()

终端符号应使用以下定义的常数进行编码:

Terminal symbols should be encoded with the following defined constants:

  • (''

  • CODE LP for ‘(’

)的CODE RP"

CODE RP for ‘)’

"{"

"{"

"=="

!="

"if"的代码IF

"else"的其他代码

CODE ELSE for ‘else’

推荐答案

据我所知:您被要求编写两个函数

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

  • ifblock
  • logic_expr
  • ifblock
  • logic_expr

作为递归下降解析器的一部分.

as part of a recursive descent parser.

对于其他非终端符号stmtsvalue,您可以假定存在相同名称的预写功能.

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.

要从输入流中获取下一个令牌,可以调用lex(),它返回一个代码,如终端符号的代码中所列.您需要做的是通过调用lex()来请求令牌代码来实现ifblock,并根据语言语法评估和匹配具有所需令牌的令牌.请注意,根据语法,ifblock中的else部分是可选的.

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.

要评估if的逻辑表达式,您需要进入函数logic_expr,该函数也会被要求编写,该函数将评估语法中定义的逻辑表达式.同样,您可以假定非终端value的功能已经存在.

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.

这篇关于有人可以引导我解决这个问题要问我的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆