Guest User

Untitled

a guest
Feb 26th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. options {
  2. STATIC = false;
  3. }
  4.  
  5. PARSER_BEGIN(Exp_avaliator)
  6. import java.io.PrintStream ;
  7. class Exp_avaliator {
  8. public static void main( String[] args )
  9. throws ParseException, TokenMgrError, NumberFormatException {
  10.  
  11. while (true) {
  12. try {
  13. Exp_avaliator parser = new Exp_avaliator( System.in );
  14.  
  15. parser.Start( System.out ) ;
  16. } catch (Exception e) {
  17. System.out.println("Rejeitado!");
  18. }
  19. }
  20.  
  21. }
  22. }
  23. PARSER_END(Exp_avaliator)
  24.  
  25. SKIP : { " " }
  26. SKIP : { "\n" | "\r" | "\r\n" }
  27. TOKEN : { < PLUS : "+" > }
  28. TOKEN : { < MINUS : "-" > }
  29. TOKEN : { < TIMES : "*" > }
  30. TOKEN : { < DIVIDE : "/" > }
  31. TOKEN : { < END : ";" > }
  32. TOKEN : { < OPEN_PAR : "(" > }
  33. TOKEN : { < CLOSE_PAR : ")" > }
  34. TOKEN : { < PREVIOUS : "$" > }
  35.  
  36. TOKEN : { < NUMBER : <DIGITS> | <DIGITS> "." <DIGITS> | <DIGITS> "." | "." <DIGITS> > }
  37. TOKEN : { < #DIGITS : (["0"-"9"])+ > }
  38.  
  39. void Start(PrintStream printStream) throws NumberFormatException :
  40. {}
  41. {
  42. (
  43. Exp()
  44. <END>
  45. {
  46. System.out.println("Aceito!!");
  47. }
  48. )*
  49. <EOF>
  50. }
  51.  
  52. void Exp() throws NumberFormatException :
  53. {}
  54. {
  55. Prim()
  56. (
  57. (<PLUS> | <MINUS> | <DIVIDE> | <TIMES>) Prim()
  58. )*
  59. }
  60.  
  61. void Prim() throws NumberFormatException :
  62. {}
  63. {
  64. <NUMBER> | <OPEN_PAR> Exp() <CLOSE_PAR> | <MINUS> Prim()
  65. }
Add Comment
Please, Sign In to add comment