More functional Makefile.
[Jack-Compiler.git] / token.h
blobbba8e9570be58ed753784f57c09a06b57ac2a348
1 #ifndef TOKEN_H_
2 #define TOKEN_H_
4 #define KEYWORD_COUNT 21
5 #define SYMBOLS "{}()[].,;+-*/&|<>=~"
6 #define SPACES "\t\n\r "
7 #define BINARY_OP "*+-&/|<>="
8 #define UNARY_OP "-~"
10 extern int space_count;
11 extern char pT[];
13 typedef enum {
14 BOOLEAN, CHAR, CLASS, CONSTRUCTOR, DO, ELSE,
15 FALSE, FIELD, FUNCTION, IF, INT, LET, METHOD,
16 NUL, RETURN, STATIC, THIS, TRUE, VAR, VOID, WHILE
17 } ttype;
19 typedef enum { KEYWORD, SYMBOL, IDENTIFIER, INT_CONST, STRING_CONST } token;
21 typedef enum { OPEN, CLOSE, BOTH } ptoken;
24 * Look at source stream and determine if more tokens are available.
25 * Returns > 0 if more are found and 0 if none found.
27 int has_more_tokens(char *pC);
30 * Move source pointer to next token in source stream.
31 * pC is pointer to code and pT is pointer to an
32 * array of char that contains the token.
33 * Should be called only if has_more_tokens is true.
35 char *advance(char *pC, char pT[]);
38 * Returns type of current token.
40 token token_type(char pT[]);
43 * Returns keyword of current token.
44 * Called only when token_type is KEYWORD.
46 ttype keyword(char pT[]);
49 * Returns character which is the current token.
50 * Called only when token_type is a SYMBOL.
52 char symbol();
55 * Returns identifier which is the current token.
56 * Called only when token_type is IDENTIFIER.
58 char *identifier(char *str);
61 * Returns integer value of the current token.
62 * Called only when token_type is INT_CONST.
64 int int_val(char pT[]);
67 * Returns a pointer to an array of char, without double quotes.
68 * Called only when token_type is STRING_CONST.
70 char *string_val();
73 * Prints opening token to stdout.
74 * Adds number of spaces stored in space_count to beginning of token.
76 void token_print(char *s, ptoken print_spec);
78 #endif