Advertisement
Guest User

KPLMLM

a guest
Mar 17th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. public void nt_ClassDecl() :
  2. {}
  3. {
  4. LOOKAHEAD(2) <CLASS> <ID> <LBRACE> (nt_FieldDecl())* (nt_MethodDecl())* <RBRACE>
  5. | <CLASS> <ID> <EXTENDS> <ID> <LBRACE> (nt_FieldDecl())*
  6. (nt_MethodDecl())* <RBRACE>
  7. }
  8.  
  9. public void nt_FieldDecl() :
  10. {}
  11. {
  12. nt_Type() <ID> <SEMICOLON>
  13. }
  14.  
  15. public void nt_MethodDecl() :
  16. {}
  17. {
  18. nt_ProcDecl() | nt_FunDecl()
  19. }
  20.  
  21. public void nt_ProcDecl() :
  22. {}
  23. {
  24. <PROC> <ID> <LPAREN> nt_FormalList() <RPAREN> <LBRACE>
  25. (nt_Statement())* <RBRACE>
  26. }
  27.  
  28. public void nt_FunDecl() :
  29. {}
  30. {
  31. <FUN> nt_Type() <ID> <LPAREN> nt_FormalList() <RPAREN>
  32. <LBRACE> (nt_Statement())* <RETURN> nt_Exp() <SEMICOLON>
  33. <RBRACE>
  34. }
  35.  
  36. public void nt_FormalList() :
  37. {}
  38. {
  39. nt_Type() <ID> (nt_FormalRest())*
  40. }
  41.  
  42. public void nt_FormalRest() :
  43. {}
  44. {
  45. <COMMA> nt_Type() <ID>
  46. }
  47.  
  48. public void nt_Type() :
  49. {}
  50. {
  51. <ARRAYOF> <LPAREN> nt_Type() <RPAREN>
  52. | <BOOLEAN>
  53. | <INT>
  54. | <ID>
  55. }
  56.  
  57. public void nt_Statement() :
  58. {}
  59. {
  60. nt_Block()
  61. | LOOKAHEAD(2) nt_Type() <ID> <SEMICOLON>
  62. | LOOKAHEAD(2)nt_Var() <ASSIGN> nt_Exp() <SEMICOLON>
  63. | LOOKAHEAD(3)nt_PrimaryExp() <LSBRACE> nt_Exp() <RSBRACE>
  64. <ASSIGN> nt_Exp()<SEMICOLON>
  65. | <IF> <LPAREN> nt_Exp() <RPAREN> <THEN>
  66. nt_Block() <ELSE> nt_Block()
  67. | <WHILE> <LPAREN> nt_Exp() <RPAREN> <DO> nt_Block()
  68. | <OUTPUT> nt_Exp() <SEMICOLON>
  69. | LOOKAHEAD(3)nt_PrimaryExp() <DOT> <ID> <LPAREN> nt_ExpList()
  70. <RPAREN> <SEMICOLON>
  71. }
  72.  
  73. public void nt_Block() :
  74. {}
  75. {
  76. <LBRACE> (nt_Statement())* <RBRACE>
  77. }
  78.  
  79. public void nt_Exp() :
  80. {}
  81. {
  82. LOOKAHEAD(2) nt_PrimaryExp() nt_Op() nt_PrimaryExp()
  83. | LOOKAHEAD(3) nt_PrimaryExp() <LSBRACE> nt_Exp() <RSBRACE>
  84. | LOOKAHEAD(3) nt_PrimaryExp() <DOT> <LENGTH>
  85. | LOOKAHEAD(3) nt_PrimaryExp() <DOT> <ID> <LPAREN> nt_ExpList()
  86. <RPAREN>
  87. | LOOKAHEAD(3)nt_PrimaryExp()
  88. }
  89.  
  90. public void nt_PrimaryExp() :
  91. {}
  92. {
  93. <INTEGER_LITERAL>
  94. | <TRUE>
  95. | <FALSE>
  96. | nt_Var()
  97. | <SELF>
  98. | LOOKAHEAD(2) <NEW> <ARRAYOF> <LPAREN> nt_Type()
  99. <RPAREN> <LSBRACE> nt_Exp() <RSBRACE>
  100. | LOOKAHEAD(2) <NEW> <OBJECT> <ID> <LPAREN> nt_ExpList() <RPAREN>
  101. | <NOT> nt_PrimaryExp()
  102. | <ISNULL> nt_PrimaryExp()
  103. <LPAREN> nt_Exp() <RPAREN>
  104. }
  105.  
  106. public void nt_Var() :
  107. {}
  108. {
  109. <ID>
  110. }
  111.  
  112. public void nt_ExpList() :
  113. {}
  114. {
  115. nt_Exp() (nt_ExpRest())*
  116. }
  117.  
  118. public void nt_ExpRest() :
  119. {}
  120. {
  121. <COMMA> nt_Exp()
  122. }
  123.  
  124. public void nt_Op() :
  125. {}
  126. {
  127. <AND>
  128. | <LT>
  129. | <ASSIGN>
  130. | <DIV>
  131. | <PLUS>
  132. | <MINUS>
  133. | <MULT>
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement