In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "what is the motivation of the web interpreter pattern". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what is the motivation of the web interpreter pattern.
Intention
Implement an interpreter according to the syntax definition of the language, which is used to interpret the statements that execute the language.
motivation
Generally speaking, software to solve problems is achieved by programmers. For example, calculation, communication and so on. This approach is effective in most cases, but it is inflexible when the requirements are changeable. There are many ways to solve this problem, such as adding parameters to the process, or forming a new process through a combination of processes, and so on. In some cases, if you can generalize the problem into some simple statements, you can build an interpreter to interpret and execute.
This is the case with mathematical calculations, such as the following expression:
100.0 * sin (29 + (23 * 6)) + sqrt (cos (34 * 5))
For different expressions, the number of input data and the composition of levels will be different. The relatively realistic solution is to define a rule and then implement an interpreter according to that rule and use the interpreter to interpret and execute the user's input. For the example of a compound expression, execution is the result of the calculation. First, let's define the rules of the expression:
[1] Expr::= AdditiveExpr
The meaning of [: =] is [defined as]. Therefore, the expression [1] can be understood as the expression Expr is defined as the addition expression AdditiveExpr.
[2] AdditiveExpr::=MultiplicativeExpr (("+" | "-") MultiplicativeExpr) *
[|] means [or], and [*] means [0 to any number]. So the meaning of the formula [2] is that the addition expression AdditiveExpr is defined as a multiplication expression MultiplicativeExpr followed by 0 to any number of multiplication expressions preceded by a plus or minus sign. To put it another way, there are several multiplicative expressions connected by positive or negative signs.
[3] MultiplicativeExpr::= UnaryExpr (("*" | "/" | "%") UnaryExpr) *
The meaning of formula [3] is that the multiplication expression MultiplicativeExpr is defined as several meta-expressions UnaryExpr connected by multiplication sign or division sign or remainder symbol.
[4] UnaryExpr::= ("-" | "+")? PrimaryExpr
[? ] means "yes or no". The meaning of formula [4] is that the meta-expression Unary is defined as the basic expression PrimaryExpr with or without a sign.
[5] PrimaryExpr::= NumericLiteral | ParenthesizedExpr | FunctionCall
The meaning of formula [5] is that the basic expression PrimaryExpr can be a numeric literal value NumerLiteral, a parenthesized expression ParemthesizedExpr, or a function call.
[6] NumericLiteral::=IntegerLiteral | DecimalLiteral
Numeric literals are defined as integer literals IntergerLiteral or decimal literals DecimalLiteral.
[7] ParenthesizedExpr::= "(" Expr ")"
An expression with parentheses is defined as an expression surrounded by parentheses. The expression can be further decomposed into addition expression, multiplication expression and so on.
[8] FunctionCall::=FunctionName "(" (Expr ("," Expr) *)? "
The function call expression FunctionCall consists of the function name FunctionName and a list of arguments enclosed in parentheses. The parameter list consists of multiple expressions concatenated with commas.
[9] IntegerLiteral:: = Digits
The integer literal IntegerLiteral is defined as the numeric Digits.
[10] DecimalLiteral: = ("." Digits) | (Digits "." Digits))
There are two forms of decimal literal DecimalLiteral. One is the decimal point plus the number, the other is the number plus the decimal point plus the number.
[11] Digits:: = [0-9] +
[+] means [1 to more], and [[0-9]] represents one of the numbers between 0 and 9. Therefore, the meaning of formula [11] is that a number is defined as one or more characters between 0 and 9.
[12] FunctionName=sin | cos | tan | asin | acos | atan | power | sqrt
Formula [12] defines possible function names.
At this point, I believe that you have a deeper understanding of "what is the motivation of the web interpreter pattern?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.