Ablstd.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. //***************************************************************************
  5. //
  6. // ABLSTD.CPP
  7. //
  8. //***************************************************************************
  9. #include <stdio.h>
  10. #ifndef ABLGEN_H
  11. #include "ablgen.h"
  12. #endif
  13. #ifndef ABLERR_H
  14. #include "ablerr.h"
  15. #endif
  16. #ifndef ABLSCAN_H
  17. #include "ablscan.h"
  18. #endif
  19. #ifndef ABLSYMT_H
  20. #include "ablsymt.h"
  21. #endif
  22. #ifndef ABLPARSE_H
  23. #include "ablparse.h"
  24. #endif
  25. //***************************************************************************
  26. extern TokenCodeType curToken;
  27. extern char wordString[];
  28. extern TokenCodeType followParmList[];
  29. extern TokenCodeType statementEndList[];
  30. extern SymTableNodePtr symTableDisplay[];
  31. extern long level;
  32. extern TypePtr IntegerTypePtr;
  33. extern TypePtr CharTypePtr;
  34. extern TypePtr RealTypePtr;
  35. extern TypePtr BooleanTypePtr;
  36. extern Type DummyType;
  37. extern SymTableNodePtr CurRoutineIdPtr;
  38. bool EnterStateSymbol = false;
  39. //***************************************************************************
  40. // STANDARD ROUTINE PARSING FUNCTIONS
  41. //***************************************************************************
  42. void stdReturn (void) {
  43. // RETURN function
  44. //
  45. // PARAMS: <same as function return type>
  46. //
  47. // RETURN: NONE
  48. if (curToken == TKN_LPAREN) {
  49. getToken();
  50. TypePtr paramType = expression();
  51. if (paramType != CurRoutineIdPtr->typePtr)
  52. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  53. ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN);
  54. }
  55. else if (CurRoutineIdPtr->typePtr != NULL)
  56. syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS);
  57. }
  58. //***************************************************************************
  59. void stdPrint (void) {
  60. // PRINT function:
  61. //
  62. // PARAMS: integer or real or string
  63. //
  64. // RETURN: NONE
  65. if (curToken == TKN_LPAREN)
  66. getToken();
  67. else
  68. syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS);
  69. TypePtr paramType = expression();
  70. if ((paramType != IntegerTypePtr) &&
  71. (paramType != RealTypePtr) &&
  72. (paramType != CharTypePtr) &&
  73. ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != CharTypePtr)))
  74. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  75. ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN);
  76. }
  77. //***************************************************************************
  78. TypePtr stdConcat (void) {
  79. // PRINT function:
  80. //
  81. // PARAMS: char array
  82. //
  83. // integer, real or char array
  84. //
  85. // RETURN: integer (resulting length, not including NULL)
  86. if (curToken == TKN_LPAREN)
  87. getToken();
  88. else
  89. syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS);
  90. TypePtr paramType = expression();
  91. if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != CharTypePtr))
  92. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  93. ifTokenGetElseError(TKN_COMMA, ABL_ERR_SYNTAX_MISSING_COMMA);
  94. paramType = expression();
  95. if ((paramType != IntegerTypePtr) &&
  96. (paramType != RealTypePtr) &&
  97. (paramType != CharTypePtr) &&
  98. (paramType != BooleanTypePtr) &&
  99. ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != CharTypePtr)))
  100. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  101. ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN);
  102. return(IntegerTypePtr);
  103. }
  104. //***************************************************************************
  105. TypePtr stdGetStateHandle (void) {
  106. if (curToken == TKN_LPAREN)
  107. getToken();
  108. else
  109. syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS);
  110. EnterStateSymbol = true;
  111. TypePtr paramType = expression();
  112. EnterStateSymbol = false;
  113. if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != CharTypePtr))
  114. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  115. ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN);
  116. return(IntegerTypePtr);
  117. }
  118. //***************************************************************************
  119. TypePtr standardRoutineCall (SymTableNodePtr routineIdPtr) {
  120. long key = routineIdPtr->defn.info.routine.key;
  121. long numParams = FunctionInfoTable[key].numParams;
  122. switch (key) {
  123. case RTN_RETURN:
  124. stdReturn();
  125. return(NULL);
  126. case RTN_PRINT:
  127. stdPrint();
  128. return(NULL);
  129. case RTN_CONCAT:
  130. return(stdConcat());
  131. case RTN_GET_STATE_HANDLE:
  132. return(stdGetStateHandle());
  133. default:
  134. if (key >= NumStandardFunctions)
  135. syntaxError(ABL_ERR_SYNTAX_UNEXPECTED_TOKEN);
  136. if (numParams == 0) {
  137. if (curToken == TKN_LPAREN)
  138. syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS);
  139. }
  140. else {
  141. if (curToken == TKN_LPAREN)
  142. getToken();
  143. else
  144. syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS);
  145. for (long i = 0; i < numParams; i++) {
  146. TypePtr paramType = expression();
  147. switch (FunctionInfoTable[key].params[i]) {
  148. case PARAM_TYPE_ANYTHING:
  149. break;
  150. case PARAM_TYPE_CHAR:
  151. if (paramType != CharTypePtr)
  152. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  153. break;
  154. case PARAM_TYPE_INTEGER:
  155. if (paramType != IntegerTypePtr)
  156. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  157. break;
  158. case PARAM_TYPE_REAL:
  159. if (paramType != RealTypePtr)
  160. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  161. break;
  162. case PARAM_TYPE_BOOLEAN:
  163. if (paramType != BooleanTypePtr)
  164. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  165. break;
  166. case PARAM_TYPE_INTEGER_REAL:
  167. if ((paramType != IntegerTypePtr) && (paramType != RealTypePtr))
  168. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  169. break;
  170. case PARAM_TYPE_CHAR_ARRAY:
  171. if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != CharTypePtr))
  172. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  173. break;
  174. case PARAM_TYPE_INTEGER_ARRAY:
  175. if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != IntegerTypePtr))
  176. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  177. break;
  178. case PARAM_TYPE_REAL_ARRAY:
  179. if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != RealTypePtr))
  180. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  181. break;
  182. case PARAM_TYPE_BOOLEAN_ARRAY:
  183. if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != BooleanTypePtr))
  184. syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES);
  185. break;
  186. }
  187. if (i == (numParams - 1))
  188. ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN);
  189. else
  190. ifTokenGetElseError(TKN_COMMA, ABL_ERR_SYNTAX_MISSING_COMMA);
  191. }
  192. }
  193. switch (FunctionInfoTable[key].returnType) {
  194. case RETURN_TYPE_NONE:
  195. return(NULL);
  196. case RETURN_TYPE_INTEGER:
  197. return(IntegerTypePtr);
  198. case RETURN_TYPE_REAL:
  199. return(RealTypePtr);
  200. case RETURN_TYPE_BOOLEAN:
  201. return(BooleanTypePtr);
  202. }
  203. }
  204. return(NULL);
  205. }
  206. //***************************************************************************