用递归下降分析法编写一个用于判断数学表达式是否正确的语法分析(国外英文资料).docVIP

  • 9
  • 0
  • 约1.49万字
  • 约 20页
  • 2017-06-08 发布于河南
  • 举报

用递归下降分析法编写一个用于判断数学表达式是否正确的语法分析(国外英文资料).doc

用递归下降分析法编写一个用于判断数学表达式是否正确的语法分析(国外英文资料)

用递归下降分析法编写一个用于判断数学表达式是否正确的语法分析(国外英文资料) The algorithm is used to analyze mathematical expressions Security programming 2011-01-07 23:43:50 reading 27 comments: large and small subscriptions Many teaching materials in China are too concerned with theoretical learning and lack of practical guidance. This paper introduces a classical algorithm problem, mathematical expression problem, to illustrate the practice of a grammar analysis algorithm in compiling principle. There is a topic in the compilation principle that we learn that is called grammar analysis (grammar analysis). Grammar analysis is to parse formal language in a fixed grammar format. There must be two algorithms for grammar analysis, one is the LL algorithm, and the other is the LR algorithm. LL, also called top-down analysis algorithm is relatively simple, suitable for manual coding, and LR algorithm is bottom-up analysis algorithm, is complex, generally we all through the use of the tool yacc to generate the relevant code. In this paper, the problem of mathematical expression in the problem of conventional algorithm is analyzed in the simplest form of the algorithm of LL (1). At the same time, this article also introduces the general method of the profiler code that manually constructs EBNF grammars. Hopefully, the practice of this article will help you implement your own parser. Mathematical expression problem In the case of learning algorithms, the expression processing of four mixed operations is a classic algorithm problem. For example, here is a mathematical expression 122 + 2 * (11-1)/(3 - (2-0)). We need to compute the results based on the description of the string. Input: 122 plus 2 times 11 minus 1 over 3 minus 2 minus 0. The Output: 142 In the four hybrid operations, you also need to take into account the precedence of parentheses, multiplication, and plus or minus, and the usual solution is to use the stack. The conventional algorithms and LL algorithms are similar in different ways. Introducti

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档