Principle and Implementation interpreter mode of Atitit. linq java, atitit. linq Interpreter
Principles and implementation interpreter mode of Atitit. linq java
1. Implementation of Linq from where 1
2. Where expr Implementation 1
3. A variation of Attilax 2
4. interpreter mode structure 2
5. Code3
5.1. EqExpression3
5.2. LikeExpression4
5.3. AndExpression4
5.4. AExpression5
6. Refer to 5
1. Implementation of Linq from where
Map row = from (ColumnsDefs). where (eq ("COLUMN_NAME", keydomain.exe (). get (0 );
2. Implementation of Where expr
There are about 15 expr... Link (size comparison), logic expr... In like and so on ..
Author: nickname: old wow's paw (full name: Attilax Akbar Al Rapanui Attila Akba Arla Panui) Name: AI long, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://www.cnblogs.com/attilax/
3. Attilax changes
The concept of Terminator is not used... two data types... express type, common data ..
If it is an express type, it can be computed ..
Note: checkSuitOk shoshould use interpreter
4. interpreter mode structure
· Abstract Interpreter: declares an abstract interface (or abstract class) that must be implemented by all specific expressions. An interface is mainly an interpret () method, which is called an interpreted operation. The specific interpretation task is completed by its implementation classes. The specific interpreter is completed by the TerminalExpression and NonterminalExpression, respectively.
· Terminator expression: implements the interpretation operation associated with the elements in the grammar. Generally, there is only one Terminator expression in the interpreter mode, but there are multiple instances corresponding to different Terminators. Half of the Terminator is the unit of operation in the grammar. For example, there is a simple formula R = R1 + R2 in which R1 and R2 are the Terminator, the interpreter for parsing R1 and R2 is the terminator expression.
· Non-terminator expression: each rule in the grammar corresponds to a non-terminator expression. Non-terminator expressions are generally operators or other keywords in the grammar, for example, in the formula R = R1 + R2, + is a non-Terminator, And the parser + is a non-terminator expression. Non-terminator expressions increase based on the complexity of the logic. In principle, each grammar rule corresponds to a non-terminator expression.
There are only two types of elements: operational elements and operator numbers. operational elements refer to a, B, c, and other symbols. objects that require a specific value assignment are also called terminologies. Why are they called terminologies? In addition to assigning values, these elements do not need to be processed. All calculation elements correspond to a specific business parameter. This is the smallest unit logic in the syntax and cannot be split; the operator number is the addition and subtraction symbol. We need to write an algorithm for processing. Each operator number must correspond to the processing unit. Otherwise, the formula cannot run. The operator number is also called a non-Terminator.
You can first draw a simple class diagram, as shown in 27-1.
5. Code5.1. EqExpression
Package com. attilax. linq;
Import java. util. Map;
Public class EqExpression extends AExpression {
Public EqExpression (String leftCol, Object ritVal ){
This. left = leftCol;
This. rit = ritVal;
}
Public boolean interpreter (Map row ){
// LikeExpression le = (LikeExpression) whereExpressAst;
If (row. get (this. left. toString (). toString (). equals (this. rit. toString ()))
Return true;
Else
Return false;
}
5.2. LikeExpression
Package com. attilax. linq;
Import java. util. Map;
Public class LikeExpression extends AExpression {
Public LikeExpression (String col, String val ){
This. left = col;
This. rit = val;
}
Public boolean checkSuitOk (Map row ){
// LikeExpression le = (LikeExpression) whereExpressAst;
If (row. get (this. left. toString (). toString (). contains (this. rit. toString ()))
Return true;
Else
Return false;
}
}
5.3. AndExpression
Package com. attilax. linq;
Import java. util. Map;
Public class AndExpression extends AExpression {
Public AndExpression (AExpression whereExpressAst, AExpression eq ){
This. left = whereExpressAst;
This. rit = eq;
}
Public boolean checkSuitOk (Map row ){
// LikeExpression le = (LikeExpression) whereExpressAst;
AExpression lft_exp = (AExpression) this. left;
AExpression rit_exp = (AExpression) this. rit;
Return lft_exp.checkSuitOk (row) & rit_exp.checkSuitOk (row );
}
}
5.4. AExpression
Package com. attilax. linq;
Import java. util. Map;
Public class AExpression {
Public Object left;
Public Object rit;
Public boolean checkSuitOk (Map row ){
Throw new RuntimeException ("no imp in base aexp class ");
}
}
6. Reference
Atitit. linq api compatibility draft v2.docx
23 design modes (14): Interpreter mode-kundamo's column-blog channel-CSDN.NET.htm
Interpreter mode-crazy programmer-blog channel-CSDN.NET.htm