云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 词法分析器设计实验报告

词法分析器设计实验报告

  • 62 次阅读
  • 3 次下载
  • 2025/5/2 12:12:23

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 + \

搜索更多关于: 词法分析器设计实验报告 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

ch = text_is[p++]; } type_code = -1; } else { number = 0; while ((ch >= '0' && ch <= '9')) { number = number * 10 + ch - '0';

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com