Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Tiny BASIC
  3.  * Token Handling Header
  4.  *
  5.  * Copyright (C) Damian Walker 2019
  6.  * Created: 15-Aug-2019
  7.  */
  8.  
  9.  
  10. #ifndef __TOKEN_H__
  11. #define __TOKEN_H__
  12.  
  13.  
  14. /*
  15.  * Type Declarations
  16.  */
  17.  
  18.  
  19. /* token classes */
  20. typedef enum
  21.   {
  22.    TOKEN_NONE, /* no token has yet been identified */
  23.    TOKEN_EOF, /* end of file */
  24.    TOKEN_EOL, /* end of line */
  25.    TOKEN_WORD, /* an identifier or keyword - token to be removed */
  26.    TOKEN_NUMBER, /* a numeric constant */
  27.    TOKEN_SYMBOL, /* a legal symbol - token to be removed */
  28.    TOKEN_STRING, /* a string constant */
  29.    TOKEN_LET, /* the LET keyword */
  30.    TOKEN_IF, /* the IF keyword */
  31.    TOKEN_THEN, /* the THEN keyword */
  32.    TOKEN_GOTO, /* the GOTO keyword */
  33.    TOKEN_GOSUB, /* the GOSUB keyword */
  34.    TOKEN_RETURN, /* the RETURN keyword */
  35.    TOKEN_END, /* the END keyword */
  36.    TOKEN_PRINT, /* the PRINT keyword */
  37.    TOKEN_INPUT, /* the INPUT keyword */
  38.    TOKEN_REM, /* the REM keyword */
  39.    TOKEN_VARIABLE, /* a single letter A..Z */
  40.    TOKEN_PLUS, /* addition or unary positive */
  41.    TOKEN_MINUS, /* subtraction or unary negative */
  42.    TOKEN_MULTIPLY, /* multiplication */
  43.    TOKEN_DIVIDE, /* division */
  44.    TOKEN_LEFT_PARENTHESIS, /* open parenthesis */
  45.    TOKEN_RIGHT_PARENTHESIS, /* close parenthesis */
  46.    TOKEN_EQUAL, /* = */
  47.    TOKEN_UNEQUAL, /* <> or >< */
  48.    TOKEN_LESSTHAN, /* < */
  49.    TOKEN_LESSOREQUAL, /* <= */
  50.    TOKEN_GREATERTHAN, /* > */
  51.    TOKEN_GREATEROREQUAL, /* >= */
  52.    TOKEN_COMMA, /* comma separator */
  53.    TOKEN_ILLEGAL /* unrecognised characters */
  54.   } TokenClass;
  55.  
  56. /* token structure */
  57. typedef struct token Token;
  58. typedef struct token
  59. {
  60.   void *data; /* private data */
  61.   TokenClass (*get_class) (Token *);
  62.   int (*get_line) (Token *);
  63.   int (*get_pos) (Token *);
  64.   char *(*get_content) (Token *);
  65.   void (*set_class) (Token *, TokenClass);
  66.   void (*set_line_pos) (Token *, int, int);
  67.   void (*set_content) (Token *, char *);
  68.   void (*initialise) (Token *, TokenClass, int, int, char *);
  69.   void (*destroy) (Token *); /* destructor */
  70. } Token;
  71.  
  72.  
  73. /*
  74.  * Function Declarations
  75.  */
  76.  
  77.  
  78. /*
  79.  * Token constructor without values to initialise
  80.  * returns:
  81.  *   Token*   the created token
  82.  */
  83. Token *new_Token (void);
  84.  
  85. /*
  86.  * Token constructor with values to initialise
  87.  * params:
  88.  *   TokenClass   class     class of token to initialise
  89.  *   int          line      line on which the token occurred
  90.  *   int          pos       character position on which the token occurred
  91.  *   char*        content   the textual content of the token
  92.  * returns:
  93.  *   Token*                 the created token
  94.  */
  95. Token *new_Token_init (TokenClass class, int line, int pos, char *content);
  96.  
  97.  
  98. #endif
  99.