⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newick.java

📁 生物物种进化历程的演示
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Generated By:JavaCC: Do not edit this line. Newick.java */package Parser;//import Parse.*;import AccordionTreeDrawer.Tree;import AccordionTreeDrawer.TreeNode;/**  * A static class used for parsing a Newick format file containing just one tree  * @author Yunhong Zhou, Tamara Munzner */public class Newick implements NewickConstants {  /** the tree to be generated from this parser */  private static Tree tree;  /** the current TreeNode that the parser is visiting and initiating */  private static TreeNode current_node;  /** a helper TreeNode field */  private static TreeNode tn;  /**    * function parseTree initiates field tree, call function Input to parse the input.   * @param t Tree t will be initiated throught the parsing process    * @author Yunhong Zhou   */  public void parseTree(Tree t) {    tree = t;    try{ Input(); }    catch( ParseException e ){        if(t.getName() == null)          System.out.println("Parsing error with input!");        else          System.out.println("Parsing error with input file " + t.getName());        e.printStackTrace();    }  }  //  WTF!!?!!?//  public void close(){//		tree=null;//		current_node=null;//		tn=null;	//		for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = null;//		System.out.println("clean Parser");//	}////	protected void finalize() throws Throwable {//		 //				 try {//					 close();//				 }//				 finally {//					 super.finalize();     //				 }//	 }   static final public void Input() throws ParseException {  String s;  double len;    current_node = tree.getRoot();    descendant_list();    if (jj_2_1(2)) {      s = label();                  current_node.setName(s);                  //System.out.println("Name: " + s);    } else {      ;    }    if (jj_2_2(2)) {      jj_consume_token(7);      len = branch_length();                                current_node.setWeight(len);                                //System.out.println("weight: " + len);     } else {      ;    }    jj_consume_token(8);    jj_consume_token(0);  }  static final public void descendant_list() throws ParseException {    jj_consume_token(9);        tn = new TreeNode();        current_node.addChild(tn);        current_node = tn;    subtree();    label_1:    while (true) {      if (jj_2_3(2)) {        ;      } else {        break label_1;      }      jj_consume_token(10);          tn = new TreeNode();          current_node.addChild(tn);          current_node = tn;      subtree();    }    jj_consume_token(11);  }/** function subtree will set name, length and weight for each tree node */  static final public void subtree() throws ParseException {  String s;  double len;    if (jj_2_8(2)) {      descendant_list();      if (jj_2_4(2)) {        s = label();                  current_node.setName(s);                  //System.out.println("Name: " + s);       } else {        ;      }      if (jj_2_5(2)) {        jj_consume_token(7);        len = branch_length();                                current_node.setWeight(len);                                //System.out.println("Weight: " + len);      } else {        ;      }         current_node = current_node.parent();    } else {      if (jj_2_6(2)) {        s = label();                  current_node.setName(s);                  //System.out.println("Name: " + s);       } else {        ;      }      if (jj_2_7(2)) {        jj_consume_token(7);        len = branch_length();                                current_node.setWeight(len);                                //System.out.println("Weight: " + len);      } else {        ;      }         current_node = current_node.parent();    }  }  static final public String label() throws ParseException {  String s;    if (jj_2_9(2)) {      s = unquoted_label();                         {if (true) return s;}    } else if (jj_2_10(2)) {      s = quoted_label();                       {if (true) return s;}    } else {      jj_consume_token(-1);      throw new ParseException();    }    throw new Error("Missing return statement in function");  }/** for each unquoted label, we need to replace '_' by ' ' */  static final public String unquoted_label() throws ParseException {  Token t;    if (jj_2_11(2)) {      t = jj_consume_token(unquoted_string);                          String s = new String(t.toString());                          {if (true) return s.replace('_', ' ');}    } else if (jj_2_12(2)) {      t = jj_consume_token(double_number);                        {if (true) return new String(t.toString());}    } else {      jj_consume_token(-1);      throw new ParseException();    }    throw new Error("Missing return statement in function");  }/** for each quoted label, we remove double quotes from the string */  static final public String quoted_label() throws ParseException {  Token t;    t = jj_consume_token(quoted_string);                        String s = new String(t.toString());                        {if (true) return s.substring(1, s.length()-1);}    throw new Error("Missing return statement in function");  }  static final public double branch_length() throws ParseException {  Token t;    t = jj_consume_token(double_number);                        {if (true) return Double.parseDouble(t.toString());}    throw new Error("Missing return statement in function");  }  static final private boolean jj_2_1(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_1();    jj_save(0, xla);    return retval;  }  static final private boolean jj_2_2(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_2();    jj_save(1, xla);    return retval;  }  static final private boolean jj_2_3(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_3();    jj_save(2, xla);    return retval;  }  static final private boolean jj_2_4(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_4();    jj_save(3, xla);    return retval;  }  static final private boolean jj_2_5(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_5();    jj_save(4, xla);    return retval;  }  static final private boolean jj_2_6(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_6();    jj_save(5, xla);    return retval;  }  static final private boolean jj_2_7(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_7();    jj_save(6, xla);    return retval;  }  static final private boolean jj_2_8(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_8();    jj_save(7, xla);    return retval;  }  static final private boolean jj_2_9(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_9();    jj_save(8, xla);    return retval;  }  static final private boolean jj_2_10(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_10();    jj_save(9, xla);    return retval;  }  static final private boolean jj_2_11(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_11();    jj_save(10, xla);    return retval;  }  static final private boolean jj_2_12(int xla) {    jj_la = xla; jj_lastpos = jj_scanpos = token;    boolean retval = !jj_3_12();    jj_save(11, xla);    return retval;  }  static final private boolean jj_3R_7() {    if (jj_scan_token(quoted_string)) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3_12() {    if (jj_scan_token(double_number)) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3_3() {    if (jj_scan_token(10)) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    if (jj_3R_4()) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3_11() {    if (jj_scan_token(unquoted_string)) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3R_6() {    Token xsp;    xsp = jj_scanpos;    if (jj_3_11()) {    jj_scanpos = xsp;    if (jj_3_12()) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3R_5() {    if (jj_scan_token(9)) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    if (jj_3R_4()) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    Token xsp;    while (true) {      xsp = jj_scanpos;      if (jj_3_3()) { jj_scanpos = xsp; break; }      if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    }    if (jj_scan_token(11)) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3_10() {    if (jj_3R_7()) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3_9() {    if (jj_3R_6()) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3R_2() {    Token xsp;    xsp = jj_scanpos;    if (jj_3_9()) {    jj_scanpos = xsp;    if (jj_3_10()) return true;    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;    return false;  }  static final private boolean jj_3_7() {    if (jj_scan_token(7)) return true;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -