package cn.lgh.compiler;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
import cn.lgh.compiler.bussinessObject.CodeScanner;
import cn.lgh.compiler.bussinessObject.InstructionCreater;
import cn.lgh.compiler.bussinessObject.Logger;
import cn.lgh.compiler.bussinessObject.Parser;
import cn.lgh.compiler.persistObject.InstructionSet;
import cn.lgh.compiler.persistObject.SyntaxTree;
/**
* 编译器视图窗口
*
* @author 蓝冠恒
* @version 2010-12-10
*
*/
public class CompilerView {
private Text txtTargetArea;// 目标代码生产区
private Text txtEditingArea;// 源代码编辑区
private Text txtConsoleInfo;// 控制台信息输出区
private Text txtTargePath;// 目标文件路径
private Text txtSouecePath;// 源文件路径
protected Shell shell;// 视图窗口
/**
* Launch the application
*
* @param args
*/
public static void main(String[] args) {
try {
CompilerView window = new CompilerView();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 打开窗口
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
/**
* 创建窗口内容(组建)
*/
protected void createContents() {
shell = new Shell(SWT.MIN | SWT.CLOSE);
shell.setToolTipText("copyRight@广西大学计算机与电子信息学院计科071蓝冠恒");
shell.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
shell.setLayout(new FormLayout());
shell.setSize(1000, 700);
shell.setText("C语言子集编译器");
final Composite cmpsMain = new Composite(shell, SWT.NONE);
final FormData fd_cmpsMain = new FormData();
fd_cmpsMain.bottom = new FormAttachment(100,0);
fd_cmpsMain.top = new FormAttachment(0, 0);
fd_cmpsMain.right = new FormAttachment(100, 0);
fd_cmpsMain.left = new FormAttachment(0, 0);
cmpsMain.setLayoutData(fd_cmpsMain);
cmpsMain.setLayout(new FormLayout());
final Group groupMain = new Group(cmpsMain, SWT.NONE);
final FormData fd_groupMain = new FormData();
fd_groupMain.left = new FormAttachment(0, 0);
fd_groupMain.right = new FormAttachment(100, 0);
fd_groupMain.top = new FormAttachment(0, 0);
fd_groupMain.bottom = new FormAttachment(100, 0);
groupMain.setLayoutData(fd_groupMain);
groupMain.setLayout(new FormLayout());
final Group groupLeft = new Group(groupMain, SWT.NONE);
groupLeft.setLayout(new FormLayout());
final FormData fd_groupLeft = new FormData();
fd_groupLeft.bottom = new FormAttachment(100, -5);
fd_groupLeft.top = new FormAttachment(0, 0);
fd_groupLeft.left = new FormAttachment(0, 5);
fd_groupLeft.right = new FormAttachment(1, 3, -10);
groupLeft.setLayoutData(fd_groupLeft);
final Group groupFunction = new Group(groupLeft, SWT.NONE);
groupFunction.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
groupFunction.setLayout(new FormLayout());
final FormData fd_groupFunction = new FormData();
fd_groupFunction.bottom = new FormAttachment(1, 3, -5);
fd_groupFunction.top = new FormAttachment(0, -5);
fd_groupFunction.right = new FormAttachment(100, -5);
fd_groupFunction.left = new FormAttachment(0, 5);
groupFunction.setLayoutData(fd_groupFunction);
Button btnSource = new Button(groupFunction, SWT.NONE);
btnSource.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
btnSource.addMouseListener(new MouseAdapter() {
public void mouseDown(final MouseEvent e) {
FileDialog fileselect = new FileDialog(shell);
fileselect.setFilterNames(new String[] { "*.*" });
fileselect.setFilterExtensions(new String[] { "*.c" });
String url = "";
String codes = "";
String line=null;
BufferedReader in = null;
url = fileselect.open();
if(url==null){
return;
}
txtSouecePath.setText(url);
try {
in=new BufferedReader(new FileReader(url));
line=in.readLine();
while(line!=null){
codes+=line+"\n";
line=in.readLine();
}
if(!codes.equals("")){
txtEditingArea.setText(codes);
txtTargetArea.setText("");
txtConsoleInfo.setText("");
}
} catch (FileNotFoundException e1) {
setConsoleInfo("找不到文件:"+e1.getMessage());
e1.printStackTrace();
} catch (IOException e2) {
setConsoleInfo("找不到文件:"+e2.getMessage());
e2.printStackTrace();
}finally{
try {
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});
btnSource.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
final FormData fd_btnSource = new FormData();
fd_btnSource.top = new FormAttachment(0, 20);
fd_btnSource.left = new FormAttachment(0, 10);
fd_btnSource.right = new FormAttachment(2, 5, 0);
fd_btnSource.height = 32;
btnSource.setLayoutData(fd_btnSource);
btnSource.setText("源文件路径");
Button btnTarget = new Button(groupFunction, SWT.NONE);
btnTarget.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
btnTarget.addMouseListener(new MouseAdapter() {
public void mouseDown(final MouseEvent e) {
FileDialog fileselect = new FileDialog(shell, SWT.SINGLE);
fileselect.setFilterNames(new String[] { "*.*" });
String url = "";
url = fileselect.open();
if(url==null){
return;
}
txtTargePath.setText(url);
}
});
btnTarget.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
final FormData fd_btnTarget = new FormData();
fd_btnTarget.right = new FormAttachment(btnSource, 0, SWT.RIGHT);
fd_btnTarget.left = new FormAttachment(btnSource, 0, SWT.LEFT);
fd_btnTarget.height = 32;
fd_btnTarget.bottom = new FormAttachment(2, 3, -10);
btnTarget.setLayoutData(fd_btnTarget);
btnTarget.setText("目标文件路径");
txtSouecePath = new Text(groupFunction, SWT.BORDER);
txtSouecePath.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NONE));
txtSouecePath.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
final FormData fd_txtSouecePath = new FormData();
fd_txtSouecePath.top = new FormAttachment(btnSource, 0, SWT.TOP);
fd_txtSouecePath.bottom = new FormAttachment(btnSource, 0, SWT.BOTTOM);
fd_txtSouecePath.left = new FormAttachment(2, 5, 0);
fd_txtSouecePath.height = 32;
fd_txtSouecePath.right = new FormAttachment(100, -10);
txtSouecePath.setLayoutData(fd_txtSouecePath);
txtTargePath = new Text(groupFunction, SWT.BORDER);
txtTargePath.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NONE));
final FormData fd_txtTargePath = new FormData();
fd_txtTargePath.top = new FormAttachment(btnTarget, 0, SWT.TOP);
fd_txtTargePath.bottom = new FormAttachment(btnTarget, 0, SWT.BOTTOM);
fd_txtTargePath.left = new FormAttachment(txtSouecePath, 0, SWT.LEFT);
fd_txtTargePath.right = new FormAttachment(txtSouecePath, 0, SWT.RIGHT);
txtTargePath.setLayoutData(fd_txtTargePath);
final Button btnCompile = new Button(groupFunction, SWT.NONE);
btnCompile.setFont(SWTResourceManager.
没有合适的资源?快使用搜索试试~ 我知道了~
编译原理课程设计-C语言子集编译器(含报告和可运行源代码).rar
共151个文件
html:94个
class:37个
java:14个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 19 下载量 6 浏览量
2022-03-20
15:01:26
上传
评论 20
收藏 2.97MB RAR 举报
温馨提示
通过所设计的C语言子集编译器能够对用户所输入的C语言子集程序代码进行词法分析、语法分析和语义分析,能将源代码编译成汇编指令(伪指令)。在进行编译的过程中,能过滤去 “//”或“/* */”形式的文字注释,具备一定的代码错误处理能力,即在编译过程中发现语法或语义错误时,将输出错误信息(出错所在代码行号和错误类型提示信息),然后跳过错误语句继续向前翻译,直到将全部代码翻译完毕,而且能够在编译C语言子集语句——if(条件){}[else{}]、while(条件){}、for(i=1;i<=10;i=i+1){}的同时,也能够实现对它们相互嵌套使用的复杂句子进行编译。在完成上述功能的同时,设计友好的用户交互界面,使用户可在用户交互界面自由进行编码,并能对源代码进行及时编译和看到编译结果,能根据需要保存源代码和目标代码。
资源推荐
资源详情
资源评论
收起资源包目录
编译原理课程设计-C语言子集编译器(含报告和可运行源代码).rar (151个子文件)
CompilerView.class 13KB
SWTResourceManager.class 13KB
Parser.class 9KB
InstructionCreater.class 9KB
CodeScanner.class 6KB
Visitor.class 4KB
InstructionSet.class 3KB
CompilerView$1.class 3KB
CompilerView$5.class 2KB
CompilerView$3.class 2KB
SyntaxTree.class 2KB
CompilerView$6.class 2KB
CompilerView$2.class 1KB
Variable.class 1KB
SymbolTable.class 1KB
TokenUtil.class 1KB
SyntaxTree$ForStmt.class 1KB
Tokens.class 1KB
SyntaxTree$IfStmt.class 1008B
SyntaxTree$Operation.class 969B
SyntaxTree$Expr.class 951B
SyntaxTree$WhileStmt.class 929B
SyntaxTree$AssignStmt.class 926B
CompilerView$4.class 916B
SWTResourceManager$1.class 857B
Symbol.class 839B
SyntaxTree$WriteStmt.class 835B
SyntaxTree$ReadStmt.class 832B
SyntaxTree$ParExpr.class 827B
Logger.class 804B
SyntaxTree$StmtSeq.class 785B
SyntaxTree$Ident.class 771B
SyntaxTree$Literal.class 746B
SyntaxTree$ErrorTree.class 698B
CodeScanner$TokenType.class 576B
CodeScanner$KeyWord.class 570B
InstructionSet$InstructionPos.class 559B
.classpath 3KB
stylesheet.css 1KB
编译原理课程设计报告.doc 2.93MB
inherit.gif 57B
SyntaxTree.html 32KB
InstructionCreater.html 27KB
Tokens.html 26KB
index-18.html 22KB
Visitor.html 21KB
SyntaxTree.ForStmt.html 19KB
index-15.html 19KB
SyntaxTree.IfStmt.html 18KB
SyntaxTree.html 18KB
SyntaxTree.Operation.html 18KB
CodeScanner.html 18KB
SyntaxTree.Expr.html 18KB
SyntaxTree.WhileStmt.html 17KB
SyntaxTree.AssignStmt.html 17KB
constant-values.html 17KB
Visitor.html 16KB
InstructionSet.html 16KB
SyntaxTree.ReadStmt.html 16KB
SyntaxTree.WriteStmt.html 16KB
SyntaxTree.ParExpr.html 16KB
SyntaxTree.StmtSeq.html 16KB
SyntaxTree.Ident.html 15KB
SyntaxTree.Literal.html 15KB
SyntaxTree.ErrorTree.html 14KB
Parser.html 14KB
Variable.html 14KB
TokenUtil.html 14KB
package-use.html 13KB
SymbolTable.html 12KB
Symbol.html 12KB
Logger.html 12KB
package-summary.html 11KB
index-3.html 11KB
overview-tree.html 11KB
index-8.html 10KB
package-tree.html 10KB
CompilerView.html 10KB
Tokens.html 10KB
InstructionSet.InstructionPos.html 9KB
index-5.html 9KB
SyntaxTree.AssignStmt.html 9KB
SyntaxTree.Operation.html 9KB
SyntaxTree.WhileStmt.html 9KB
SyntaxTree.WriteStmt.html 9KB
SyntaxTree.IfStmt.html 9KB
SyntaxTree.ReadStmt.html 9KB
SyntaxTree.Literal.html 9KB
SyntaxTree.ForStmt.html 9KB
SyntaxTree.StmtSeq.html 9KB
SyntaxTree.ParExpr.html 9KB
SyntaxTree.Ident.html 9KB
SyntaxTree.Expr.html 8KB
index-9.html 8KB
Symbol.html 8KB
index-16.html 8KB
InstructionSet.InstructionPos.html 8KB
help-doc.html 8KB
package-use.html 8KB
SyntaxTree.ErrorTree.html 8KB
共 151 条
- 1
- 2
等天晴i
- 粉丝: 3509
- 资源: 10万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页