Skip to main content
Version: 3.6

BinaryExpression 二元表达式

1. 结构声明

class BinaryExpression extends LogicItem {
left: LogicItem;
right: LogicItem;
operator: '+' | '-' | '*' | '/' | '%' | '==' | '!=' | '>' | '<' | '>=' | '<=' | '&&' | '||' | 'startwith' | 'endwith' | 'like' | 'in';
}

2. 节点示例

(1) 示例

AST 如下:

{
"concept": "BinaryExpression",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "ratio"
},
"operator": "*",
"right": {
"concept": "NumericLiteral",
"value": "100",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
}
}

对应的代码如下:

ratio * 100

(2) 示例

AST 如下:

{
"concept": "BinaryExpression",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "ratio"
},
"operator": "==",
"right": {
"concept": "NumericLiteral",
"value": "1",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
}
}

对应的代码如下:

ratio == 1

(3) 示例

AST 如下:

{
"concept": "BinaryExpression",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "condition1"
},
"operator": "||",
"right": {
"concept": "BinaryExpression",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "ratio"
},
"operator": ">",
"right": {
"concept": "NumericLiteral",
"value": "1",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
}
}
}

对应的代码如下:

condition1 || ratio > 1

(4) 数据查询中的二元表达式

AST 如下:

{
"concept": "BinaryExpression",
"left": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "Student",
"propertyName": "fullName",
"asName": ""
},
"right": {
"concept": "Identifier",
"namespace": "",
"name": "name"
},
"operator": "like"
}

对应的代码如下:

LIKE(Student.fullName, name)