parse.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * PROGRAM: Language Preprocessor
  3. * MODULE: parse.h
  4. * DESCRIPTION: Common parser definitions
  5. *
  6. * The contents of this file are subject to the Interbase Public
  7. * License Version 1.0 (the "License"); you may not use this file
  8. * except in compliance with the License. You may obtain a copy
  9. * of the License at http://www.Inprise.com/IPL.html
  10. *
  11. * Software distributed under the License is distributed on an
  12. * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  13. * or implied. See the License for the specific language governing
  14. * rights and limitations under the License.
  15. *
  16. * The Original Code was created by Inprise Corporation
  17. * and its predecessors. Portions created by Inprise Corporation are
  18. * Copyright (C) Inprise Corporation.
  19. *
  20. * All Rights Reserved.
  21. * Contributor(s): ______________________________________.
  22. */
  23. #ifndef GPRE_PARSE_H
  24. #define GPRE_PARSE_H
  25. #include "../gpre/words.h"
  26. #include "../gpre/gpre.h"
  27. // Token block, used to hold a lexical token.
  28. enum tok_t {
  29. tok_ident,
  30. tok_number,
  31. tok_sglquoted,
  32. tok_punct,
  33. tok_introducer,
  34. tok_dblquoted
  35. };
  36. struct tok
  37. {
  38. tok_t tok_type; // type of token
  39. gpre_sym* tok_symbol; // hash block if recognized
  40. kwwords_t tok_keyword; // keyword number, if recognized
  41. SLONG tok_position; // byte number in input stream
  42. USHORT tok_length;
  43. USHORT tok_white_space;
  44. SCHAR tok_string[MAX_SYM_SIZE];
  45. bool tok_first; // is it the first token in a statement?
  46. gpre_sym* tok_charset; // Character set of token
  47. };
  48. const size_t TOK_LEN = sizeof(tok);
  49. // CVC: This function doesn't unescape embedded quotes.
  50. inline void strip_quotes(tok& tkn)
  51. {
  52. int ij;
  53. for (ij = 1; ij < tkn.tok_length - 1; ij++)
  54. tkn.tok_string[ij - 1] = tkn.tok_string[ij];
  55. --ij;
  56. tkn.tok_string[ij] = 0;
  57. tkn.tok_length = ij;
  58. }
  59. inline bool isQuoted(const int typ)
  60. {
  61. return (typ == tok_sglquoted || typ == tok_dblquoted);
  62. }
  63. #endif // GPRE_PARSE_H