Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. test1.cxx
  5. Abstract:
  6. Main program to test the lexer
  7. Author:
  8. Shankara Shastry [ShankSh] 08-Jul-1996
  9. ++*/
  10. #include <stdio.h>
  11. #include "lexer.hxx"
  12. #include "sconv.hxx"
  13. static WCHAR *DisplayName[] = {
  14. L"TOKEN_ERROR ",
  15. L"TOKEN_LPARAN ",
  16. L"TOKEN_RPARAN ",
  17. L"TOKEN_OR ",
  18. L"TOKEN_AND ",
  19. L"TOKEN_NOT ",
  20. L"TOKEN_APPORX_EQ",
  21. L"TOKEN_EQ ",
  22. L"TOKEN_LE ",
  23. L"TOKEN_GE ",
  24. L"TOKEN_PRESENT ",
  25. L"TOKEN_ATTRTYPE ",
  26. L"TOKEN_ATTRVAL ",
  27. L"TOKEN_END ",
  28. L"TOKEN_STAR "
  29. };
  30. DECLARE_INFOLEVEL(OleDs)
  31. int
  32. _cdecl main(
  33. int argc,
  34. char **argv
  35. )
  36. {
  37. HRESULT status = NO_ERROR;
  38. LPWSTR pszPattern;
  39. // Check the arguments.
  40. //
  41. if ( argc != 2 )
  42. {
  43. wprintf( L"\nUsage: lt <pattern> \n" );
  44. wprintf( L"\n where: pattern is the string where the tokens have to be recognised\n" );
  45. return -1;
  46. }
  47. if(!(pszPattern = AllocateUnicodeString(argv[1]))) {
  48. fprintf (stderr, "Not enough memory\n");
  49. return (-1);
  50. }
  51. CLexer samplePattern(pszPattern);
  52. LPWSTR lexeme;
  53. DWORD token;
  54. wprintf(L"Token\t\tLexeme\n\n");
  55. samplePattern.GetNextToken(&lexeme, &token);
  56. while (token != TOKEN_END && token != TOKEN_ERROR) {
  57. wprintf(L"%s\t%s\n", DisplayName[token - TOKEN_START], lexeme);
  58. samplePattern.GetNextToken(&lexeme, &token);
  59. }
  60. if(token == TOKEN_ERROR)
  61. wprintf(L"%s\n", DisplayName[token - TOKEN_START]);
  62. FreeUnicodeString(pszPattern);
  63. return (0);
  64. }
  65.