Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. /* Statements */
  2.  
  3. public static boolean statements(){
  4. if( statement() && statements() )
  5. {
  6. return true;
  7. }
  8. if( statements())
  9. return true;
  10.  
  11. return false;
  12. }
  13. public static boolean statement(){
  14. if( simpleStmt() )
  15. {
  16. if(tokens.get(index).equals("$SEMICOLON"))
  17. {
  18. index++;
  19. stack.add(level + " ;");
  20. return true;
  21. }
  22. }
  23. if( statement_return() ) {
  24.  
  25. if (tokens.get(index).equals("$SEMICOLON")) {
  26. index++;
  27. stack.add(level + " ;");
  28. return true;
  29. }
  30. }
  31. if( functionCall() )
  32. {
  33. if(tokens.get(index).equals("$SEMICOLON"))
  34. {
  35. index++;
  36. stack.add(level + " ;");
  37. return true;
  38. }
  39. }
  40. if( controlStmt())
  41. return true;
  42.  
  43.  
  44. return false;
  45. }
  46. public static boolean statement_return() {
  47.  
  48. if(tokens.get(index).equals("$RETURN"))
  49. {
  50. index++;
  51. stack.add(level + " ;");
  52.  
  53. if( expression() ) {
  54.  
  55. return true;
  56. }
  57. // Reikia su return 0 kažką bbž padaryt
  58. }
  59. return false;
  60.  
  61. }
  62. public static boolean functionCall() {
  63.  
  64. if( functionName() ) {
  65. if(tokens.get(index).equals("$LBRACKET1")) {
  66. index++;
  67. stack.add(level + " '('");
  68.  
  69. if (tokens.get(index).equals("$RBRACKET1")) {
  70. index++;
  71. stack.add(level + " ')'");
  72.  
  73. return true;
  74. } else if (callParameters()) {
  75. if (tokens.get(index).equals("$RBRACKET1")) {
  76. index++;
  77. stack.add(level + " ')'");
  78. return true;
  79. }
  80. }
  81. }
  82. }
  83. return false;
  84. }
  85. public static boolean callParameters(){
  86. if( expression() ){
  87. if(tokens.get(index).equals("$COMMA") ){
  88. index++;
  89. stack.add(level + " ','");
  90.  
  91. if( callParameters())
  92. return true;
  93. }
  94. else
  95. return true;
  96. }
  97. return false;
  98. }
  99.  
  100. public static boolean simpleStmt()
  101. {
  102. if( statement_varDeclaration() )
  103. return true;
  104. if( statement_assignment( ))
  105. return true;
  106. if( io() )
  107. return true;
  108.  
  109. return false;
  110. }
  111.  
  112. public static boolean statement_varDeclaration()
  113. {
  114. if( type() )
  115. {
  116. if( variable() )
  117. {
  118. if(tokens.get(index).equals("$SEMICOLON"))
  119. {
  120. index++;
  121. stack.add(level + " ;");
  122. return true;
  123. }
  124. else if(tokens.get(index).equals("$ASSIGNMENT"))
  125. {
  126. index++;
  127. stack.add(level + " '='");
  128.  
  129. if( expression())
  130. {
  131. if(tokens.get(index).equals("$SEMICOLON"))
  132. {
  133. index++;
  134. stack.add(level + " ;");
  135. return true;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. return false;
  142. }
  143.  
  144. public static boolean statement_assignment()
  145. {
  146. if(variable())
  147. {
  148. if( assigment())
  149. {
  150. if( expression())
  151. return true;
  152. }
  153. }
  154. return false;
  155.  
  156. }
  157. public static boolean io()
  158. {
  159. if( input( ))
  160. {
  161. return true;
  162. }
  163. if( output( ))
  164. {
  165. return true;
  166. }
  167. return false;
  168.  
  169. }
  170. public static boolean input(){
  171. if(tokens.get(index).equals("$IN"))
  172. {
  173. index++;
  174. stack.add(level + " 'input'");
  175.  
  176. if( variable() )
  177. return true;
  178.  
  179. }
  180. return false;
  181. }
  182. public static boolean output(){
  183. if(tokens.get(index).equals("$OUT"))
  184. {
  185. index++;
  186. stack.add(level + " 'echo'");
  187.  
  188. if( expression( ))
  189. return true;
  190. }
  191. return false;
  192. }
  193. }
  194.  
  195.  
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement