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

📄 calcparser.java

📁 CroftSoft Code Library是一个开源的可移植的纯Java游戏库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

//----------------------------------------------------
// The following code was generated by CUP v0.10i
// Tue Mar 16 03:05:28 EST 1999
//----------------------------------------------------

package com.croftsoft.apps.compiler;

import java.util.HashMap;
import java.util.Map;
import java_cup.runtime.*;

public class CalcParser extends java_cup.runtime.lr_parser {

  /** constructor */
  public CalcParser() {super();}

  /** production table */
  protected static final short _production_table[][] = 
    unpackFromStrings(new String[] {
    "\000\025\000\002\002\004\000\002\003\003\000\002\004" +
    "\005\000\002\004\004\000\002\005\003\000\002\005\003" +
    "\000\002\005\003\000\002\006\006\000\002\006\006\000" +
    "\002\007\005\000\002\010\005\000\002\010\005\000\002" +
    "\010\005\000\002\010\005\000\002\010\005\000\002\010" +
    "\005\000\002\010\004\000\002\010\003\000\002\010\003" +
    "\000\002\010\005\000\002\010\005" });

  /** access to production table */
  public short[][] production_table() {return _production_table;}

  /** parse action table */
  protected static final short[][] _action_table = 
    unpackFromStrings(new String[] {
    "\000\051\000\010\003\005\024\007\027\013\001\002\000" +
    "\004\002\053\001\002\000\004\021\ufffb\001\002\000\004" +
    "\021\ufffc\001\002\000\004\022\046\001\002\000\004\002" +
    "\000\001\002\000\004\021\044\001\002\000\004\021\ufffd" +
    "\001\002\000\004\025\014\001\002\000\012\005\016\022" +
    "\017\026\015\027\021\001\002\000\022\004\uffef\005\uffef" +
    "\006\uffef\007\uffef\010\uffef\011\uffef\021\uffef\023\uffef\001" +
    "\002\000\012\005\016\022\017\026\015\027\021\001\002" +
    "\000\012\005\016\022\017\026\015\027\040\001\002\000" +
    "\022\004\023\005\024\006\027\007\026\010\022\011\025" +
    "\021\ufff8\023\ufff8\001\002\000\022\004\ufff0\005\ufff0\006" +
    "\ufff0\007\ufff0\010\ufff0\011\ufff0\021\ufff0\023\ufff0\001\002" +
    "\000\012\005\016\022\017\026\015\027\021\001\002\000" +
    "\012\005\016\022\017\026\015\027\021\001\002\000\012" +
    "\005\016\022\017\026\015\027\021\001\002\000\012\005" +
    "\016\022\017\026\015\027\021\001\002\000\012\005\016" +
    "\022\017\026\015\027\021\001\002\000\012\005\016\022" +
    "\017\026\015\027\021\001\002\000\022\004\ufff5\005\ufff5" +
    "\006\ufff5\007\ufff5\010\ufff5\011\025\021\ufff5\023\ufff5\001" +
    "\002\000\022\004\ufff4\005\ufff4\006\ufff4\007\ufff4\010\ufff4" +
    "\011\025\021\ufff4\023\ufff4\001\002\000\022\004\ufff3\005" +
    "\ufff3\006\ufff3\007\ufff3\010\ufff3\011\025\021\ufff3\023\ufff3" +
    "\001\002\000\022\004\ufff6\005\ufff6\006\027\007\026\010" +
    "\022\011\025\021\ufff6\023\ufff6\001\002\000\022\004\ufff7" +
    "\005\ufff7\006\027\007\026\010\022\011\025\021\ufff7\023" +
    "\ufff7\001\002\000\022\004\ufff2\005\ufff2\006\ufff2\007\ufff2" +
    "\010\ufff2\011\025\021\ufff2\023\ufff2\001\002\000\004\023" +
    "\042\001\002\000\020\004\023\005\024\006\027\007\026" +
    "\010\022\011\025\023\041\001\002\000\022\004\ufff0\005" +
    "\ufff0\006\ufff0\007\ufff0\010\ufff0\011\ufff0\023\ufff0\025\014" +
    "\001\002\000\022\004\uffee\005\uffee\006\uffee\007\uffee\010" +
    "\uffee\011\uffee\021\uffee\023\uffee\001\002\000\022\004\uffed" +
    "\005\uffed\006\uffed\007\uffed\010\uffed\011\uffed\021\uffed\023" +
    "\uffed\001\002\000\022\004\ufff1\005\ufff1\006\ufff1\007\ufff1" +
    "\010\ufff1\011\025\021\ufff1\023\ufff1\001\002\000\012\002" +
    "\ufffe\003\005\024\007\027\013\001\002\000\004\002\uffff" +
    "\001\002\000\012\005\016\022\017\026\015\027\040\001" +
    "\002\000\020\004\023\005\024\006\027\007\026\010\022" +
    "\011\025\023\052\001\002\000\004\023\051\001\002\000" +
    "\004\021\ufff9\001\002\000\004\021\ufffa\001\002\000\004" +
    "\002\001\001\002" });

  /** access to parse action table */
  public short[][] action_table() {return _action_table;}

  /** reduce_goto table */
  protected static final short[][] _reduce_table = 
    unpackFromStrings(new String[] {
    "\000\051\000\014\003\003\004\007\005\010\006\005\007" +
    "\011\001\001\000\002\001\001\000\002\001\001\000\002" +
    "\001\001\000\002\001\001\000\002\001\001\000\002\001" +
    "\001\000\002\001\001\000\002\001\001\000\004\010\017" +
    "\001\001\000\002\001\001\000\004\010\042\001\001\000" +
    "\006\007\035\010\036\001\001\000\002\001\001\000\002" +
    "\001\001\000\004\010\034\001\001\000\004\010\033\001" +
    "\001\000\004\010\032\001\001\000\004\010\031\001\001" +
    "\000\004\010\030\001\001\000\004\010\027\001\001\000" +
    "\002\001\001\000\002\001\001\000\002\001\001\000\002" +
    "\001\001\000\002\001\001\000\002\001\001\000\002\001" +
    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +
    "\000\002\001\001\000\002\001\001\000\012\004\044\005" +
    "\010\006\005\007\011\001\001\000\002\001\001\000\006" +
    "\007\047\010\046\001\001\000\002\001\001\000\002\001" +
    "\001\000\002\001\001\000\002\001\001\000\002\001\001" +
    "" });

  /** access to reduce_goto table */
  public short[][] reduce_table() {return _reduce_table;}

  /** instance of action encapsulation class */
  protected CUP$CalcParser$actions action_obj;

  /** action encapsulation object initializer */
  protected void init_actions()
    {
      action_obj = new CUP$CalcParser$actions(this);
    }

  /** invoke a user supplied parse action */
  public java_cup.runtime.Symbol do_action(
    int                        act_num,
    java_cup.runtime.lr_parser parser,
    java.util.Stack            stack,
    int                        top)
    throws java.lang.Exception
  {
    /* call code in generated class */
    return action_obj.CUP$CalcParser$do_action(act_num, parser, stack, top);
  }

  /** start state */
  public int start_state() {return 0;}
  /** start production */
  public int start_production() {return 0;}

  /** EOF Symbol index */
  public int EOF_sym() {return 0;}

  /** error Symbol index */
  public int error_sym() {return 1;}


  /** user initialization */
  public void user_init() throws java.lang.Exception
    {
 
    }

  /** scan to get the next Symbol */
  public java_cup.runtime.Symbol scan()
    throws java.lang.Exception
    {
 return calcScanner.nextToken ( ); 
    }



     protected CalcScanner  calcScanner;

     public  CalcParser ( CalcScanner  calcScanner )
     //////////////////////////////////////////////////////////////////////
     {
       this.calcScanner = calcScanner;
     }

     
}

/** Cup generated class to encapsulate user supplied action code.*/
class CUP$CalcParser$actions {



     //////////////////////////////////////////////////////////////////////
     // Action Code
     //////////////////////////////////////////////////////////////////////

     public static Integer  actExpressPlus ( Integer  e0, Integer  e1 )
     //////////////////////////////////////////////////////////////////////
     {
       if ( ( e0 == null ) || ( e1 == null ) )
       {
         System.out.println ( "null operand" );
         return null;
       }

       return new Integer ( e0.intValue ( ) + e1.intValue ( ) );
     }

     public static Integer  actExpressMinus ( Integer  e0, Integer  e1 )
     //////////////////////////////////////////////////////////////////////
     {
       if ( ( e0 == null ) || ( e1 == null ) )
       {
         System.out.println ( "null operand" );
         return null;
       }

       return new Integer ( e0.intValue ( ) - e1.intValue ( ) );
     }

     public static Integer  actExpressTimes ( Integer  e0, Integer  e1 )
     //////////////////////////////////////////////////////////////////////
     {
       if ( ( e0 == null ) || ( e1 == null ) )
       {
         System.out.println ( "null operand" );
         return null;
       }

       return new Integer ( e0.intValue ( ) * e1.intValue ( ) );
     }

     public static Integer  actExpressDivide ( Integer  e0, Integer  e1 )
     //////////////////////////////////////////////////////////////////////
     {
       if ( ( e0 == null ) || ( e1 == null ) )
       {
         System.out.println ( "null operand" );
         return null;
       }

       return new Integer ( e0.intValue ( ) / e1.intValue ( ) );
     }

     public static Integer  actExpressExponent ( Integer  e0, Integer  e1 )
     //////////////////////////////////////////////////////////////////////
     {
       if ( ( e0 == null ) || ( e1 == null ) )
       {
         System.out.println ( "null operand" );
         return null;
       }

       return new Integer ( power ( e0.intValue ( ), e1.intValue ( ) ) );
     }

     public static Integer  actExpressModulus ( Integer  e0, Integer  e1 )
     //////////////////////////////////////////////////////////////////////
     {
       if ( ( e0 == null ) || ( e1 == null ) )
       {
         System.out.println ( "null operand" );
         return null;
       }

       return new Integer ( e0.intValue ( ) % e1.intValue ( ) );
     }

     public static Integer  actExpressNegate ( Integer  e0 )
     //////////////////////////////////////////////////////////////////////
     {
       if ( e0 == null )
       {
         System.out.println ( "null operand" );
         return null;
       }

       return new Integer ( -e0.intValue ( ) );
     }

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

     public static int  power ( int  a, int  b )
     //////////////////////////////////////////////////////////////////////
     {
       if ( b < 0 )
       {
         throw new IllegalArgumentException ( "negative exponent" );
       }

       int  result = 1;

       for ( int  i = 0; i < b; i++ )
       {
         result *= a;
       }

       return result;
     }

     //////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////

     private Map  map = new HashMap ( );

     public Integer  actExpressVariable ( String  variable )
     //////////////////////////////////////////////////////////////////////
     {
       return ( Integer ) map.get ( variable );
     }

     public void  actWrite ( Integer  i )
     //////////////////////////////////////////////////////////////////////
     {
       System.out.println ( i );
     }

     public Integer  actAssignment ( String  variable, Integer  i )
     //////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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