BinaryExpression 二元表达式
1. 结构声明
- TS Declaration
- JSON Schema
class BinaryExpression extends LogicItem {
left: LogicItem;
right: LogicItem;
operator: '+' | '-' | '*' | '/' | '%' | '==' | '!=' | '>' | '<' | '>=' | '<=' | '&&' | '||' | 'startwith' | 'endwith' | 'like' | 'in' | 'contains';
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"changedTime": {
"$ref": "#/definitions/long"
},
"label": {
"type": "string"
},
"description": {
"type": "string"
},
"folded": {
"type": "boolean"
},
"offsetX": {
"type": "number"
},
"offsetY": {
"type": "number"
},
"typeAnnotation": {
"$ref": "#/definitions/TypeAnnotation"
},
"breakpoint": {
"type": "string",
"enum": [
"ENABLED",
"DISABLED"
]
},
"left": {
"$ref": "#/definitions/LogicItem"
},
"right": {
"$ref": "#/definitions/LogicItem"
},
"operator": {
"type": "string",
"enum": [
"+",
"-",
"*",
"/",
"%",
"==",
"!=",
">",
"<",
">=",
"<=",
"&&",
"||",
"startwith",
"endwith",
"like",
"in",
"contains"
]
}
},
"required": [
"left",
"right",
"operator"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"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": {}
}
}
}
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: {}
对应的代码如下:
- 文本化 NASL
- Natural TS
ratio * 100
ratio * 100
(2) 示例
AST 如下:
- JSON
- YAML
{
"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": {}
}
}
}
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: {}
对应的代码如下:
- 文本化 NASL
- Natural TS
ratio == 1
ratio == 1
(3) 示例
AST 如下:
- JSON
- YAML
{
"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": {}
}
}
}
}
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: {}
对应的代码如下:
- 文本化 NASL
- Natural TS
condition1 || ratio > 1
condition1 || ratio > 1
(4) 数据查询中的二元表达式
AST 如下:
- JSON
- YAML
{
"concept": "BinaryExpression",
"left": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "Student",
"propertyName": "fullName",
"asName": ""
},
"right": {
"concept": "Identifier",
"namespace": "",
"name": "name"
},
"operator": "like"
}
concept: BinaryExpression
left:
concept: QueryFieldExpression
isDotStar: false
entityAsName: Student
propertyName: fullName
asName: ""
right:
concept: Identifier
namespace: ""
name: name
operator: like
对应的代码如下:
- 文本化 NASL
- Natural TS
LIKE(Student.fullName, name)
LIKE(Student.fullName, name)