keywordclass.cs
来自「C#更新版的C语言的词法分析器」· CS 代码 · 共 59 行
CS
59 行
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LAB1
{
class keyWordClass
{
private List<CoupleClass> keywordList;
public List<CoupleClass> KeywordList
{
get { return keywordList; }
set { keywordList = value; }
}
public keyWordClass()
{
keywordList = new List<CoupleClass>();
this.keywordList.Add(new CoupleClass("int", "INT"));
this.keywordList.Add(new CoupleClass("double", "DBL"));
this.keywordList.Add(new CoupleClass("for", "FOR"));
this.keywordList.Add(new CoupleClass("while","WHILE"));
this.keywordList.Add(new CoupleClass("if","IF"));
this.keywordList.Add(new CoupleClass("else", "ELSE"));
this.keywordList.Add(new CoupleClass("printf", "PNT"));
this.keywordList.Add(new CoupleClass("switch","SWITCH"));
this.keywordList.Add(new CoupleClass("case","CASE"));
this.keywordList.Add(new CoupleClass("+","ADD"));
this.keywordList.Add(new CoupleClass("-","MIN"));
this.keywordList.Add(new CoupleClass("%","MOD"));
this.keywordList.Add(new CoupleClass("++", "INC"));
this.keywordList.Add(new CoupleClass("--", "DEC"));
this.keywordList.Add(new CoupleClass(":=", "ASS"));
this.keywordList.Add(new CoupleClass("==", "EQU"));
this.keywordList.Add(new CoupleClass("/*", "CBN"));
this.keywordList.Add(new CoupleClass("*/", "CEN"));
this.keywordList.Add(new CoupleClass("{", "BEGIN"));
this.keywordList.Add(new CoupleClass("}", "END"));
this.keywordList.Add(new CoupleClass(",", "dot"));
this.keywordList.Add(new CoupleClass("(", "SLP"));
this.keywordList.Add(new CoupleClass(")", "SRP"));
this.keywordList.Add(new CoupleClass("\"", "CONST"));
this.keywordList.Add(new CoupleClass("#include", "LIB"));
}
public CoupleClass contains(string tokenIn)
{
foreach (CoupleClass item in this.keywordList)
{
if (item.KeyWord == tokenIn)
{
return item;
}
}
return null;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?