home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / pgen_2 / expr_lex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-04  |  2.4 KB  |  100 lines

  1. /*    EXPR_LEX.H
  2.     Copyright (C) 1992    Keith L. Robertson    All Rights Reserved
  3.  
  4.     Lexical analyzer for the EXPR expression evaluator.
  5.     Declares token and other constant values, external data, and
  6.     external functions for lexical analysys.
  7. */
  8. #ifndef    EXPR_LEX_H
  9. #define    EXPR_LEX_H
  10.  
  11. #ifndef TYPES_H
  12.  #include <types.h>
  13. #endif
  14.  
  15.  
  16. /************************/
  17. /*      TOKENS    */
  18. /************************/
  19.  
  20. enum    {    EOS,        /* End of input stream */
  21.  
  22.     REAL,    IDENTIFIER,
  23.     COMMA,    SEMICOLON,
  24.     EQUAL,
  25.     OPEN_P,    CLOSE_P,
  26.     PLUS,    MINUS,
  27.     TIMES,    DIVIDE,
  28.     POWER,    QUESTION,
  29.     LIST,
  30.     KILL,
  31.     LISP,
  32.     HELP,
  33. };
  34.  
  35.  
  36. /****************************************/
  37. /*         Helper Functions        */
  38.  
  39. /* Write a string to Standard Output. */
  40. extern VOID    put_string (CSTRING str);
  41.  
  42. /* Convert unsigned short to a string. */
  43. extern STRING    ustoa (USHORT num);
  44.  
  45.  
  46. /****************************************/
  47. /*         Lexical Functions        */
  48.  
  49. /* Print an error message, desc.  'etype' is the type of error. */
  50. /* 'desc' is err msg. */
  51. extern VOID    log_error   (USHORT etype,  CSTRING desc);
  52. extern VOID    log_warning (USHORT etype,  CSTRING desc);
  53. enum    { LEXICAL, SYNTAX, SEMANTIC, FATAL };    /* Types of errors */
  54.  
  55. extern SHORT    ERROR_THRESHOLD;    /* Max # errors before it quits */
  56. extern SHORT    TAB_STOPS;        /* Spaces between tabs */
  57.  
  58.  
  59. /* Initialize lexical analyzer.  Called before any other call. */
  60. extern VOID    init_lexer ();        /* Reads from stdin */
  61.  
  62. /* Get data from input stream. */
  63. extern USHORT    get_token ();
  64. extern UCHAR    get_character ();
  65.  
  66. extern USHORT    last_token;        /* Last token returned by get_token () */
  67.  
  68.  
  69. /****************************************/
  70. /*        Lexical Info        */
  71. /* Used to transfer other lexical information from lexer to semantic actions
  72.    and also to represent symbol attribute information on the parse stack. */
  73.  
  74. typedef struct    {
  75.     USHORT    line;        /* Line number where lexeme began. (NONZERO) */
  76.     USHORT    posn;        /* Position on line. */
  77.  
  78.     USHORT    token;        /* Token of this lexeme. */
  79.     STRING    name;        /* Lexeme string for some tokens. */
  80.  
  81.     /* Which is used and its meaning is between lexer & sem actions. */
  82.     union  {
  83.     SHORT    s;
  84.     LONG    l;
  85.     FLOAT    f;
  86.     VOID*    p;
  87.     }    val;
  88. }    LEX_INFO;
  89.  
  90. extern LEX_INFO        lexeme;
  91.  
  92.  
  93. /*    Operations needed by the parser and semantic actions.    */
  94.  
  95. #define        set_jumped(lex_info,val)    ((lex_info).line = ! val)
  96. #define        was_jumped(lex_info)        ((lex_info).line == 0)
  97.  
  98.  
  99. #endif    /* EXPR_LEX_H */
  100.