123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /**
- *
- * @author seagle
- * @date 2024-7-10
- * @Description 表达式结点
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MECF.Framework.UI.Core.DxfScript
- {
- public delegate void UserFunction(ExpressNode curr, bool OnlyCheckDataType = false);
- public class ExpressNode
- {
-
- public KeywordType NodeType { get; set;}
- public Variable Var { get; set; }
-
- public UserFunction UserFunc;
- public bool Closed { get; set; }
- public ExpressNode FirstChild, LastChild, NextBrother, PrevBrother, Father;
- public ExpressNode(Variable var,UserFunction userFunc,KeywordType nodeType )
- {
- Var = var;
- UserFunc = userFunc;
- NodeType = nodeType;
- FirstChild = LastChild = NextBrother = PrevBrother = Father = null;
- Closed = false;
- }
- public int ComparePrior(KeywordType kw)
- {
- int prior1 = getOperatorPrior(NodeType);
- int prior2 = getOperatorPrior(kw);
- if (prior1 < 0 || prior2 < 0)
- {
- throw new Exception("Can not compare prior [" + NodeType + "] and [" + kw + "]");
-
- }
- if (prior1 < prior2)
- {
- return -1;
- }
- else if (prior1 > prior2)
- {
- return 1;
- }
- else
- {
- if ((NodeType == KeywordType.KW_OPERATOR_PLUS && kw == KeywordType.KW_OPERATOR_PLUS) ||
- (NodeType == KeywordType.KW_OPERATOR_MULTIPLE && kw == KeywordType.KW_OPERATOR_MULTIPLE) ||
- (NodeType == KeywordType.KW_OPERATOR_AND && kw == KeywordType.KW_OPERATOR_AND) ||
- (NodeType == KeywordType.KW_OPERATOR_OR && kw == KeywordType.KW_OPERATOR_OR) ||
- (NodeType == KeywordType.KW_OPERATOR_BIT_AND && kw == KeywordType.KW_OPERATOR_BIT_AND) ||
- (NodeType == KeywordType.KW_OPERATOR_BIT_OR && kw == KeywordType.KW_OPERATOR_BIT_OR) ||
- (NodeType == KeywordType.KW_OPERATOR_COMMA && kw == KeywordType.KW_OPERATOR_COMMA))
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
-
- }
- //运算符优先级
- private static int getOperatorPrior(KeywordType Operator)
- {
- switch (Operator)
- {
- case KeywordType.KW_FUNCTION:
- case KeywordType.KW_ROUND_LEFT:
- return 0;
- case KeywordType.KW_OPERATOR_COMMA:
- return 1;
- case KeywordType.KW_OPERATOR_OR:
- return 2;
- case KeywordType.KW_OPERATOR_AND:
- return 3;
- case KeywordType.KW_OPERATOR_NOT:
- return 4;
- case KeywordType.KW_OPERATOR_GT:
- case KeywordType.KW_OPERATOR_GE:
- case KeywordType.KW_OPERATOR_LT:
- case KeywordType.KW_OPERATOR_LE:
- case KeywordType.KW_OPERATOR_EQUAL:
- case KeywordType.KW_OPERATOR_NOT_EQUAL:
- return 5;
- case KeywordType.KW_OPERATOR_PLUS:
- case KeywordType.KW_OPERATOR_MINUS:
- return 6;
- case KeywordType.KW_OPERATOR_MULTIPLE:
- case KeywordType.KW_OPERATOR_DEVIDE:
- return 7;
- case KeywordType.KW_OPERATOR_NEGATIVE:
- return 8;
- case KeywordType.KW_OPERATOR_BIT_OR:
- return 9;
- case KeywordType.KW_OPERATOR_BIT_AND:
- return 10;
- case KeywordType.KW_OPERATOR_BIT_NOT:
- return 11;
- case KeywordType.KW_OPERATOR_MOVE_LEFT:
- case KeywordType.KW_OPERATOR_MOVE_RIGHT:
- return 12;
- default:
- return -1;
- }
- }
- }
- }
|