- 9
- 0
- 约1.49万字
- 约 20页
- 2017-06-08 发布于河南
- 举报
用递归下降分析法编写一个用于判断数学表达式是否正确的语法分析(国外英文资料)
用递归下降分析法编写一个用于判断数学表达式是否正确的语法分析(国外英文资料)
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
您可能关注的文档
- 最新通用少儿英语一星口语模拟测试(国外英文资料).doc
- 杨丹卒业论文outline(国外英文资料).doc
- 校刊稿1(国外英文资料).doc
- 杨致远简介(国外英文资料).doc
- 有效备课上课听课评课(国外英文资料).doc
- 校友会小品台词(国外英文资料).doc
- 校园展销会办展背景介绍 完整版(国外英文资料).doc
- 校园次序与课外运动治理规定(国外英文资料).doc
- 校订标准(国外英文资料).doc
- 桃花源记温习课教案(国外英文资料).doc
- 广东省广州省实验中学教育集团2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州大学附属中学2025-2026学年八年级上学期奥班期中物理试题(解析版).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(含答案).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第八十六中学2025-2026学年八年级上学期期中物理试题(解析版).docx
- 广东省广州市第八十九中学2025-2026学年八年级上学期期中考试物理试题(含答案).docx
- 广东省广州市第二中学2025-2026学年八年级上学期期中考试物理试题(解析版).docx
- 2026《中国人寿上海分公司营销员培训体系优化研究》18000字.docx
- 《生物探究性实验教学》中小学教师资格模拟试题.docx
原创力文档

文档评论(0)