While statements implemented and do statements updated.
[Jack-Compiler.git] / token.h
blob0ebcb3cd247651cd68ae1ea2ca10054a3f1f3c76
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 typedef enum {
11 BOOLEAN, CHAR, CLASS, CONSTRUCTOR, DO, ELSE,
12 FALSE, FIELD, FUNCTION, IF, INT, LET, METHOD,
13 NUL, RETURN, STATIC, THIS, TRUE, VAR, VOID, WHILE
14 } ttype;
16 typedef enum { KEYWORD, SYMBOL, IDENTIFIER, INT_CONST, STRING_CONST } token;
19 * Look at source stream and determine if more tokens are available.
20 * Returns > 0 if more are found and 0 if none found.
22 int has_more_tokens(char *pC);
25 * Move source pointer to next token in source stream.
26 * pC is pointer to code and pT is pointer to an
27 * array of char that contains the token.
28 * Should be called only if has_more_tokens is true.
30 char *advance(char *pC, char pT[]);
33 * Returns type of current token.
35 token token_type(char pT[]);
38 * Returns keyword of current token.
39 * Called only when token_type is KEYWORD.
41 ttype keyword(char pT[]);
44 * Returns character which is the current token.
45 * Called only when token_type is a SYMBOL.
47 char symbol();
50 * Returns identifier which is the current token.
51 * Called only when token_type is IDENTIFIER.
53 char *identifier(char *str);
56 * Returns integer value of the current token.
57 * Called only when token_type is INT_CONST.
59 int int_val(char pT[]);
62 * Returns a pointer to an array of char, without double quotes.
63 * Called only when token_type is STRING_CONST.
65 char *string_val();
67 #endif