Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- options {
- STATIC = false;
- }
- PARSER_BEGIN(Exp_avaliator)
- import java.io.PrintStream ;
- class Exp_avaliator {
- public static void main( String[] args )
- throws ParseException, TokenMgrError, NumberFormatException {
- while (true) {
- try {
- Exp_avaliator parser = new Exp_avaliator( System.in );
- parser.Start( System.out ) ;
- } catch (Exception e) {
- System.out.println("Rejeitado!");
- }
- }
- }
- }
- PARSER_END(Exp_avaliator)
- SKIP : { " " }
- SKIP : { "\n" | "\r" | "\r\n" }
- TOKEN : { < PLUS : "+" > }
- TOKEN : { < MINUS : "-" > }
- TOKEN : { < TIMES : "*" > }
- TOKEN : { < DIVIDE : "/" > }
- TOKEN : { < END : ";" > }
- TOKEN : { < OPEN_PAR : "(" > }
- TOKEN : { < CLOSE_PAR : ")" > }
- TOKEN : { < PREVIOUS : "$" > }
- TOKEN : { < NUMBER : <DIGITS> | <DIGITS> "." <DIGITS> | <DIGITS> "." | "." <DIGITS> > }
- TOKEN : { < #DIGITS : (["0"-"9"])+ > }
- void Start(PrintStream printStream) throws NumberFormatException :
- {}
- {
- (
- Exp()
- <END>
- {
- System.out.println("Aceito!!");
- }
- )*
- <EOF>
- }
- void Exp() throws NumberFormatException :
- {}
- {
- Prim()
- (
- (<PLUS> | <MINUS> | <DIVIDE> | <TIMES>) Prim()
- )*
- }
- void Prim() throws NumberFormatException :
- {}
- {
- <NUMBER> | <OPEN_PAR> Exp() <CLOSE_PAR> | <MINUS> Prim()
- }
Add Comment
Please, Sign In to add comment