/* Generated By:JavaCC: Do not edit this line. ifParse.java */
package ifelsesematic;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
@SuppressWarnings("all")
public class ifParse implements ifParseConstants {
public int count=0; /*四元式标号*/
public static ArrayList<Sys> sysList = new ArrayList<Sys>();
public int ncount=0; /*临时变量下标*/
public static void main(String args[]) throws ParseException {
FileInputStream fileStream;
try {
fileStream = new FileInputStream("test1.c");
ifParse parser = new ifParse(fileStream);
System.out.println("Reading from standard input...");
System.out.println("Enter c programe only main() with only while();\" :");
try {
switch (parser.start()) {
case 0:
System.out.println("OK.");
break;
case 1:
System.out.println("Goodbye.");
break;
default:
break;
}
for(int i = 0; i<sysList.size(); i++){
System.out.println(sysList.get(i));
}
} catch (Exception e) {
System.out.println("NOK.");
System.out.println(e.getMessage());
parser.ReInit(System.in);
} catch (Error e) {
System.out.println("Oops.");
System.out.println(e.getMessage());
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
final public int start() throws ParseException {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case VOID:
Procedure();
jj_consume_token(0);
{if (true) return 0;}
break;
case 0:
jj_consume_token(0);
{if (true) return 1;}
break;
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/*处理主程序*/
final public void Procedure() throws ParseException {
jj_consume_token(VOID);
jj_consume_token(MAIN);
jj_consume_token(LC);
jj_consume_token(RC);
jj_consume_token(LB);
Statement();
jj_consume_token(RB);
}
final public void Statement() throws ParseException {
IfStatement();
label_1:
while (true) {
if (jj_2_1(2)) {
;
} else {
break label_1;
}
ElseifStatement();
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case ELSE:
ElseStatement();
break;
default:
jj_la1[1] = jj_gen;
;
}
}
/* IfStatement */
final public void IfStatement() throws ParseException {
Token node; //
int j1;
int next; //下一个四元式标号
Sys newsys;
jj_consume_token(IF);
jj_consume_token(LC);
next=count+1;
Condition();
jj_consume_token(RC);
count++;
j1=count;
newsys = new Sys(count+"","J","_", "_", j1+"#"); //声明一个新的四元式(1:J,_,_,1#)
sysList.add(newsys);
jj_consume_token(LB);
next=count+1;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case IDENTIFIER:
Assign();
jj_consume_token(28);
break;
case IF:
Statement();
break;
default:
jj_la1[2] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(RB);
count++; //count=2
newsys = new Sys(count+"","J","_", "_", next+""); //声明一个新的四元式(2:J,_,_,1#)
sysList.add(newsys);
EditSys.huitian(sysList, j1+"#", count+1+""); //回填如果四元式列表中有result==1#的则将其result置为2
}
/* ElseStatement */
final public void ElseStatement() throws ParseException {
Token node;
int j1;
int next; //下一个四元式标号
Sys newsys;
jj_consume_token(ELSE);
jj_consume_token(LB);
next=count+1;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case IDENTIFIER:
Assign();
jj_consume_token(28);
break;
case IF:
Statement();
break;
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(RB);
count++;
j1=count; //count=2
newsys = new Sys(count+"","J","_", "_", next+""); //声明一个新的四元式(2:J,_,_,1#)
sysList.add(newsys);
EditSys.huitian(sysList, j1+"#", count+1+""); //回填如果四元式列表中有result==1#的则将其result置为2
}
final public void ElseifStatement() throws ParseException {
Token node;
int j1;
int next; //下一个四元式标号
Sys newsys;
jj_consume_token(ELSE);
jj_consume_token(IF);
jj_consume_token(LC);
next=count+1;
Condition();
jj_consume_token(RC);
count++;
j1=count;
newsys = new Sys(count+"","J","_", "_", j1+"#");
sysList.add(newsys);
jj_consume_token(LB);
next=count+1;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case IDENTIFIER:
Assign();
jj_consume_token(28);
break;
case IF:
Statement();
break;
default:
jj_la1[4] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(RB);
count++;
newsys = new Sys(count+"","J","_", "_",j1+"#"+"");
sysList.add(newsys);
EditSys.huitian(sysList, j1+"#", count+1+"");
}
/*
void IfStatement():
{
Token node;
int j1;
int next;
Sys newsys;
}
{
<IF><LC>
{
next=count+1;
}
Condition()<RC>
{
count++;
j1=count;
newsys = new Sys(count+"","J","_", "_", j1+"#");
sysList.add(newsys);
}
<LB>
{
next=count+1;
}
((Assign()";")|Statement())<RB>
{
count++;
newsys = new Sys(count+"","J","_", "_", j1+"#"+"");
sysList.add(newsys);
EditSys.huitian(sysList, j1+"#", count+1+"");
}
}
void ElseifStatement():
{
Token node;
int j1;
int next;
Sys newsys;
}
{
<ELSE><IF><LC>
{
next=count+1;
}
Condition()<RC>
{
count++;
j1=count;
newsys = new Sys(count+"","J","_", "_", j1+"#");
sysList.add(newsys);
}
<LB>
{
next=count+1;
}
((Assign()";")|Statement())<RB>
{
count++;
newsys = new Sys(count+"","J","_", "_",j1+"#"+"");
sysList.add(newsys);
EditSys.huitian(sysList, j1+"#", count+1+"");
}
}
void ElseStatement():
{
Token node;
int j1;
int next;
Sys newsys;
}
{
<ELSE>
<LB>
{
next=count+1;
}
((Assign()";")|Statement())<RB>
{
count++;
j1=count;
newsys = new Sys(count+"","J","_", "_", j1+"#");
sysList.add(newsys);
EditSys.huitian(sysList, j1+"#", count+1+"");
}
}*/
final public String Expression() throws ParseException {
//定义变量
String first;
String middle;
String temp="";
Sys newsys;
//函数体
first = Term();
temp=first;
label_2:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case PLUS:
case MINUS:
;
break;
default:
jj_la1[5] = jj_gen;
break label_2;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case PLUS:
jj_consume_token(PLUS);
middle = Term();
//加法要分步计算
count++;
temp="T"+ncount;
ncount++;
newsys = new Sys(count+"","+",first,middle,temp);
sysList.add(newsys);
first = temp;
//fi
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ifelse语义分析源代码.rar (11个子文件)
ifelse语义分析源代码
src
test1.c 269B
ifelsesematic
SimpleCharStream.java 12KB
ifParseConstants.java 2KB
Sys.java 1KB
ifsematic.jj 9KB
ParseException.java 7KB
TokenMgrError.java 5KB
EditSys.java 494B
Token.java 4KB
ifParseTokenManager.java 14KB
ifParse.java 22KB
共 11 条
- 1
Eiffee_Lee
- 粉丝: 0
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页