资源简介
用java写的LALR编译器,实现语法分析

代码片段和文件信息
/**
* @(#)LALR.java
*
*
* @author Huachunya
* @version 1.00 2009/6/15
*/
import java.io.*;
import java.lang.*;
import java.util.*;
public class LALR {
private Map mapt=new HashMap();//终结符
private Map mapn=new HashMap(); //非终结符
private char map[]=new char[9]; //非终结符
private String pro[]=new String[20];
private int len=0; //产生式的个数
private int cntn=0; //非终结符个数
private int cntt=0; //终结符个数
private char first[][]=new char[9][25];
private char follow[][]=new char[9][25];
private int firstlen[]=new int[9];
private int followlen[]=new int[9];
private String I[][]=new String[200][25];//LALR项目集
private String It[][]=new String [200][25]; //LR后跟的集合
private String Iori[]=new String [25];
private String Itori[]=new String [25];
private int Icnt[]=new int[200];//每个项目集中产生式的个数
private int Ioricnt[]=new int[200];//每个项目集的原始产生式个数
private int Inum=0;//项目集中的个数
private int Taction[][]=new int[200][25];
private int Tgoto[][]=new int[200][10];
private String mstr=null; //要分析的句子
private int escape1[]=new int[25]; //终结符要跟着输出的空格数
private int escape2[]=new int[25];//非终结符
public void InitialProducer() throws NullPointerException{
try{
mapt.clear();
mapt.put(‘a‘“;“); escape1[0]=5;
mapt.put(‘b‘“var“);escape1[1]=3;
mapt.put(‘c‘“id“);escape1[2]=4;
mapt.put(‘d‘“$“);escape1[3]=5;
mapt.put(‘e‘“if“);escape1[4]=4;
mapt.put(‘f‘“then“);escape1[5]=2;
mapt.put(‘g‘“else“);escape1[6]=2;
mapt.put(‘h‘“while“);escape1[7]=1;
mapt.put(‘i‘“do“);escape1[8]=4;
mapt.put(‘j‘“begin“);escape1[9]=1;
mapt.put(‘k‘“end“);escape1[10]=3;
mapt.put(‘l‘“:=“);escape1[11]=4;
mapt.put(‘m‘“:“);escape1[12]=5;
mapt.put(‘n‘“n“);escape1[13]=5;
mapt.put(‘o‘“*“);escape1[14]=5;
mapt.put(‘p‘“(“);escape1[15]=5;
mapt.put(‘q‘“)“);escape1[16]=5;
mapt.put(‘r‘“true“);escape1[17]=2;
mapt.put(‘s‘“false“);escape1[18]=1;
mapt.put(‘t‘“==“);escape1[19]=4;
mapt.put(‘u‘“+“);escape1[20]=5;
mapt.put(‘v‘“#“);escape1[21]=5;
cntt=mapt.size();
mapn.clear();
mapn.put(‘Q‘0);
mapn.put(‘P‘1);
mapn.put(‘D‘2);
mapn.put(‘S‘3);
mapn.put(‘L‘4);
mapn.put(‘E‘5);
mapn.put(‘T‘6);
mapn.put(‘F‘7);
mapn.put(‘B‘8);
cntn=mapn.size();
map[0]=‘Q‘;escape2[0]=5;
map[1]=‘P‘;escape2[1]=5;
map[2]=‘D‘;escape2[2]=5;
map[3]=‘S‘;escape2[3]=5;
map[4]=‘L‘;escape2[4]=5;
map[5]=‘E‘;escape2[5]=5;
map[6]=‘T‘;escape2[6]=5;
map[7]=‘F‘;escape2[7]=5;
map[8]=‘B‘;escape2[8]=5;
len=0;
pro[len++]=“Q-P“;
pro[len++]=“P-DS“;//P-DaS?
pro[len++]=“D-bcaD“;
pro[len++]=“D-d“;
pro[len++]=“S-eBfSgS“;
pro[len++]=“S-hBiS“;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 19624 2009-06-25 12:39 LALR1\classes\LALR.class
文件 1631 2009-06-25 12:39 LALR1\classes\LALR1.class
文件 899 2009-06-25 12:39 LALR1\LALR1.jcp
文件 284 2009-06-25 12:39 LALR1\LALR1.jcw
文件 2125 2009-06-25 12:39 LALR1\LALR12.jcu
文件 285 2009-06-25 12:39 LALR1\LALR12.jcw
文件 25178 2009-06-25 12:39 LALR1\src\LALR.java
文件 1117 2009-06-25 12:39 LALR1\src\LALR1.java
文件 209 2009-06-25 12:39 LALR1\src_lalr1.txt
目录 0 2009-06-25 12:39 LALR1\classes
目录 0 2009-06-25 12:39 LALR1\src
目录 0 2009-06-25 12:39 LALR1
----------- --------- ---------- ----- ----
51352 12
- 上一篇:网上购物系统设计前台部分和后台部分
- 下一篇:Android音乐播放器
相关资源
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
- [免费]java实现有障碍物的贪吃蛇游戏
- java Servlet投票实例
评论
共有 条评论