日期:2014-05-17  浏览次数:20819 次

c# 窗口simple词法分析器
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;


namespace 词法分析器
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
            
        }
        public static int k = 0;
        public static char ch = ' ';//存放最新读进的字符
        public static int i = 1;//当前读到的字符位置
        public char []  strToken ;//存放单词符号的字符数组
        public ArrayList b1 = new ArrayList();
        public ArrayList a1 = new ArrayList();
        public static string[] 保留字 ={"and","array","begin","bool","call","case","char","constant","dim","do"
        ,"else","end","false","for","if","input","integer","not","of","or",
        "output","procedure","program","read","real","repeat","set","stop","then",
        "to","true","until","var","while","write"
        };
        public static string[] 界符 ={"(",")","*","*/","+",",","-",".","..","/","/*",
        ":",":=",";","<","<=","<>","=",">",">=","[","]"};
        public static string[] 标识符;
        public static string[] 整数;
        public static string[] 字符常数;
        public string change(char[] a)
        {
            string sstring = null;
            for (int s = 0; s < a.Length; s++)
            {
                sstring += a[s];
            }
            return sstring;
        }
        public  void Getchar(string str)
        {
            ch = str[i-1];
            i++;
   &n