operator.cs
来自「编译原理语法分析和词法分析综合实验: 源程序、可执行程序、测试程序文件、程序运行」· CS 代码 · 共 107 行
CS
107 行
using System;
using System.Collections.Generic;
using System.Text;
namespace syn
{
public class Operator
{
public static readonly char LeftCurve = '(';
public static readonly char RightCurve = ')';
private char _operator;
public Operator(char op)
{
this._operator = op;
}
public char Value
{
get { return this._operator; }
}
public bool IsLeftCurve()
{
return IsLeftCurve(this._operator);
}
public bool IsRightCurve()
{
return IsRightCurve(this._operator);
}
public static bool IsLeftCurve(char ch)
{
if (ch == LeftCurve)
return true;
else
return false;
}
public static bool IsRightCurve(char ch)
{
if (ch == RightCurve)
return true;
else
return false;
}
//判断是否是操作fu
public static bool IsOperator(char ch)
{
char[] operators = { '+', '-', '*', '/', '(', ')' };
for (int i = 0; i < operators.Length; i++)
if (ch == operators[i])
return true;
return false;
}
public int Priority
{
get
{
return GetPriority(this.Value);
}
}
//返回运算符的优先级
public static int GetPriority(char ch)
{
int priority;
switch (ch)
{
case '+':
priority = 1;
break;
case '-':
priority = 1;
break;
case '*':
priority = 2;
break;
case '/':
priority = 2;
break;
default:
priority = 0;
break;
}
return priority;
}
public override string ToString()
{
return this._operator.ToString();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?