Parsing Expressions in Java

By Sasha Gontmakher and Ilan Horn

Dr. Dobb's Journal January 1999

Expression        : Term TermOp ;

TermOp            : Plus Term TermOp
                  | Hyphen Term TermOp
                  | ;
                  
Term              : Factor FactorOp ;

FactorOp          : Asterisk Factor FactorOp
                  | Slash Factor FactorOp
                  | ;
                  
Factor            : Primary PrimaryOp ;

PrimaryOp         : OpenParen EList CloseParen PrimaryOp
                  | ;
                  
Primary           : Ident
                  | NumericLiteral
                  | OpenParen Expression CloseParen
                  | SignedExpression ;
                  
IntExpression     : Expression ;

Selector          : Ident ;

SignedExpression  : Hyphen Primary
                  | Plus Primary ;
                  
EList             : Expression MoreEList 
                  | ;
                  
MoreEList         : Comma Expression MoreEList
                  | ;
                  
NumericLiteral    : IntLiteral 
                  | FloatLiteral ;

Figure 1: Typical grammar.

Back to Article


Copyright © 1999, Dr. Dobb's Journal