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

📄 paparser.jj

📁 基于求函数f(x,y,z)=xyz*sin(xyz)最大值问题的演示程序 解压后在命令行输入:java -jar genetic_algorithm.jar
💻 JJ
字号:
options {
        LOOKAHEAD=1;
	JAVA_UNICODE_ESCAPE = true;
	STATIC = false;
//        USER_CHAR_STREAM = true;
}

PARSER_BEGIN(PAParser)

package com.lowagie.text.pdf.codec.postscript;

public class PAParser extends Object {

}

PARSER_END(PAParser)


/* WHITE SPACE  ,WITHINSTRING */
<DEFAULT>
SKIP :
{
  < WHITESPACE: " " | "\t" | "\n" | "\r" | "\f" |"\u0004" >
|
  < "%" ( ~["\n"] )* "\n" >
      |
  < "%" ( ~["\r"] )* "\r" >
  |
  < "%" ( ~["\r"] )* "\r\n" >
}

/* LITERALS */
<DEFAULT>
TOKEN :
{
  < INTEGER_LITERAL:
      ("-")? (  <DECIMAL_LITERAL> (["l","L"])?
      | <HEX_LITERAL> (["l","L"])?
       )
  >
|
  < #DECIMAL_LITERAL: ["0"-"9"] (["0"-"9"])* >
|
  < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
|
  < FLOATING_POINT_LITERAL:
        ((["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?)
      | ("." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?)
      | ((["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?)
      | ((["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"])
      | ("-" (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?)
      | ("-" "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?)
      | ("-" (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?)
      | ("-" (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"])
  >
|
  < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|
  < STRING_LITERAL:
      "("
      (   (~[")","\\"])
        | ("\\"
            ( ["n","t","b","r","f","\\","'",")", "(","\n"]
            | ["0"-"7"] ( ["0"-"7"] )?
            | ["0"-"3"] ["0"-"7"] ["0"-"7"]
            )
          )
      )*
      ")"
  >
}

/* IDENTIFIERS */
<DEFAULT>
TOKEN :
{
  < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|"-"|".")* >
|
  < KEY_IDENTIFIER: "/" ((".")|("#"))? <IDENTIFIER> >
|
  < IMMEDIATE_IDENTIFIER: "//" <IDENTIFIER> >
|
  < #LETTER:
      [
       "+",
       "-",
       "?",
       "\u0024",
       "\u0041"-"\u005a",
       "\u005f",
       "\u0061"-"\u007a",
       "\u00c0"-"\u00d6",
       "\u00d8"-"\u00f6",
       "\u00f8"-"\u00ff",
       "\u0100"-"\u1fff",
       "\u3040"-"\u318f",
       "\u3300"-"\u337f",
       "\u3400"-"\u3d2d",
       "\u4e00"-"\u9fff",
       "\uf900"-"\ufaff"
      ]
  >
|
  < #DIGIT:
      [
       "\u0030"-"\u0039",
       "\u0660"-"\u0669",
       "\u06f0"-"\u06f9",
       "\u0966"-"\u096f",
       "\u09e6"-"\u09ef",
       "\u0a66"-"\u0a6f",
       "\u0ae6"-"\u0aef",
       "\u0b66"-"\u0b6f",
       "\u0be7"-"\u0bef",
       "\u0c66"-"\u0c6f",
       "\u0ce6"-"\u0cef",
       "\u0d66"-"\u0d6f",
       "\u0e50"-"\u0e59",
       "\u0ed0"-"\u0ed9",
       "\u1040"-"\u1049"
      ]
  >
}

/* SEPARATORS */
<DEFAULT>
TOKEN :
{

  < LBRACE: "{" >
| < RBRACE: "}" >
| < LBRACKET: "[" >
| < RBRACKET: "]" >
| < LDICT: "<<" >
| < RDICT: ">>" >
}


<WITHINSTRING>
MORE:
{
  <Nextchar: ~[">"] >
}

<WITHINSTRING>
TOKEN:
{
 <HEX_STRING_LITERAL: ">" > {matchedToken.image=image.toString().substring(0,image.toString().length()-1); } :DEFAULT
}

<DEFAULT>
TOKEN :
{
 < Instring: "<" > :WITHINSTRING
}

JAVACODE
  void error_skipto(int kind){
    ParseException e=generateParseException();
    Token t;
    String dump="";
    do{
      if(getToken(1).kind==kind)break;
      t=getNextToken();
      dump+=t.image;
    }while(t.kind!=kind);

    if (PAContext.DebugExecution) {
      System.out.println("Ignoriere >"+dump+"<");
    }
  }

JAVACODE
  String ExceptionString(String hint,JavaCharStream jj_input_stream,PAContext context,Token t,Exception e ){
    return "\nparser "+hint+" ["+jj_input_stream.bufpos+"]"+context.engine.litMode()+":\""+t.image+"\" in line "+t.beginLine+" column "+t.beginColumn+"\n"+e.toString();
  }


void parse(PAContext context) :
{
        Token x = null;
}
{
  try{
       (

      (
              (  (
                        x = <INTEGER_LITERAL>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+x.image+"\"");System.out.flush();System.err.flush();}}
                                        context.engine.process(new Integer(x.image));
                                } catch(NumberFormatException e) {
                                        throw new ParseException(ExceptionString("int_literal",jj_input_stream,context,token,e));
                                } catch(PainterException e) {
                                        throw new ParseException(ExceptionString("int_literal",jj_input_stream,context,token,e));
                                }
                        }
                )
                |
                (
                        x = <FLOATING_POINT_LITERAL>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+x.image+"\"");System.out.flush();System.err.flush();}}
                                       context.engine.process(new Double(x.image));
                                } catch(NumberFormatException e) {
                                        throw new ParseException(ExceptionString("float_literal",jj_input_stream,context,token,e));
                                } catch(PainterException e) {
                                        throw new ParseException(ExceptionString("float_literal",jj_input_stream,context,token,e));
                                }
                        }
                )
                |
                (
                        <Instring> x = <HEX_STRING_LITERAL>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+x.image+"\"");System.out.flush();System.err.flush();}}
                                      context.engine.process((x.image.substring(1, x.image.length() -1)));
                                } catch(PainterException e) {
                                      throw new ParseException(ExceptionString("hex_string_literal",jj_input_stream,context,token,e));
                                 }
                        }
                )
                |
               (
                       x = <STRING_LITERAL>
                       {
                               try {
                                 {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+x.image+"\"");System.out.flush();System.err.flush();}}
                                     context.engine.process(x.image.substring(1, x.image.length() -1));
                               } catch(PainterException e) {
                                     throw new ParseException(ExceptionString("string_literal",jj_input_stream,context,token,e));
                                }
                       }
               )

                |
                (
                        x = <IDENTIFIER>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+x.image+"\"");System.out.flush();System.err.flush();}}
                                              context.engine.process(new PAToken(x.image, PAToken.IDENTIFIER));
                                } catch(PainterException e) {
                                             throw new ParseException(ExceptionString("identifier",jj_input_stream,context,token,e));
                                }
                        }
                )
                |
                (
                        x = <KEY_IDENTIFIER>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+x.image+"\"");System.out.flush();System.err.flush();}}
                                            context.engine.process(new PAToken(x.image.substring(1, x.image.length()), PAToken.KEY));
                                } catch(PainterException e) {
                                  throw new ParseException(ExceptionString("key_identifier",jj_input_stream,context,token,e));
                                 }
                        }
                )
                |
                (
                        x = <IMMEDIATE_IDENTIFIER>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+x.image+"\"");System.out.flush();System.err.flush();}}
                                            context.engine.process(new PAToken(x.image.substring(2, x.image.length()), PAToken.IMMEDIATE));
                                } catch(PainterException e) {
                                         throw new ParseException(ExceptionString("immediate_identifier",jj_input_stream,context,token,e));
                                }
                        }
                ) )
                |
                (
                        <LBRACE>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+token.image+"\"");System.out.flush();System.err.flush();}}
                                             context.engine.process(new PAToken(null, PAToken.START_PROCEDURE));
                                } catch(PainterException e) {
                                  throw new ParseException(ExceptionString("lbrace",jj_input_stream,context,token,e));
                                }
                        }
                )
                |
                (
                        <RBRACE>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+token.image+"\"");System.out.flush();System.err.flush();}}
                                      context.engine.process(new PAToken(null, PAToken.END_PROCEDURE));
                                } catch(PainterException e) {
                                  throw new ParseException(ExceptionString("rbrace",jj_input_stream,context,token,e));
                               }
                        }
                )
                |
                (
                        <LBRACKET>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+token.image+"\"");System.out.flush();System.err.flush();}}
                                       context.engine.process(new PAToken(null, PAToken.START_ARRAY));
                                } catch(PainterException e) {
                                  throw new ParseException(ExceptionString("lbracket",jj_input_stream,context,token,e));
                                }
                        }
                )
                |
                (
                        <RBRACKET>
                        {
                                try {
                                  {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+token.image+"\"");System.out.flush();System.err.flush();}}
                                       context.engine.process(new PAToken(null, PAToken.END_ARRAY));
                                } catch(PainterException e) {
                                  throw new ParseException(ExceptionString("rbracket",jj_input_stream,context,token,e));
                                }
                        }
                )
                |
               (
                       <LDICT>
                       {
                               try {
                                 {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+token.image+"\"");System.out.flush();System.err.flush();}}
                                      context.engine.process(new PAToken(null, PAToken.START_DICT));
                               } catch(PainterException e) {
                                 throw new ParseException(ExceptionString("ldict",jj_input_stream,context,token,e));
                                }
                       }
               )
               |
               (
                       <RDICT>
                       {
                               try {
                                 {if(PAContext.DebugExecution){System.out.print("\nparser ["+jj_input_stream.getBeginLine()+","+jj_input_stream.getBeginColumn()+"]"+context.engine.litMode()+":\""+token.image+"\"");System.out.flush();System.err.flush();}}
                                       context.engine.process(new PAToken(null, PAToken.END_DICT));
                               } catch(PainterException e) {
                                 throw new ParseException(ExceptionString("rdict",jj_input_stream,context,token,e));
                                 }
                       }
               )

                )
        )*

  }catch(ParseException e){
    if (PAContext.DebugExecution) {
      System.out.flush();System.err.flush();
      //System.out.println("Fehlerhaftes Element in Spalte "+e.currentToken.beginColumn+" in Eingabedatei in Zeile="+e.currentToken.next.beginLine+" in Zeichen Nr. "+e.currentToken.next.beginColumn+". >"+e.currentToken.next.image+"< wurde hier nicht erwartet.");
      //System.err.println("Fehler:"+e);
      e.printStackTrace();
    }
    error_skipto(WHITESPACE);
  }
}



⌨️ 快捷键说明

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