词法分析器设计实验报告

2026/4/24 22:32:40

六、实验代码(C#)

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms;

namespace LL_1_分析法 {

public partial class Form1 : Form {

public Production []production; public char[] terminator;//终结符 public char[] nonterminal;//非终结符 public int flag = 0;

public String Terminator = \ String STACK = \符号栈 String stack = \输入串 public struct Production { public Char noter;

public String production; }//产生式结构体 public struct FIRST { public Char noter; public String first; }//FIRST集结构体

public struct FOLLOW { public Char noter; public String follow; }//FOLLOW集结构体 public struct PLACE{ public bool flag; public int x; public int y; }

public Form1() {

InitializeComponent(); }

private Char[] getNonterminal(Char[] s) {

String nonterminal = \

for (int i = 0; i < s.Length; i++) {

if (s[i] >= 'A' && s[i] <= 'Z') {

if (!nonterminal.Contains(s[i]))

nonterminal = nonterminal + s[i]; } }

return nonterminal.ToCharArray(); }

private Char[] getTerminator(Char[] s) {

String terminator = \

for (int i = 0; i < s.Length; i++) {

if ((s[i] >= 'a' && s[i] <= 'z') || s[i] == '(' || s[i] == ')' || s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/'||s[i]=='@') {

if (!terminator.Contains(s[i]))

terminator = terminator + s[i]; } }

Terminator = terminator.Replace(\ return terminator.ToCharArray(); }

private Production[] getProductions(Char[] s) {

int index = 0;

Production[] productions=new Production[20]; for (int i = 0; i < s.Length - 1; i++) {

int flag = 0;

if (nonterminal.Contains(s[i]) && s[i + 1] == '$')//- {

productions[index].noter = s[i]; i = i + 3;

while (s[i] != ' '&&s[i]!='\\n') {

if (flag == 0) {

productions[index].production =productions[index].production +s[i];

i++; } else {

productions[index].noter = productions[index - 1].noter;

productions[index].production = productions[index].production + s[i];

i++; }

if (s[i] == '|') {

flag = 1; index++; i++; }


词法分析器设计实验报告.doc 将本文的Word文档下载到电脑
搜索更多关于: 词法分析器设计实验报告 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219