11 "boolean","char", "class", "constructor", "do", "else",
12 "false", "field", "function", "if", "int", "let", "method",
13 "null", "return", "static", "this", "true", "var", "void", "while"
16 int has_more_tokens(char *pC
)
26 char *advance(char *pC
, char pT
[])
29 int cont
; /* continue */
30 int in_quote
= 0; /* inside quotes? */
33 /* skip past C++ style comments */
34 if(*pC
== '/' && *(pC
+1) == '/')
36 pC
= strchr(pC
, '\n');
39 /* skip past C style comments */
40 if(*pC
== '/' && *(pC
+1) == '*')
47 /* advance past spaces and newline chars */
49 while((strchr(SPACES
, ch
)) != NULL
)
55 /* determine if more advancement is needed */
56 if(*pC
== '/' && *(pC
+1) == '/') { cont
++; }
57 if(*pC
== '/' && *(pC
+1) == '*') { cont
++; }
61 /* test for symbol - copy to buffer */
63 if(strchr(SYMBOLS
, ch
) != NULL
)
71 /* should be at beginning of token - copy to buffer */
72 cont
= 0; in_quote
= 0;
75 in_quote
++; /* inside quote */
76 pC
++; /* skip quote itself */
81 if(*pC
== '"') { pC
++; break; } /* found corresponding quote, stop */
83 if(((strchr(SPACES
, ch
)) != NULL
) || ((strchr(SYMBOLS
, ch
)) != NULL
))
98 token
token_type(char pT
[])
100 token t
= IDENTIFIER
;
103 /* check token for symbols */
104 if(strchr(SYMBOLS
, pT
[0]) != NULL
) { t
= SYMBOL
; }
106 /* check token for integer constants */
109 if(isdigit(pT
[i
]) == 0)
116 if(j
== 0) { t
= INT_CONST
; }
118 /* check token for keywords */
121 j
= strcmp(keywords
[i
], pT
);
123 } while ((j
!= 0) && (i
< KEYWORD_COUNT
));
125 if(j
== 0) { t
= KEYWORD
; }
130 ttype
keyword(char pT
[])
135 } while (strcmp(pT
, keywords
[i
]) < 0 && i
< KEYWORD_COUNT
);
146 char *identifier(char *str
)
153 int int_val(char pT
[])