bsh
Class Parser

java.lang.Object
  extended bybsh.Parser
All Implemented Interfaces:
ParserConstants, ParserTreeConstants

public class Parser
extends java.lang.Object
implements ParserTreeConstants, ParserConstants

This is the BeanShell parser. It is used internally by the Interpreter class (which is probably what you are looking for). The parser knows only how to parse the structure of the language, it does not understand names, commands, etc.

You can use the Parser from the command line to do basic structural validation of BeanShell files without actually executing them. e.g.

                java bsh.Parser [ -p ] file [ file ] [ ... ]
        

The -p option causes the abstract syntax to be printed.

From code you'd use the Parser like this:

                Parser parser = new Parser(in);
                while( !(eof=parser.Line()) ) {
                        SimpleNode node = parser.popNode();
                        // use the node, etc. (See bsh.BSH* classes)
                }
        


Field Summary
 bsh.Token jj_nt
           
protected  bsh.JJTParserState jjtree
           
 boolean lookingAhead
           
 bsh.Token token
           
 ParserTokenManager token_source
           
 
Fields inherited from interface bsh.ParserTreeConstants
JJTALLOCATIONEXPRESSION, JJTAMBIGUOUSNAME, JJTARGUMENTS, JJTARRAYDIMENSIONS, JJTARRAYINITIALIZER, JJTASSIGNMENT, JJTBINARYEXPRESSION, JJTBLOCK, JJTCASTEXPRESSION, JJTFORMALCOMMENT, JJTFORMALPARAMETER, JJTFORMALPARAMETERS, JJTFORSTATEMENT, JJTIFSTATEMENT, JJTIMPORTDECLARATION, JJTLHSPRIMARYEXPRESSION, JJTLHSPRIMARYSUFFIX, JJTLITERAL, JJTMETHODDECLARATION, JJTMETHODINVOCATION, jjtNodeName, JJTPRIMARYEXPRESSION, JJTPRIMARYSUFFIX, JJTPRIMITIVETYPE, JJTRETURNSTATEMENT, JJTRETURNTYPE, JJTSTATEMENTEXPRESSIONLIST, JJTSWITCHLABEL, JJTSWITCHSTATEMENT, JJTTERNARYEXPRESSION, JJTTHROWSTATEMENT, JJTTRYSTATEMENT, JJTTYPE, JJTTYPEDVARIABLEDECLARATION, JJTUNARYEXPRESSION, JJTVARIABLEDECLARATOR, JJTVOID, JJTWHILESTATEMENT
 
Fields inherited from interface bsh.ParserConstants
_DEFAULT, ANDASSIGN, ANDASSIGNX, ASSIGN, BANG, BIT_AND, BIT_ANDX, BIT_OR, BIT_ORX, BOOL_AND, BOOL_ANDX, BOOL_OR, BOOL_ORX, BOOLEAN, BREAK, BYTE, CASE, CATCH, CHAR, CHARACTER_LITERAL, CLASS, COLON, COMMA, CONST, CONTINUE, DECIMAL_LITERAL, DECR, DEFAULT, DIGIT, DO, DOT, DOUBLE, ELSE, EOF, EQ, EXPONENT, FALSE, FINAL, FINALLY, FLOAT, FLOATING_POINT_LITERAL, FOR, FORMAL_COMMENT, GE, GEX, GOTO, GT, GTX, HASH_BANG_COMMENT, HEX_LITERAL, HOOK, IDENTIFIER, IF, IMPORT, INCR, INSTANCEOF, INT, INTEGER_LITERAL, INTERFACE, LBRACE, LBRACKET, LE, LETTER, LEX, LONG, LPAREN, LSHIFT, LSHIFTASSIGN, LSHIFTASSIGNX, LSHIFTX, LT, LTX, MINUS, MINUSASSIGN, MOD, MODASSIGN, MULTI_LINE_COMMENT, NE, NEW, NONPRINTABLE, NULL, OCTAL_LITERAL, ORASSIGN, ORASSIGNX, PLUS, PLUSASSIGN, PRIVATE, PROTECTED, PUBLIC, RBRACE, RBRACKET, RETURN, RPAREN, RSIGNEDSHIFT, RSIGNEDSHIFTASSIGN, RSIGNEDSHIFTASSIGNX, RSIGNEDSHIFTX, RUNSIGNEDSHIFT, RUNSIGNEDSHIFTASSIGN, RUNSIGNEDSHIFTASSIGNX, RUNSIGNEDSHIFTX, SEMICOLON, SHORT, SINGLE_LINE_COMMENT, SLASH, SLASHASSIGN, STAR, STARASSIGN, STATIC, STRING_LITERAL, SWITCH, THROW, TILDE, tokenImage, TRUE, TRY, VOID, WHILE, XOR, XORASSIGN
 
Constructor Summary
Parser(java.io.InputStream stream)
           
Parser(ParserTokenManager tm)
           
Parser(java.io.Reader stream)
           
 
Method Summary
 void AdditiveExpression()
           
 void AllocationExpression()
           
 void AmbiguousName()
           
 void AndExpression()
           
 void ArgumentList()
           
 void Arguments()
           
 void ArrayDimensions()
           
 void ArrayInitializer()
           
 void Assignment()
           
 int AssignmentOperator()
           
 void Block()
           
 void BlockStatement()
           
 boolean BooleanLiteral()
           
 void BreakStatement()
           
 void CastExpression()
           
 void CastLookahead()
           
 void ConditionalAndExpression()
           
 void ConditionalExpression()
           
 void ConditionalOrExpression()
           
 void ContinueStatement()
           
 void disable_tracing()
           
 void DoStatement()
           
 void EmptyStatement()
           
 void enable_tracing()
           
 void EqualityExpression()
           
 void ExclusiveOrExpression()
           
 void Expression()
           
 void ForInit()
           
 void FormalComment()
           
 void FormalParameter()
           
 void FormalParameters()
           
 void ForStatement()
           
 void ForUpdate()
           
 bsh.ParseException generateParseException()
           
 bsh.Token getNextToken()
           
 bsh.Token getToken(int index)
           
 void IfStatement()
           
 void ImportDeclaration()
           
 void InclusiveOrExpression()
           
 void InstanceOfExpression()
           
 void LabeledStatement()
           
 void LHSPrimaryExpression()
           
 void LHSPrimaryPrefix()
          The method invocation is here to force this to an object type in order to simplify the suffix processing.
 void LHSPrimarySuffix()
           
 boolean Line()
           
 void Literal()
           
static void main(java.lang.String[] args)
           
 void MethodDeclaration()
          THE JAVA LANGUAGE GRAMMAR STARTS HERE *
 void MethodDeclarationLookahead()
           
 void MethodDeclarationTypeLookahead()
           
 void MethodInvocation()
           
 void MultiplicativeExpression()
           
 void NullLiteral()
           
 bsh.SimpleNode popNode()
           
 void PostfixExpression()
           
 void PreDecrementExpression()
           
 void PreIncrementExpression()
           
 void PrimaryExpression()
           
 void PrimaryPrefix()
           
 void PrimarySuffix()
           
 void PrimitiveType()
           
 void ReInit(java.io.InputStream stream)
           
 void ReInit(ParserTokenManager tm)
           
 void ReInit(java.io.Reader stream)
           
 void RelationalExpression()
           
 void ReturnStatement()
           
 void ReturnType()
           
 void setRetainComments(boolean b)
           
 void ShiftExpression()
           
 void Statement()
           
 void StatementExpression()
           
 void StatementExpressionList()
           
 void SwitchLabel()
           
 void SwitchStatement()
           
 void ThrowStatement()
           
 void TryStatement()
           
 void Type()
           
 void TypedVariableDeclaration()
          Declared a typed variable.
 void UnaryExpression()
           
 void UnaryExpressionNotPlusMinus()
           
 void VariableDeclarator()
           
 void VariableInitializer()
           
 void VoidLiteral()
           
 void WhileStatement()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jjtree

protected bsh.JJTParserState jjtree

token_source

public ParserTokenManager token_source

token

public bsh.Token token

jj_nt

public bsh.Token jj_nt

lookingAhead

public boolean lookingAhead
Constructor Detail

Parser

public Parser(java.io.InputStream stream)

Parser

public Parser(java.io.Reader stream)

Parser

public Parser(ParserTokenManager tm)
Method Detail

setRetainComments

public void setRetainComments(boolean b)

popNode

public bsh.SimpleNode popNode()

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        bsh.ParseException
Throws:
java.io.IOException
bsh.ParseException

Line

public final boolean Line()
                   throws bsh.ParseException
Throws:
bsh.ParseException

MethodDeclaration

public final void MethodDeclaration()
                             throws bsh.ParseException
THE JAVA LANGUAGE GRAMMAR STARTS HERE *

Throws:
bsh.ParseException

MethodDeclarationLookahead

public final void MethodDeclarationLookahead()
                                      throws bsh.ParseException
Throws:
bsh.ParseException

MethodDeclarationTypeLookahead

public final void MethodDeclarationTypeLookahead()
                                          throws bsh.ParseException
Throws:
bsh.ParseException

ImportDeclaration

public final void ImportDeclaration()
                             throws bsh.ParseException
Throws:
bsh.ParseException

VariableDeclarator

public final void VariableDeclarator()
                              throws bsh.ParseException
Throws:
bsh.ParseException

VariableInitializer

public final void VariableInitializer()
                               throws bsh.ParseException
Throws:
bsh.ParseException

ArrayInitializer

public final void ArrayInitializer()
                            throws bsh.ParseException
Throws:
bsh.ParseException

FormalParameters

public final void FormalParameters()
                            throws bsh.ParseException
Throws:
bsh.ParseException

FormalParameter

public final void FormalParameter()
                           throws bsh.ParseException
Throws:
bsh.ParseException

Type

public final void Type()
                throws bsh.ParseException
Throws:
bsh.ParseException

ReturnType

public final void ReturnType()
                      throws bsh.ParseException
Throws:
bsh.ParseException

PrimitiveType

public final void PrimitiveType()
                         throws bsh.ParseException
Throws:
bsh.ParseException

AmbiguousName

public final void AmbiguousName()
                         throws bsh.ParseException
Throws:
bsh.ParseException

Expression

public final void Expression()
                      throws bsh.ParseException
Throws:
bsh.ParseException

Assignment

public final void Assignment()
                      throws bsh.ParseException
Throws:
bsh.ParseException

AssignmentOperator

public final int AssignmentOperator()
                             throws bsh.ParseException
Throws:
bsh.ParseException

ConditionalExpression

public final void ConditionalExpression()
                                 throws bsh.ParseException
Throws:
bsh.ParseException

ConditionalOrExpression

public final void ConditionalOrExpression()
                                   throws bsh.ParseException
Throws:
bsh.ParseException

ConditionalAndExpression

public final void ConditionalAndExpression()
                                    throws bsh.ParseException
Throws:
bsh.ParseException

InclusiveOrExpression

public final void InclusiveOrExpression()
                                 throws bsh.ParseException
Throws:
bsh.ParseException

ExclusiveOrExpression

public final void ExclusiveOrExpression()
                                 throws bsh.ParseException
Throws:
bsh.ParseException

AndExpression

public final void AndExpression()
                         throws bsh.ParseException
Throws:
bsh.ParseException

EqualityExpression

public final void EqualityExpression()
                              throws bsh.ParseException
Throws:
bsh.ParseException

InstanceOfExpression

public final void InstanceOfExpression()
                                throws bsh.ParseException
Throws:
bsh.ParseException

RelationalExpression

public final void RelationalExpression()
                                throws bsh.ParseException
Throws:
bsh.ParseException

ShiftExpression

public final void ShiftExpression()
                           throws bsh.ParseException
Throws:
bsh.ParseException

AdditiveExpression

public final void AdditiveExpression()
                              throws bsh.ParseException
Throws:
bsh.ParseException

MultiplicativeExpression

public final void MultiplicativeExpression()
                                    throws bsh.ParseException
Throws:
bsh.ParseException

UnaryExpression

public final void UnaryExpression()
                           throws bsh.ParseException
Throws:
bsh.ParseException

PreIncrementExpression

public final void PreIncrementExpression()
                                  throws bsh.ParseException
Throws:
bsh.ParseException

PreDecrementExpression

public final void PreDecrementExpression()
                                  throws bsh.ParseException
Throws:
bsh.ParseException

UnaryExpressionNotPlusMinus

public final void UnaryExpressionNotPlusMinus()
                                       throws bsh.ParseException
Throws:
bsh.ParseException

CastLookahead

public final void CastLookahead()
                         throws bsh.ParseException
Throws:
bsh.ParseException

PostfixExpression

public final void PostfixExpression()
                             throws bsh.ParseException
Throws:
bsh.ParseException

CastExpression

public final void CastExpression()
                          throws bsh.ParseException
Throws:
bsh.ParseException

PrimaryExpression

public final void PrimaryExpression()
                             throws bsh.ParseException
Throws:
bsh.ParseException

MethodInvocation

public final void MethodInvocation()
                            throws bsh.ParseException
Throws:
bsh.ParseException

PrimaryPrefix

public final void PrimaryPrefix()
                         throws bsh.ParseException
Throws:
bsh.ParseException

PrimarySuffix

public final void PrimarySuffix()
                         throws bsh.ParseException
Throws:
bsh.ParseException

LHSPrimaryPrefix

public final void LHSPrimaryPrefix()
                            throws bsh.ParseException
The method invocation is here to force this to an object type in order to simplify the suffix processing.

Throws:
bsh.ParseException

LHSPrimaryExpression

public final void LHSPrimaryExpression()
                                throws bsh.ParseException
Throws:
bsh.ParseException

LHSPrimarySuffix

public final void LHSPrimarySuffix()
                            throws bsh.ParseException
Throws:
bsh.ParseException

Literal

public final void Literal()
                   throws bsh.ParseException
Throws:
bsh.ParseException

BooleanLiteral

public final boolean BooleanLiteral()
                             throws bsh.ParseException
Throws:
bsh.ParseException

NullLiteral

public final void NullLiteral()
                       throws bsh.ParseException
Throws:
bsh.ParseException

VoidLiteral

public final void VoidLiteral()
                       throws bsh.ParseException
Throws:
bsh.ParseException

Arguments

public final void Arguments()
                     throws bsh.ParseException
Throws:
bsh.ParseException

ArgumentList

public final void ArgumentList()
                        throws bsh.ParseException
Throws:
bsh.ParseException

AllocationExpression

public final void AllocationExpression()
                                throws bsh.ParseException
Throws:
bsh.ParseException

ArrayDimensions

public final void ArrayDimensions()
                           throws bsh.ParseException
Throws:
bsh.ParseException

Statement

public final void Statement()
                     throws bsh.ParseException
Throws:
bsh.ParseException

LabeledStatement

public final void LabeledStatement()
                            throws bsh.ParseException
Throws:
bsh.ParseException

Block

public final void Block()
                 throws bsh.ParseException
Throws:
bsh.ParseException

BlockStatement

public final void BlockStatement()
                          throws bsh.ParseException
Throws:
bsh.ParseException

FormalComment

public final void FormalComment()
                         throws bsh.ParseException
Throws:
bsh.ParseException

EmptyStatement

public final void EmptyStatement()
                          throws bsh.ParseException
Throws:
bsh.ParseException

StatementExpression

public final void StatementExpression()
                               throws bsh.ParseException
Throws:
bsh.ParseException

SwitchStatement

public final void SwitchStatement()
                           throws bsh.ParseException
Throws:
bsh.ParseException

SwitchLabel

public final void SwitchLabel()
                       throws bsh.ParseException
Throws:
bsh.ParseException

IfStatement

public final void IfStatement()
                       throws bsh.ParseException
Throws:
bsh.ParseException

WhileStatement

public final void WhileStatement()
                          throws bsh.ParseException
Throws:
bsh.ParseException

DoStatement

public final void DoStatement()
                       throws bsh.ParseException
Throws:
bsh.ParseException

ForStatement

public final void ForStatement()
                        throws bsh.ParseException
Throws:
bsh.ParseException

ForInit

public final void ForInit()
                   throws bsh.ParseException
Throws:
bsh.ParseException

TypedVariableDeclaration

public final void TypedVariableDeclaration()
                                    throws bsh.ParseException
Declared a typed variable. Untyped variables are not declared per-se but are handled by the part of the grammar that deals with assignments.

Throws:
bsh.ParseException

StatementExpressionList

public final void StatementExpressionList()
                                   throws bsh.ParseException
Throws:
bsh.ParseException

ForUpdate

public final void ForUpdate()
                     throws bsh.ParseException
Throws:
bsh.ParseException

BreakStatement

public final void BreakStatement()
                          throws bsh.ParseException
Throws:
bsh.ParseException

ContinueStatement

public final void ContinueStatement()
                             throws bsh.ParseException
Throws:
bsh.ParseException

ReturnStatement

public final void ReturnStatement()
                           throws bsh.ParseException
Throws:
bsh.ParseException

ThrowStatement

public final void ThrowStatement()
                          throws bsh.ParseException
Throws:
bsh.ParseException

TryStatement

public final void TryStatement()
                        throws bsh.ParseException
Throws:
bsh.ParseException

ReInit

public void ReInit(java.io.InputStream stream)

ReInit

public void ReInit(java.io.Reader stream)

ReInit

public void ReInit(ParserTokenManager tm)

getNextToken

public final bsh.Token getNextToken()

getToken

public final bsh.Token getToken(int index)

generateParseException

public final bsh.ParseException generateParseException()

enable_tracing

public final void enable_tracing()

disable_tracing

public final void disable_tracing()


© 2000 pat@pat.net :-)