第一范文网 - 专业文章范例文档资料分享平台

词法分析器设计实验报告

来源:用户分享 时间:2025/5/28 23:35:01 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

ch = text_is[p++]; }

type_code = -1; } else {

number = 0;

while ((ch >= '0' && ch <= '9')) {

number = number * 10 + ch - '0'; ch = text_is[p++]; } p--;

type_code = 41; if (number > 32767) number = -1; } }

else switch (ch) //其他字符 {

case '<':text=text+ch; ch = text_is[p++]; if (ch == '>') {

type_code = 48; text = text + ch; }

else if (ch == '=') {

type_code = 49; text = text + ch; } else {

type_code = 47; p--; } break;

case '>': text = text + ch; ch = text_is[p++]; if (ch == '=')

{

type_code = 50; text = text + ch; } else {

type_code= 46; p--; } break;

case '+': text = text + ch; ch = text_is[p++]; if (ch == '+') {

text = text + ch; ch = text_is[p++]; if(ch=='+'||ch=='-'){ text = text + ch; type_code = -1; } else

type_code = 57; p--; } else {

type_code = 44; p--; } break;

case '-': text = text + ch; ch = text_is[p++]; if (ch == '-') {

text = text + ch; ch = text_is[p++]; if (ch == '+' || ch == '-') {

text = text + ch; type_code = -1; } else

type_code = 58;

p--; } else {

type_code = 45; p--; } break;

case '*': type_code = 42; text = \ case '/': type_code = 43; text = \ case '=': type_code = 51; text = \ case ';': type_code = 52; text = \ case '(': type_code = 53; text = \ case ')': type_code = 54; text = \ case '{': type_code = 55; text = \ case '}': type_code = 56; text = \ case '#': type_code = 0; text = \ case '\\n': type_code = -2; break; case '\\r': type_code = -3; break; default: type_code = -1; break; } }

private void button1_Click(object sender, EventArgs e) {

String path = \

OpenFileDialog op = new OpenFileDialog(); if (op.ShowDialog() == DialogResult.OK) {

path = op.FileName;

richTextBox1.Text = System.IO.File.ReadAllText(path, Encoding.Default); } }

private String getTextIo(){

return richTextBox1.Text+'#'; }

private void addData(String data1,String data2,String data3,String data4){ try {

DataGridViewRow dgr = new DataGridViewRow();

DataGridViewTextBoxCell dt1 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dt2 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dt3 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dt4 = new DataGridViewTextBoxCell(); dt1.Value = data1;

dt2.Value = data2; dt3.Value = data3; dt4.Value = data4; dgr.Cells.Add(dt1); dgr.Cells.Add(dt2); dgr.Cells.Add(dt3); dgr.Cells.Add(dt4);

dataGridView1.Rows.Add(dgr); }

catch (Exception) {

; } }

private void button2_Click(object sender, EventArgs e) {

type_code = 10; p = 0; line = 1; column = 1; try {

dataGridView1.Rows.Clear(); }

catch (Exception) { ; }

text_is = getTextIo().ToCharArray(); do {

readIo();

switch (type_code) {

case 41:

addData(number+\\type_code+ \+ number + \常量\

column++; break; case -1:

addData(text + \有错误\+ line + \

搜索更多关于: 词法分析器设计实验报告 的文档
词法分析器设计实验报告.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1dolg1f4jy072ie1ycam_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top