2016012904 王凯生 语法分析.rar

  • 一念凉丶
    了解作者
  • C/C++
    开发工具
  • 102KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 0
    下载次数
  • 2019-12-19 17:05
    上传日期
学期结束的编译原理机房实习的语法分析代码
2016012904 王凯生 语法分析.rar
  • 2016012904 王凯生 语法分析
  • src
  • MyNodeList.java
    783B
  • Adder.java
    76.1KB
  • ParseException.java
    6.7KB
  • JJTAdderState.java
    3.3KB
  • Node.java
    1.2KB
  • SimpleNode.java
    2.4KB
  • SimpleCharStream.java
    12.2KB
  • Record.java
    471B
  • MyTip.java
    1.2KB
  • AdderTreeConstants.java
    1.5KB
  • AdderConstants.java
    4.9KB
  • Adder.jjt
    26.6KB
  • MyNode.java
    1.6KB
  • AdderTokenManager.java
    32.3KB
  • Adder.jj
    50.9KB
  • TokenMgrError.java
    4.5KB
  • Token.java
    3.8KB
  • .settings
  • org.eclipse.jdt.core.prefs
    629B
  • bin
  • TokenMgrError.class
    2.7KB
  • MyTip.class
    2KB
  • SimpleNode.class
    2.7KB
  • JJTAdderState.class
    2.5KB
  • AdderTreeConstants.class
    1.9KB
  • Token.class
    1KB
  • MyNode.class
    2.3KB
  • AdderTokenManager.class
    15.5KB
  • SimpleCharStream.class
    8KB
  • Record.class
    881B
  • Adder.class
    41.4KB
  • MyNodeList.class
    1.6KB
  • Adder.jjt
    26.6KB
  • ParseException.class
    3.4KB
  • Node.class
    304B
  • Adder.jj
    50.9KB
  • AdderConstants.class
    3.9KB
  • .project
    384B
  • 测试用例.c
    836B
  • .classpath
    301B
内容介绍
/* Generated By:JJTree&JavaCC: Do not edit this line. Adder.java */ import java.util.ArrayList; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; public class Adder/*@bgen(jjtree)*/implements AdderTreeConstants, AdderConstants {/*@bgen(jjtree)*/ protected JJTAdderState jjtree = new JJTAdderState();public static int count=0; /*四元式标号*/ public static int ncount=0; /*临时变量下标*/ public static int con; public static int j=0; public static ArrayList<MyTip> tips=new ArrayList<MyTip>(); public static FileOutputStream foutStream ; public static PrintStream print_Stream; static ArrayList<MyNode> mylist=new ArrayList<MyNode>();//结点集合 static MyNodeList myNodeList=new MyNodeList(mylist);//封装结点集合,对结点进行处理 public static void main(String args[]) throws Exception { Lexical(); //词法分析 FileInputStream fileStream; try { fileStream = new FileInputStream("\u6d4b\u8bd5\u7528\u4f8b.c"); Adder parser = new Adder(fileStream); foutStream = new FileOutputStream("\u8bed\u4e49\u5206\u6790.txt"); print_Stream = new PrintStream(foutStream); try { SimpleNode n = parser.Start(); n.dump(""); System.out.println("\u8bed\u6cd5\u6811\u5df2\u8f93\u51fa"); fileStream.close(); } 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(); } { FileOutputStream ftableStream = new FileOutputStream("\u7b26\u53f7\u8868.txt"); PrintStream table_Stream = new PrintStream(ftableStream); String Symbol_table=""; for(MyNode tem:myNodeList.mylist){ Symbol_table+=tem; } System.out.println("\u7b26\u53f7\u8868\u5df2\u8f93\u51fa"); table_Stream.print(Symbol_table); } } public static void Lexical()throws FileNotFoundException{ SimpleCharStream jj_input_stream=new SimpleCharStream(new FileInputStream("\u6d4b\u8bd5\u7528\u4f8b.c")); AdderTokenManager TokenManager=new AdderTokenManager(jj_input_stream); FileOutputStream fcifaStream = new FileOutputStream("\u8bcd\u6cd5\u5206\u6790.txt"); PrintStream Lexical_Stream = new PrintStream(fcifaStream); System.out.println("\u8bcd\u6cd5\u5206\u6790\u5df2\u8f93\u51fa"); int n=1; String lexical=""; for(;;){ Token t=TokenManager.getNextToken(); if(t.kind==0){ break; } lexical+="(\t"+t.image+"\t"+t.kind+"\t)"+" "; if(n%3==0) lexical+="\r\n"; n++; } Lexical_Stream.print(lexical); } final public SimpleNode Start() throws ParseException { /*@bgen(jjtree) Start */ SimpleNode jjtn000 = new SimpleNode(JJTSTART); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VOID: case 72: Procedure(); jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; /////////////// for(int i=0;i<tips.size();i++) { MyTip temp=tips.get(i); //System.out.print(temp.toString()); print_Stream.print(temp.toString()); } System.out.println("\u8bed\u4e49\u5206\u6790\u5df2\u8f93\u51fa"); {if (true) return jjtn000;} break; case 0: jj_consume_token(0); jjtree.closeNodeScope(jjtn000, true); jjtc000 = false; {if (true) return jjtn000;} break; default: jj_la1[0] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } throw new Error("Missing return statement in function"); } /*处理主程序*/ final public void Procedure() throws ParseException { /*@bgen(jjtree) Procedure */ SimpleNode jjtn000 = new SimpleNode(JJTPROCEDURE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 72: ; break; default: jj_la1[1] = jj_gen; break label_1; } jj_consume_token(72); jj_consume_token(INCLUDE); jj_consume_token(LOWER); Head(); jj_consume_token(GREAT); } jj_consume_token(VOID); jj_consume_token(MAIN); jj_consume_token(LC); jj_consume_token(RC); SentenceBlock(); } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } //语句块 final public void SentenceBlock() throws ParseException { /*@bgen(jjtree) SentenceBlock */ SimpleNode jjtn000 = new SimpleNode(JJTSENTENCEBLOCK); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LB: jj_consume_token(LB); StatementBunth(); jj_consume_token(RB); break; default: jj_la1[2] = jj_gen; StatementBunth(); } } catch (Throwable jjte000) { if (jjtc000) { jjtree.clearNodeScope(jjtn000); jjtc000 = false; } else { jjtree.popNode(); } if (jjte000 instanceof RuntimeException) { {if (true) throw (RuntimeException)jjte000;} } if (jjte000 instanceof ParseException) { {if (true) throw (ParseException)jjte000;} } {if (true) throw (Error)jjte000;} } finally { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); } } } //语句串 final public void StatementBunth() throws ParseException { /*@bgen(jjtree) StatementBunth */ SimpleNode jjtn000 = new SimpleNode(JJTSTATEMENTBUNTH); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); try { label_2: while (true) { switch ((jj_ntk==-1)?
评论
    相关推荐