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

📄 expr.jj

📁 jpda例子文件
💻 JJ
📖 第 1 页 / 共 2 页
字号:
|  "short"|  "int"|  "long"|  "float"|  "double"}String Name() :{StringBuffer sb = new StringBuffer();}{  <IDENTIFIER> { sb.append(token); }  ( LOOKAHEAD(2) "." <IDENTIFIER> { sb.append('.'); sb.append(token); }  )*        { return sb.toString(); }}void NameList() :{}{  Name()  ( "," Name()  )*}/* * Expression syntax follows. */void Expression() :{}{  LOOKAHEAD( PrimaryExpression() AssignmentOperator() )  Assignment()|  ConditionalExpression()}void Assignment() :{}{  PrimaryExpression() AssignmentOperator() Expression()        { LValue exprVal = pop(); pop().setValue(exprVal); push(exprVal);}}void AssignmentOperator() :{}{  "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>=" | "&=" | "^=" | "|="}void ConditionalExpression() :{}{  ConditionalOrExpression()         [ "?" Expression() ":" ConditionalExpression()                 { LValue falseBranch = pop(); LValue trueBranch = pop();                   Value cond = pop().interiorGetValue();                  if (cond instanceof BooleanValue) {                        push(((BooleanValue)cond).booleanValue()?                                         trueBranch : falseBranch);                  } else {                        throw new ParseException("Condition must be boolean");                  }                }        ]}void ConditionalOrExpression() :{}{  ConditionalAndExpression()         ( "||" ConditionalAndExpression()                         { throw new ParseException("operation not yet supported"); }        )*}void ConditionalAndExpression() :{}{  InclusiveOrExpression()         ( "&&" InclusiveOrExpression()                         { throw new ParseException("operation not yet supported"); }        )*}void InclusiveOrExpression() :{}{  ExclusiveOrExpression()         ( "|" ExclusiveOrExpression()                         { throw new ParseException("operation not yet supported"); }        )*}void ExclusiveOrExpression() :{}{  AndExpression()         ( "^" AndExpression()                         { throw new ParseException("operation not yet supported"); }        )*}void AndExpression() :{}{  EqualityExpression()         ( "&" EqualityExpression()                         { throw new ParseException("operation not yet supported"); }        )*}void EqualityExpression() :{Token tok;}{  InstanceOfExpression()         ( ( tok = "==" | tok = "!=" ) InstanceOfExpression()                 { LValue left = pop();                   push( LValue.booleanOperation(vm, tok, pop(), left) ); }        )*}void InstanceOfExpression() :{}{  RelationalExpression()         [ "instanceof" Type()                         { throw new ParseException("operation not yet supported"); }        ]}void RelationalExpression() :{Token tok;}{  ShiftExpression()         ( ( tok = "<" | tok = ">" | tok = "<=" | tok = ">=" ) ShiftExpression()                { LValue left = pop();                   push( LValue.booleanOperation(vm, tok, pop(), left) ); }         )*}void ShiftExpression() :{}{  AdditiveExpression()         ( ( "<<" | ">>" | ">>>" ) AdditiveExpression()                         { throw new ParseException("operation not yet supported"); }        )*}void AdditiveExpression() :{Token tok;}{  MultiplicativeExpression()         ( ( tok = "+" | tok = "-" ) MultiplicativeExpression()                 { LValue left = pop();                   push( LValue.operation(vm, tok, pop(), left, frameGetter) ); }        )*}void MultiplicativeExpression() :{Token tok;}{  UnaryExpression()         ( ( tok = "*" | tok = "/" | tok = "%" ) UnaryExpression()                { LValue left = pop();                   push( LValue.operation(vm, tok, pop(), left, frameGetter) ); }        )*}void UnaryExpression() :{}{  ( "+" | "-" ) UnaryExpression()                        { throw new ParseException("operation not yet supported"); }|  PreIncrementExpression()|  PreDecrementExpression()|  UnaryExpressionNotPlusMinus()}void PreIncrementExpression() :{}{  "++" PrimaryExpression()                        { throw new ParseException("operation not yet supported"); }}void PreDecrementExpression() :{}{  "--" PrimaryExpression()                        { throw new ParseException("operation not yet supported"); }}void UnaryExpressionNotPlusMinus() :{}{  ( "~" | "!" ) UnaryExpression()                        { throw new ParseException("operation not yet supported"); }|  LOOKAHEAD( CastLookahead() )  CastExpression()|  PostfixExpression()}// This production is to determine lookahead only.  The LOOKAHEAD specifications// below are not used, but they are there just to indicate that we know about// this.void CastLookahead() :{}{  LOOKAHEAD(2)  "(" PrimitiveType()|  LOOKAHEAD("(" Name() "[")  "(" Name() "[" "]"|  "(" Name() ")" ( "~" | "!" | "(" | <IDENTIFIER> | "this" | "super" | "new" | Literal() )}void PostfixExpression() :{}{  PrimaryExpression()         [ "++" | "--"                         { throw new ParseException("operation not yet supported"); }        ]}void CastExpression() :{}{  LOOKAHEAD(2)  "(" PrimitiveType() ( "[" "]" )* ")" UnaryExpression()|  "(" Name() ( "[" "]" )* ")" UnaryExpressionNotPlusMinus()}void PrimaryExpression() :{}{  PrimaryPrefix() ( PrimarySuffix() )*}void PrimaryPrefix() :{String name;}{  Literal()|  name = Name()                        { push(LValue.makeName(vm, frameGetter, name)); }|  "this"                        { push(LValue.makeThisObject(vm, frameGetter, token)); }|  "super" "." <IDENTIFIER>                        { throw new ParseException("operation not yet supported"); }|  "(" Expression() ")"|  AllocationExpression()}void PrimarySuffix() :{List argList;}{  "[" Expression() "]"                          { LValue index = pop();                          push(pop().arrayElementLValue(index)); }|  "." <IDENTIFIER>                        { push(pop().memberLValue(frameGetter, token.image)); }|  argList = Arguments()                        { peek().invokeWith(argList); }}void Literal() :{}{  <INTEGER_LITERAL>                        { push(LValue.makeInteger(vm, token)); }|  <FLOATING_POINT_LITERAL>                        { push(LValue.makeFloat(vm, token)); }|  <CHARACTER_LITERAL>                        { push(LValue.makeCharacter(vm, token)); }|  <STRING_LITERAL>                        { push(LValue.makeString(vm, token)); }|  BooleanLiteral()                        { push(LValue.makeBoolean(vm, token)); }|  NullLiteral()                        { push(LValue.makeNull(vm, token)); }}void BooleanLiteral() :{}{  "true" |  "false"}void NullLiteral() :{}{  "null"}List Arguments() :{List argList = new ArrayList();}{  "(" [ ArgumentList(argList) ] ")"  { return argList; }}void ArgumentList(List argList) :{}{  Expression() {argList.add(pop().interiorGetValue());}  ( "," Expression() {argList.add(pop().interiorGetValue());} )*}void AllocationExpression() :{List argList; String className;}{  LOOKAHEAD(2)  "new" PrimitiveType() ArrayDimensions()|  "new" className = Name() ( argList = Arguments()                         { push(LValue.makeNewObject(vm, frameGetter, className, argList)); }                           | ArrayDimensions()                         { throw new ParseException("operation not yet supported"); }			   )}/* * The second LOOKAHEAD specification below is to parse to PrimarySuffix * if there is an expression between the "[...]". */void ArrayDimensions() :{}{  ( LOOKAHEAD(2) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )*}

⌨️ 快捷键说明

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