All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javacc-7.0.1.test.tmp.Interpreter.SPL.jj Maven / Gradle / Ivy

There is a newer version: 7.0.13
Show newest version
/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. SPL.jj */
/*@egen*//* Copyright (c) 2006, Sun Microsystems, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Sun Microsystems, Inc. nor the names of its
 *       contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

options {
               
                          
                      
}

PARSER_BEGIN(SPLParser)

/** Stupid Programming Language parser. */
public class SPLParser/*@bgen(jjtree)*/implements SPLParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
  protected static JJTSPLParserState jjtree = new JJTSPLParserState();

/*@egen*/

  /**
   * Returns the root node of the AST.  
   * It only makes sense to call this after a successful parse. 
   * @return the root node
   */
  public Node rootNode() {
    return jjtree.rootNode();
  }  

}

PARSER_END(SPLParser)


SKIP : /* WHITE SPACE */
{
  " "
| "\t"
| "\n"
| "\r"
| "\f"
}

TOKEN : /* Types */
{
   < INT: "int" >
 |
   < BOOL: "boolean" >
}

TOKEN : /* LITERALS */
{
  < INTEGER_LITERAL: ()+ >
}

/*
 * Program structuring syntax follows.
 */

/** Compilation unit. */
void CompilationUnit() :
{/*@bgen(jjtree) CompilationUnit */
   ASTCompilationUnit jjtn000 = new ASTCompilationUnit(JJTCOMPILATIONUNIT);
   boolean jjtc000 = true;
   jjtree.openNodeScope(jjtn000);
   jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/
   String name;
}
{/*@bgen(jjtree) CompilationUnit */
   try {
/*@egen*/
   (
       VarDeclaration() ";"
     |
       Statement()
   )*
   /*@bgen(jjtree)*/
   } catch (Throwable jjte000) {
     if (jjtc000) {
       jjtree.clearNodeScope(jjtn000);
       jjtc000 = false;
     } else {
       jjtree.popNode();
     }
     if (jjte000 instanceof RuntimeException) {
       throw (RuntimeException)jjte000;
     }
     if (jjte000 instanceof ParseException) {
       throw (ParseException)jjte000;
     }
     throw (Error)jjte000;
   } finally {
     if (jjtc000) {
       jjtree.closeNodeScope(jjtn000, true);
       jjtn000.jjtSetLastToken(getToken(0));
     }
   }
/*@egen*/
}

/** Variable declaration. */
void VarDeclaration() :
{/*@bgen(jjtree) VarDeclaration */
  ASTVarDeclaration jjtn000 = new ASTVarDeclaration(JJTVARDECLARATION);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/ Token t; }
{/*@bgen(jjtree) VarDeclaration */
  try {
/*@egen*/
  (
    "boolean" { jjtn000.type = BOOL; }
   |
    "int" { jjtn000.type = INT; }
  )
  t = /*@bgen(jjtree)*/
  {
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.jjtSetLastToken(getToken(0));
  }
/*@egen*/ 
  { jjtn000.name = t.image; }/*@bgen(jjtree)*/
  } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
      jjtn000.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/
}

/*
 * Expression syntax follows.
 */

/** Expression. */
void Expression()      :
{}
{
  LOOKAHEAD( PrimaryExpression() "=" )
  Assignment()
|
  ConditionalOrExpression()
}

/** Assignment. */
void Assignment()                :
{/*@bgen(jjtree) #Assignment( 2) */
  ASTAssignment jjtn000 = new ASTAssignment(JJTASSIGNMENT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/}
{/*@bgen(jjtree) #Assignment( 2) */
  try {
/*@egen*/
  PrimaryExpression() "=" Expression()/*@bgen(jjtree)*/
  } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      throw (RuntimeException)jjte000;
    }
    if (jjte000 instanceof ParseException) {
      throw (ParseException)jjte000;
    }
    throw (Error)jjte000;
  } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000,  2);
      jjtn000.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/
}

/** Conditional or expression. */
void ConditionalOrExpression()       :
{}
{
  ConditionalAndExpression()
  ( "||"/*@bgen(jjtree) #OrNode( 2) */
         {
           ASTOrNode jjtn001 = new ASTOrNode(JJTORNODE);
           boolean jjtc001 = true;
           jjtree.openNodeScope(jjtn001);
           jjtn001.jjtSetFirstToken(getToken(1));
         }
         try {
/*@egen*/ ConditionalAndExpression()/*@bgen(jjtree)*/
         } catch (Throwable jjte001) {
           if (jjtc001) {
             jjtree.clearNodeScope(jjtn001);
             jjtc001 = false;
           } else {
             jjtree.popNode();
           }
           if (jjte001 instanceof RuntimeException) {
             throw (RuntimeException)jjte001;
           }
           if (jjte001 instanceof ParseException) {
             throw (ParseException)jjte001;
           }
           throw (Error)jjte001;
         } finally {
           if (jjtc001) {
             jjtree.closeNodeScope(jjtn001,  2);
             jjtn001.jjtSetLastToken(getToken(0));
           }
         }
/*@egen*/            )*
}

/** Conditional and expression. */
void ConditionalAndExpression()       :
{}
{
  InclusiveOrExpression()
  ( "&&"/*@bgen(jjtree) #AndNode( 2) */
         {
           ASTAndNode jjtn001 = new ASTAndNode(JJTANDNODE);
           boolean jjtc001 = true;
           jjtree.openNodeScope(jjtn001);
           jjtn001.jjtSetFirstToken(getToken(1));
         }
         try {
/*@egen*/ InclusiveOrExpression()/*@bgen(jjtree)*/
         } catch (Throwable jjte001) {
           if (jjtc001) {
             jjtree.clearNodeScope(jjtn001);
             jjtc001 = false;
           } else {
             jjtree.popNode();
           }
           if (jjte001 instanceof RuntimeException) {
             throw (RuntimeException)jjte001;
           }
           if (jjte001 instanceof ParseException) {
             throw (ParseException)jjte001;
           }
           throw (Error)jjte001;
         } finally {
           if (jjtc001) {
             jjtree.closeNodeScope(jjtn001,  2);
             jjtn001.jjtSetLastToken(getToken(0));
           }
         }
/*@egen*/             )*
}

/** Inclusive or expression. */
void InclusiveOrExpression()       :
{}
{
  ExclusiveOrExpression()
  ( "|"/*@bgen(jjtree) #BitwiseOrNode( 2) */
        {
          ASTBitwiseOrNode jjtn001 = new ASTBitwiseOrNode(JJTBITWISEORNODE);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
          jjtn001.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ ExclusiveOrExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte001) {
          if (jjtc001) {
            jjtree.clearNodeScope(jjtn001);
            jjtc001 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte001 instanceof RuntimeException) {
            throw (RuntimeException)jjte001;
          }
          if (jjte001 instanceof ParseException) {
            throw (ParseException)jjte001;
          }
          throw (Error)jjte001;
        } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001,  2);
            jjtn001.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/                   )*
}

/** Exclusive or expression. */
void ExclusiveOrExpression()       :
{}
{
  AndExpression()
  ( "^"/*@bgen(jjtree) #BitwiseXorNode( 2) */
        {
          ASTBitwiseXorNode jjtn001 = new ASTBitwiseXorNode(JJTBITWISEXORNODE);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
          jjtn001.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ AndExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte001) {
          if (jjtc001) {
            jjtree.clearNodeScope(jjtn001);
            jjtc001 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte001 instanceof RuntimeException) {
            throw (RuntimeException)jjte001;
          }
          if (jjte001 instanceof ParseException) {
            throw (ParseException)jjte001;
          }
          throw (Error)jjte001;
        } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001,  2);
            jjtn001.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/                    )*
}

/** And expression. */
void AndExpression()       :
{}
{
  EqualityExpression()
  ( "&"/*@bgen(jjtree) #BitwiseAndNode( 2) */
        {
          ASTBitwiseAndNode jjtn001 = new ASTBitwiseAndNode(JJTBITWISEANDNODE);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
          jjtn001.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ EqualityExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte001) {
          if (jjtc001) {
            jjtree.clearNodeScope(jjtn001);
            jjtc001 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte001 instanceof RuntimeException) {
            throw (RuntimeException)jjte001;
          }
          if (jjte001 instanceof ParseException) {
            throw (ParseException)jjte001;
          }
          throw (Error)jjte001;
        } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001,  2);
            jjtn001.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/                    )*
}

/** Equality expression. */
void EqualityExpression()       :
{}
{
  RelationalExpression()
  (
     "=="/*@bgen(jjtree) #EQNode( 2) */
          {
            ASTEQNode jjtn001 = new ASTEQNode(JJTEQNODE);
            boolean jjtc001 = true;
            jjtree.openNodeScope(jjtn001);
            jjtn001.jjtSetFirstToken(getToken(1));
          }
          try {
/*@egen*/ RelationalExpression()/*@bgen(jjtree)*/
          } catch (Throwable jjte001) {
            if (jjtc001) {
              jjtree.clearNodeScope(jjtn001);
              jjtc001 = false;
            } else {
              jjtree.popNode();
            }
            if (jjte001 instanceof RuntimeException) {
              throw (RuntimeException)jjte001;
            }
            if (jjte001 instanceof ParseException) {
              throw (ParseException)jjte001;
            }
            throw (Error)jjte001;
          } finally {
            if (jjtc001) {
              jjtree.closeNodeScope(jjtn001,  2);
              jjtn001.jjtSetLastToken(getToken(0));
            }
          }
/*@egen*/           
   |
     "!="/*@bgen(jjtree) #NENode( 2) */
          {
            ASTNENode jjtn002 = new ASTNENode(JJTNENODE);
            boolean jjtc002 = true;
            jjtree.openNodeScope(jjtn002);
            jjtn002.jjtSetFirstToken(getToken(1));
          }
          try {
/*@egen*/ RelationalExpression()/*@bgen(jjtree)*/
          } catch (Throwable jjte002) {
            if (jjtc002) {
              jjtree.clearNodeScope(jjtn002);
              jjtc002 = false;
            } else {
              jjtree.popNode();
            }
            if (jjte002 instanceof RuntimeException) {
              throw (RuntimeException)jjte002;
            }
            if (jjte002 instanceof ParseException) {
              throw (ParseException)jjte002;
            }
            throw (Error)jjte002;
          } finally {
            if (jjtc002) {
              jjtree.closeNodeScope(jjtn002,  2);
              jjtn002.jjtSetLastToken(getToken(0));
            }
          }
/*@egen*/           
  )*
}

/** Relational expression. */
void RelationalExpression()       :
{}
{
  AdditiveExpression()
  (
    "<"/*@bgen(jjtree) #LTNode( 2) */
        {
          ASTLTNode jjtn001 = new ASTLTNode(JJTLTNODE);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
          jjtn001.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ AdditiveExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte001) {
          if (jjtc001) {
            jjtree.clearNodeScope(jjtn001);
            jjtc001 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte001 instanceof RuntimeException) {
            throw (RuntimeException)jjte001;
          }
          if (jjte001 instanceof ParseException) {
            throw (ParseException)jjte001;
          }
          throw (Error)jjte001;
        } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001,  2);
            jjtn001.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/           
   |
    ">"/*@bgen(jjtree) #GTNode( 2) */
        {
          ASTGTNode jjtn002 = new ASTGTNode(JJTGTNODE);
          boolean jjtc002 = true;
          jjtree.openNodeScope(jjtn002);
          jjtn002.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ AdditiveExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte002) {
          if (jjtc002) {
            jjtree.clearNodeScope(jjtn002);
            jjtc002 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte002 instanceof RuntimeException) {
            throw (RuntimeException)jjte002;
          }
          if (jjte002 instanceof ParseException) {
            throw (ParseException)jjte002;
          }
          throw (Error)jjte002;
        } finally {
          if (jjtc002) {
            jjtree.closeNodeScope(jjtn002,  2);
            jjtn002.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/           
   |
    "<="/*@bgen(jjtree) #LENode( 2) */
         {
           ASTLENode jjtn003 = new ASTLENode(JJTLENODE);
           boolean jjtc003 = true;
           jjtree.openNodeScope(jjtn003);
           jjtn003.jjtSetFirstToken(getToken(1));
         }
         try {
/*@egen*/ AdditiveExpression()/*@bgen(jjtree)*/
         } catch (Throwable jjte003) {
           if (jjtc003) {
             jjtree.clearNodeScope(jjtn003);
             jjtc003 = false;
           } else {
             jjtree.popNode();
           }
           if (jjte003 instanceof RuntimeException) {
             throw (RuntimeException)jjte003;
           }
           if (jjte003 instanceof ParseException) {
             throw (ParseException)jjte003;
           }
           throw (Error)jjte003;
         } finally {
           if (jjtc003) {
             jjtree.closeNodeScope(jjtn003,  2);
             jjtn003.jjtSetLastToken(getToken(0));
           }
         }
/*@egen*/           
   |
    ">="/*@bgen(jjtree) #GENode( 2) */
         {
           ASTGENode jjtn004 = new ASTGENode(JJTGENODE);
           boolean jjtc004 = true;
           jjtree.openNodeScope(jjtn004);
           jjtn004.jjtSetFirstToken(getToken(1));
         }
         try {
/*@egen*/ AdditiveExpression()/*@bgen(jjtree)*/
         } catch (Throwable jjte004) {
           if (jjtc004) {
             jjtree.clearNodeScope(jjtn004);
             jjtc004 = false;
           } else {
             jjtree.popNode();
           }
           if (jjte004 instanceof RuntimeException) {
             throw (RuntimeException)jjte004;
           }
           if (jjte004 instanceof ParseException) {
             throw (ParseException)jjte004;
           }
           throw (Error)jjte004;
         } finally {
           if (jjtc004) {
             jjtree.closeNodeScope(jjtn004,  2);
             jjtn004.jjtSetLastToken(getToken(0));
           }
         }
/*@egen*/           
  )*
}

/** Additive expression. */
void AdditiveExpression()       :
{}
{
  MultiplicativeExpression()
  (
    "+"/*@bgen(jjtree) #AddNode( 2) */
        {
          ASTAddNode jjtn001 = new ASTAddNode(JJTADDNODE);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
          jjtn001.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ MultiplicativeExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte001) {
          if (jjtc001) {
            jjtree.clearNodeScope(jjtn001);
            jjtc001 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte001 instanceof RuntimeException) {
            throw (RuntimeException)jjte001;
          }
          if (jjte001 instanceof ParseException) {
            throw (ParseException)jjte001;
          }
          throw (Error)jjte001;
        } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001,  2);
            jjtn001.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/            
   |
    "-"/*@bgen(jjtree) #SubtractNode( 2) */
        {
          ASTSubtractNode jjtn002 = new ASTSubtractNode(JJTSUBTRACTNODE);
          boolean jjtc002 = true;
          jjtree.openNodeScope(jjtn002);
          jjtn002.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ MultiplicativeExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte002) {
          if (jjtc002) {
            jjtree.clearNodeScope(jjtn002);
            jjtc002 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte002 instanceof RuntimeException) {
            throw (RuntimeException)jjte002;
          }
          if (jjte002 instanceof ParseException) {
            throw (ParseException)jjte002;
          }
          throw (Error)jjte002;
        } finally {
          if (jjtc002) {
            jjtree.closeNodeScope(jjtn002,  2);
            jjtn002.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/                 
  )*
}

/** Multiplicative expression. */
void MultiplicativeExpression()       :
{}
{
  UnaryExpression()
  (
    "*"/*@bgen(jjtree) #MulNode( 2) */
        {
          ASTMulNode jjtn001 = new ASTMulNode(JJTMULNODE);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
          jjtn001.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ UnaryExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte001) {
          if (jjtc001) {
            jjtree.clearNodeScope(jjtn001);
            jjtc001 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte001 instanceof RuntimeException) {
            throw (RuntimeException)jjte001;
          }
          if (jjte001 instanceof ParseException) {
            throw (ParseException)jjte001;
          }
          throw (Error)jjte001;
        } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001,  2);
            jjtn001.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/            
   |
    "/"/*@bgen(jjtree) #DivNode( 2) */
        {
          ASTDivNode jjtn002 = new ASTDivNode(JJTDIVNODE);
          boolean jjtc002 = true;
          jjtree.openNodeScope(jjtn002);
          jjtn002.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ UnaryExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte002) {
          if (jjtc002) {
            jjtree.clearNodeScope(jjtn002);
            jjtc002 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte002 instanceof RuntimeException) {
            throw (RuntimeException)jjte002;
          }
          if (jjte002 instanceof ParseException) {
            throw (ParseException)jjte002;
          }
          throw (Error)jjte002;
        } finally {
          if (jjtc002) {
            jjtree.closeNodeScope(jjtn002,  2);
            jjtn002.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/            
   |
    "%"/*@bgen(jjtree) #ModNode( 2) */
        {
          ASTModNode jjtn003 = new ASTModNode(JJTMODNODE);
          boolean jjtc003 = true;
          jjtree.openNodeScope(jjtn003);
          jjtn003.jjtSetFirstToken(getToken(1));
        }
        try {
/*@egen*/ UnaryExpression()/*@bgen(jjtree)*/
        } catch (Throwable jjte003) {
          if (jjtc003) {
            jjtree.clearNodeScope(jjtn003);
            jjtc003 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte003 instanceof RuntimeException) {
            throw (RuntimeException)jjte003;
          }
          if (jjte003 instanceof ParseException) {
            throw (ParseException)jjte003;
          }
          throw (Error)jjte003;
        } finally {
          if (jjtc003) {
            jjtree.closeNodeScope(jjtn003,  2);
            jjtn003.jjtSetLastToken(getToken(0));
          }
        }
/*@egen*/            
  )*
}

/** Unary expression. */
void UnaryExpression()       :
{}
{
  "~"/*@bgen(jjtree) #BitwiseComplNode( 1) */
      {
        ASTBitwiseComplNode jjtn001 = new ASTBitwiseComplNode(JJTBITWISECOMPLNODE);
        boolean jjtc001 = true;
        jjtree.openNodeScope(jjtn001);
        jjtn001.jjtSetFirstToken(getToken(1));
      }
      try {
/*@egen*/ UnaryExpression()/*@bgen(jjtree)*/
      } catch (Throwable jjte001) {
        if (jjtc001) {
          jjtree.clearNodeScope(jjtn001);
          jjtc001 = false;
        } else {
          jjtree.popNode();
        }
        if (jjte001 instanceof RuntimeException) {
          throw (RuntimeException)jjte001;
        }
        if (jjte001 instanceof ParseException) {
          throw (ParseException)jjte001;
        }
        throw (Error)jjte001;
      } finally {
        if (jjtc001) {
          jjtree.closeNodeScope(jjtn001,  1);
          jjtn001.jjtSetLastToken(getToken(0));
        }
      }
/*@egen*/                     
|
  "!"/*@bgen(jjtree) #NotNode( 1) */
      {
        ASTNotNode jjtn002 = new ASTNotNode(JJTNOTNODE);
        boolean jjtc002 = true;
        jjtree.openNodeScope(jjtn002);
        jjtn002.jjtSetFirstToken(getToken(1));
      }
      try {
/*@egen*/ UnaryExpression()/*@bgen(jjtree)*/
      } catch (Throwable jjte002) {
        if (jjtc002) {
          jjtree.clearNodeScope(jjtn002);
          jjtc002 = false;
        } else {
          jjtree.popNode();
        }
        if (jjte002 instanceof RuntimeException) {
          throw (RuntimeException)jjte002;
        }
        if (jjte002 instanceof ParseException) {
          throw (ParseException)jjte002;
        }
        throw (Error)jjte002;
      } finally {
        if (jjtc002) {
          jjtree.closeNodeScope(jjtn002,  1);
          jjtn002.jjtSetLastToken(getToken(0));
        }
      }
/*@egen*/            
|
  PrimaryExpression()
}

/** Primary expression. */
void PrimaryExpression()       :
{
   String name;
}
{
  Literal()
|
  Id() 
|
  "(" Expression() ")"
}

/** An Id. */
void Id() :
{/*@bgen(jjtree) Id */
   ASTId jjtn000 = new ASTId(JJTID);
   boolean jjtc000 = true;
   jjtree.openNodeScope(jjtn000);
   jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/
   Token t;
}
{/*@bgen(jjtree) Id */
   try {
/*@egen*/
   t = /*@bgen(jjtree)*/
                     {
                       jjtree.closeNodeScope(jjtn000, true);
                       jjtc000 = false;
                       jjtn000.jjtSetLastToken(getToken(0));
                     }
/*@egen*/  { jjtn000.name = t.image; }/*@bgen(jjtree)*/
   } finally {
     if (jjtc000) {
       jjtree.closeNodeScope(jjtn000, true);
       jjtn000.jjtSetLastToken(getToken(0));
     }
   }
/*@egen*/
}

/** A literal. */
void Literal()       :
{
   Token t;
}
{/*@bgen(jjtree) IntConstNode */
 {
   ASTIntConstNode jjtn001 = new ASTIntConstNode(JJTINTCONSTNODE);
   boolean jjtc001 = true;
   jjtree.openNodeScope(jjtn001);
   jjtn001.jjtSetFirstToken(getToken(1));
 }
 try {
/*@egen*/
 (
  t=/*@bgen(jjtree)*/
    {
      jjtree.closeNodeScope(jjtn001, true);
      jjtc001 = false;
      jjtn001.jjtSetLastToken(getToken(0));
    }
/*@egen*/
    {
       jjtn001.val = Integer.parseInt(t.image);
    }
 )/*@bgen(jjtree)*/
 } finally {
   if (jjtc001) {
     jjtree.closeNodeScope(jjtn001, true);
     jjtn001.jjtSetLastToken(getToken(0));
   }
 }
/*@egen*/             
|
  BooleanLiteral()
}

/** A boolean literal. */
void BooleanLiteral()       :
{}
{/*@bgen(jjtree) TrueNode */
  {
    ASTTrueNode jjtn001 = new ASTTrueNode(JJTTRUENODE);
    boolean jjtc001 = true;
    jjtree.openNodeScope(jjtn001);
    jjtn001.jjtSetFirstToken(getToken(1));
  }
  try {
/*@egen*/
  "true"/*@bgen(jjtree)*/
  } finally {
    if (jjtc001) {
      jjtree.closeNodeScope(jjtn001, true);
      jjtn001.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/          
|/*@bgen(jjtree) FalseNode */
  {
    ASTFalseNode jjtn002 = new ASTFalseNode(JJTFALSENODE);
    boolean jjtc002 = true;
    jjtree.openNodeScope(jjtn002);
    jjtn002.jjtSetFirstToken(getToken(1));
  }
  try {
/*@egen*/
  "false"/*@bgen(jjtree)*/
  } finally {
    if (jjtc002) {
      jjtree.closeNodeScope(jjtn002, true);
      jjtn002.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/           
}

/*
 * Statement syntax follows.
 */

/** A statement. */
void Statement()       :
{}
{
  ";"
|
  LOOKAHEAD(2)
  LabeledStatement()
|
  Block()
|
  StatementExpression()
|
  IfStatement()
|
  WhileStatement()
|
  IOStatement()
}

/** A labeled statement. */
void LabeledStatement()       :
{}
{
   ":" Statement()
}

/** A block. */
void Block() :
{/*@bgen(jjtree) Block */
  ASTBlock jjtn000 = new ASTBlock(JJTBLOCK);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/}
{/*@bgen(jjtree) Block */
  try {
/*@egen*/
  "{" ( Statement() )* "}"/*@bgen(jjtree)*/
  } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      throw (RuntimeException)jjte000;
    }
    if (jjte000 instanceof ParseException) {
      throw (ParseException)jjte000;
    }
    throw (Error)jjte000;
  } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
      jjtn000.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/
}

/** A statement expression. */
void StatementExpression() :
/*
 * The last expansion of this production accepts more than the legal
 * SPL expansions for StatementExpression.
 */
{/*@bgen(jjtree) StatementExpression */
  ASTStatementExpression jjtn000 = new ASTStatementExpression(JJTSTATEMENTEXPRESSION);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/}
{/*@bgen(jjtree) StatementExpression */
  try {
/*@egen*/
  Assignment() ";"/*@bgen(jjtree)*/
  } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      throw (RuntimeException)jjte000;
    }
    if (jjte000 instanceof ParseException) {
      throw (ParseException)jjte000;
    }
    throw (Error)jjte000;
  } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
      jjtn000.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/
}

/** An if statement. */
void IfStatement() :
/*
 * The disambiguating algorithm of JavaCC automatically binds dangling
 * else's to the innermost if statement.  The LOOKAHEAD specification
 * is to tell JavaCC that we know what we are doing.
 */
{/*@bgen(jjtree) IfStatement */
  ASTIfStatement jjtn000 = new ASTIfStatement(JJTIFSTATEMENT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/}
{/*@bgen(jjtree) IfStatement */
  try {
/*@egen*/
  "if" "(" Expression() ")" Statement() [ LOOKAHEAD(1) "else" Statement() ]/*@bgen(jjtree)*/
  } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      throw (RuntimeException)jjte000;
    }
    if (jjte000 instanceof ParseException) {
      throw (ParseException)jjte000;
    }
    throw (Error)jjte000;
  } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
      jjtn000.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/
}

/** A while statement. */
void WhileStatement() :
{/*@bgen(jjtree) WhileStatement */
  ASTWhileStatement jjtn000 = new ASTWhileStatement(JJTWHILESTATEMENT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/}
{/*@bgen(jjtree) WhileStatement */
  try {
/*@egen*/
  "while" "(" Expression() ")" Statement()/*@bgen(jjtree)*/
  } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      throw (RuntimeException)jjte000;
    }
    if (jjte000 instanceof ParseException) {
      throw (ParseException)jjte000;
    }
    throw (Error)jjte000;
  } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
      jjtn000.jjtSetLastToken(getToken(0));
    }
  }
/*@egen*/
}

/** An IO statement. */
void IOStatement()       :
{ String name; }
{
   ReadStatement()
 |
   WriteStatement()
}

/** A read statement. */
void ReadStatement() :
{/*@bgen(jjtree) ReadStatement */
  ASTReadStatement jjtn000 = new ASTReadStatement(JJTREADSTATEMENT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/ Token t; }
{/*@bgen(jjtree) ReadStatement */
   try {
/*@egen*/
   "read" t = /*@bgen(jjtree)*/
   {
     jjtree.closeNodeScope(jjtn000, true);
     jjtc000 = false;
     jjtn000.jjtSetLastToken(getToken(0));
   }
/*@egen*/
   { jjtn000.name = t.image; }/*@bgen(jjtree)*/
   } finally {
     if (jjtc000) {
       jjtree.closeNodeScope(jjtn000, true);
       jjtn000.jjtSetLastToken(getToken(0));
     }
   }
/*@egen*/
}

/** A write statement. */
void WriteStatement() :
{/*@bgen(jjtree) WriteStatement */
  ASTWriteStatement jjtn000 = new ASTWriteStatement(JJTWRITESTATEMENT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
  jjtn000.jjtSetFirstToken(getToken(1));
/*@egen*/ Token t; }
{/*@bgen(jjtree) WriteStatement */
   try {
/*@egen*/
   "write" t = /*@bgen(jjtree)*/
   {
     jjtree.closeNodeScope(jjtn000, true);
     jjtc000 = false;
     jjtn000.jjtSetLastToken(getToken(0));
   }
/*@egen*/
   { jjtn000.name = t.image; }/*@bgen(jjtree)*/
   } finally {
     if (jjtc000) {
       jjtree.closeNodeScope(jjtn000, true);
       jjtn000.jjtSetLastToken(getToken(0));
     }
   }
/*@egen*/
}

TOKEN : /* IDENTIFIERS */
{
  < IDENTIFIER:  (|)* >
|
  < #LETTER: [ "a"-"z", "A"-"Z" ] >
|
  < #DIGIT: [ "0"-"9"] >
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy