daily pastebin goal
13%
SHARE
TWEET

Untitled

a guest May 16th, 2018 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * JavaCC template file created by SF JavaCC plugin 1.5.17+ wizard for JavaCC 1.5.0+
  3.  */
  4. options
  5. {
  6.   JDK_VERSION = "1.5";
  7.   static = true;
  8. }
  9.  
  10. PARSER_BEGIN(eg1)
  11.  
  12. public class eg1
  13. {
  14.   public static void main(String args []) throws ParseException
  15.   {
  16.     eg1 parser = new eg1(System.in);
  17.     while (true)
  18.     {
  19.       try
  20.       {
  21.       System.out.print("Write a valid variable: ");
  22.       eg1.input();
  23.       System.out.println("Variable is valid.");
  24.     }catch(Exception e)
  25.     {
  26.       System.out.println("Variable not valid");
  27.     }
  28.      
  29.     }
  30.   }
  31. }
  32.  
  33. PARSER_END(eg1)
  34.  
  35. SKIP :
  36. {
  37.   " "
  38. | "\r"
  39. | "\t"
  40. | "\n"
  41. }
  42.  
  43. TOKEN : /* OPERATORS */
  44. {
  45.   < PLUS : "+" >
  46. | < MINUS : "-" >
  47. | < MULTIPLY : "*" >
  48. | < DIVIDE : "/" >
  49. | < EQUALS : "=" >
  50. | < TYPE : "BYTE" | "SHORT" | "INT" | "LONG" | "FLOAT" | "DOUBLE" | "BOOLEAN" | "CHAR" >
  51. | < EOS : ";" >
  52.  
  53.  
  54. }
  55.  
  56. TOKEN :
  57. {
  58.     < IDENTIFIER : ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","0"-"9","_"] )* >
  59. }
  60. void input() :
  61. {
  62. Token t1; String name;
  63. Token t2; String type;
  64. }
  65. {
  66.  t1=< TYPE >
  67.  {type=t1.image.toString();}
  68.  {System.out.println("type="+type); }
  69.  t2=<IDENTIFIER>
  70.  < EOS >
  71.  {name=t2.image.toString();}
  72.  {System.out.println("variable name="+name); }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top