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

📄 javacc.jj

📁 java 编译器java复杂编译器,可以编译java文件的类库
💻 JJ
📖 第 1 页 / 共 4 页
字号:
	{	  if (count > 1) {	    c1.member = seq;	  }	}}void complex_regular_expression_unit(Container c) :	{	  String image;	  RStringLiteral strlit;	  RJustName jn;	  Token t = getToken(1);          int r1 = 0, r2 = -1;	}{  image=StringLiteral()	{	  strlit = new RStringLiteral();	  strlit.line = t.beginLine;	  strlit.column = t.beginColumn;	  strlit.image = image;	  c.member = strlit;	}|  "<" image=identifier() ">"	{	  jn = new RJustName();	  jn.line = t.beginLine;	  jn.column = t.beginColumn;	  jn.label = image;	  c.member = jn;	}|  character_list(c)|  "(" complex_regular_expression_choices(c) ")"  (  "+"	{	  ROneOrMore omrexp = new ROneOrMore();	  omrexp.line = t.beginLine;	  omrexp.column = t.beginColumn;	  omrexp.regexpr = (RegularExpression)c.member;	  c.member = omrexp;	}   | "*"	{	  RZeroOrMore zmrexp = new RZeroOrMore();	  zmrexp.line = t.beginLine;	  zmrexp.column = t.beginColumn;	  zmrexp.regexpr = (RegularExpression)c.member;	  c.member = zmrexp;	}   | "?"	{	  RZeroOrOne zorexp = new RZeroOrOne();	  zorexp.line = t.beginLine;	  zorexp.column = t.beginColumn;	  zorexp.regexpr = (RegularExpression)c.member;	  c.member = zorexp;	}   | "{" r1 = IntegerLiteral() [ "," r2 = IntegerLiteral() ] "}"	{	  RRepetitionRange rrrexp = new RRepetitionRange();	  rrrexp.line = t.beginLine;	  rrrexp.column = t.beginColumn;	  rrrexp.min = r1;	  rrrexp.max = r2;	  rrrexp.regexpr = (RegularExpression)c.member;	  c.member = rrrexp;	}  )?}void character_list(Container c1) :	{	  RCharacterList chlist = new RCharacterList();	  Token t = getToken(1);	  chlist.line = t.beginLine;	  chlist.column = t.beginColumn;	  Container c2 = new Container();	}{  ["~"	{	  chlist.negated_list = true;	}  ]  "[" [ character_descriptor(c2)	{	  chlist.descriptors.addElement(c2.member);	}        ( "," character_descriptor(c2)	{	  chlist.descriptors.addElement(c2.member);	}        )*      ]  "]"	{	  c1.member = chlist;	}}void character_descriptor(Container c) :	{	  char c1, c2 = ' '; // unnecessary initialization to make Java compiler happy!	  boolean isrange = false;	  String imageL, imageR;	  Token t = getToken(1);	}{  imageL=StringLiteral()	{	  c1 = character_descriptor_assign(getToken(0), imageL);	}  [ "-" imageR=StringLiteral()	{	  isrange = true;	  c2 = character_descriptor_assign(getToken(0), imageR, imageL);	}  ]	{	  if (isrange) {	    CharacterRange cr = new CharacterRange();	    cr.line = t.beginLine;	    cr.column = t.beginColumn;	    cr.left = c1;	    cr.right = c2;	    c.member = cr;	  } else {	    SingleCharacter sc = new SingleCharacter();	    sc.line = t.beginLine;	    sc.column = t.beginColumn;	    sc.ch = c1;	    c.member = sc;	  }	}}String identifier() :	{	  Token t;	}{  t=<IDENTIFIER>	{	  return t.image;	}}/********************************************** * THE JAVA GRAMMAR SPECIFICATION STARTS HERE * **********************************************//* * The Java grammar is modified to use sequences of tokens * for the missing tokens - those that include "<<" and ">>". *//* * The following production defines Java identifiers - it * includes the reserved words of JavaCC also. */Token JavaIdentifier() :{}{(  <IDENTIFIER>| "options"| "LOOKAHEAD"| "IGNORE_CASE"| "PARSER_BEGIN"| "PARSER_END"| "JAVACODE"| "TOKEN"| "SPECIAL_TOKEN"| "MORE"| "SKIP"| "TOKEN_MGR_DECLS"| "EOF")	{	  Token retval = getToken(0);	  retval.kind = IDENTIFIER;	  return retval;	}}/* * The productions for the missing code follows.  Obviously * these productions accept more than what is legal in Java, * but that is OK for our purposes. */void ShiftOps() :{}{  "<" "<"|  ">" ">" [ ">" ]}void OtherAssignmentOps() :{}{  "<" "<="|  ">" [ ">" ] ">="}/* * Program structuring syntax follows. */void CompilationUnit() :/* * The <EOF> is deleted since the compilation unit is embedded * within grammar code. */	{	  set_initial_cu_token(getToken(1));	}{  [ PackageDeclaration() ]  ( ImportDeclaration() )*  ( TypeDeclaration() )*	{	  insertionpointerrors(getToken(1));	}}void PackageDeclaration() :{}{  "package" Name(new java.util.Vector()) ";"}void ImportDeclaration() :{}{  "import" Name(new java.util.Vector()) [ "." "*" ] ";"}void TypeDeclaration() :{}{  LOOKAHEAD( ( "abstract" | "final" | "public" )* "class" )  ClassDeclaration()|  InterfaceDeclaration()|  ";"}/* * Declaration syntax follows. */void ClassDeclaration() :{}{  ( "abstract" | "final" | "public" )*  UnmodifiedClassDeclaration()}void UnmodifiedClassDeclaration() :	{	  class_nesting++;	  Token t;	  boolean is_parser_class = false;	}{  "class" t=JavaIdentifier() [ "extends" Name(new java.util.Vector()) ] [ "implements" NameList() ]	{	  if (t.image.equals(parser_class_name) && class_nesting == 1 && processing_cu) {	    is_parser_class = true;	    setinsertionpoint(getToken(1), 1);	  }	}  ClassBody(new java.util.Vector())	{	  if (is_parser_class) {	    setinsertionpoint(getToken(0), 2);	  }	  class_nesting--;	}}void ClassBody(java.util.Vector tokens) :/* * Parsing this fills "tokens" with all tokens of the block * excluding the braces at each end. */	{	  Token first, last;	}{  "{"	{	  first = getToken(1);	}  ( ClassBodyDeclaration() )*	{	  last = getToken(0);	}  "}"	{	  if (last.next != first) { // i.e., this is not an empty sequence	    Token t = first;	    while (true) {	      tokens.addElement(t);	      if (t == last) break;	      t = t.next;	    }	  }	}}void NestedClassDeclaration() :{}{  ( "static" | "abstract" | "final" | "public" | "protected" | "private" )*  UnmodifiedClassDeclaration()}void ClassBodyDeclaration() :{}{  LOOKAHEAD(2)  Initializer()|  LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "class" )  NestedClassDeclaration()|  LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "interface" )  NestedInterfaceDeclaration()|  LOOKAHEAD( [ "public" | "protected" | "private" ] Name(new java.util.Vector()) "(" )  ConstructorDeclaration()|  LOOKAHEAD( MethodDeclarationLookahead() )  MethodDeclaration()|  FieldDeclaration()}// This production is to determine lookahead only.void MethodDeclarationLookahead() :{}{  ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )*  ResultType(new java.util.Vector()) JavaIdentifier() "("}void InterfaceDeclaration() :{}{  ( "abstract" | "public" )*  UnmodifiedInterfaceDeclaration()}void NestedInterfaceDeclaration() :{}{  ( "static" | "abstract" | "final" | "public" | "protected" | "private" )*  UnmodifiedInterfaceDeclaration()}void UnmodifiedInterfaceDeclaration() :{}{  "interface" JavaIdentifier() [ "extends" NameList() ]  "{" ( InterfaceMemberDeclaration() )* "}"}void InterfaceMemberDeclaration() :{}{  LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "class" )  NestedClassDeclaration()|  LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "interface" )  NestedInterfaceDeclaration()|  LOOKAHEAD( MethodDeclarationLookahead() )  MethodDeclaration()|  FieldDeclaration()}void FieldDeclaration() :{}{  ( "public" | "protected" | "private" | "static" | "final" | "transient" | "volatile" )*  Type() VariableDeclarator() ( "," VariableDeclarator() )* ";"}void VariableDeclarator() :{}{  VariableDeclaratorId() [ "=" VariableInitializer() ]}void VariableDeclaratorId() :{}{  JavaIdentifier() ( "[" "]" )*}void VariableInitializer() :{}{  ArrayInitializer()|  Expression(new java.util.Vector())}void ArrayInitializer() :{}{  "{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}"}void MethodDeclaration() :{}{  ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )*  ResultType(new java.util.Vector()) MethodDeclarator() [ "throws" NameList() ]  ( Block(new java.util.Vector()) | ";" )}void MethodDeclarator() :{}{  JavaIdentifier() FormalParameters(new java.util.Vector()) ( "[" "]" )*}void FormalParameters(java.util.Vector tokens) :/* * Parsing this fills "tokens" with all tokens of the formal * parameters excluding the parentheses at each end. */	{	  Token first, last;	}{  "("	{	  first = getToken(1);	}  [ FormalParameter() ( "," FormalParameter() )* ]	{	  last = getToken(0);	}  ")"	{	  if (last.next != first) { // i.e., this is not an empty sequence	    Token t = first;	    while (true) {	      tokens.addElement(t);	      if (t == last) break;	      t = t.next;	    }	  }	}}void FormalParameter() :{}{  [ "final" ] Type() VariableDeclaratorId()}void ConstructorDeclaration() :{}{  [ "public" | "protected" | "private" ]  JavaIdentifier() FormalParameters(new java.util.Vector()) [ "throws" NameList() ]  "{"    [ LOOKAHEAD(ExplicitConstructorInvocation()) ExplicitConstructorInvocation() ]    ( BlockStatement() )*  "}"}void ExplicitConstructorInvocation() :{}{  LOOKAHEAD("this" Arguments(new java.util.Vector()) ";")  "this" Arguments(new java.util.Vector()) ";"|  [ LOOKAHEAD(2) PrimaryExpression() "." ] "super" Arguments(new java.util.Vector()) ";"}void Initializer() :{}{  [ "static" ] Block(new java.util.Vector())}/* * Type, name and expression syntax follows. */void Type() :{}{  ( PrimitiveType() | Name(new java.util.Vector()) ) ( "[" "]" )*}void PrimitiveType() :{}{  "boolean"|  "char"|  "byte"|  "short"|  "int"|  "long"|  "float"|  "double"}void ResultType(java.util.Vector tokens) :	{	  Token first = getToken(1);	}{(  "void"|  Type())	{	  Token last = getToken(0);	  Token t = first;	  while (true) {	    tokens.addElement(t);	    if (t == last) break;	    t = t.next;	  }	}}void Name(java.util.Vector tokens) :/* * A lookahead of 2 is required below since "Name" can be followed * by a ".*" when used in the context of an "ImportDeclaration". */	{	  Token first = getToken(1);	}{  JavaIdentifier()  ( LOOKAHEAD(2) "." JavaIdentifier()  )*	{	  Token last = getToken(0);	  Token t = first;	  while (true) {	    tokens.addElement(t);	    if (t == last) break;	    t = t.next;	  }	}}void NameList() :{}{  Name(new java.util.Vector())  ( "," Name(new java.util.Vector())  )*}/* * Expression syntax follows. */void Expression(java.util.Vector tokens) :/* * This expansion has been written this way instead of: *   Assignment() | ConditionalExpression() * for performance reasons. * However, it is a weakening of the grammar for it allows the LHS of * assignments to be any conditional expression whereas it can only be * a primary expression.  Consider adding a semantic predicate to work * around this. */	{	  Token first = getToken(1);	}{

⌨️ 快捷键说明

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