10 "boolean","char", "class", "constructor", "do", "else",
11 "false", "field", "function", "if", "int", "let", "method",
12 "null", "return", "static", "this", "true", "var", "void", "while"
15 int has_more_tokens(char *pC
)
25 char *advance(char *pC
, char pT
[])
28 int cont
; /* continue */
29 int in_quote
= 0; /* inside quotes? */
32 /* skip past C++ style comments */
33 if(*pC
== '/' && *(pC
+1) == '/')
35 pC
= strchr(pC
, '\n');
38 /* skip past C style comments */
39 if(*pC
== '/' && *(pC
+1) == '*')
46 /* advance past spaces and newline chars */
48 while((strchr(SPACES
, ch
)) != NULL
)
54 /* determine if more advancement is needed */
55 if(*pC
== '/' && *(pC
+1) == '/') { cont
++; }
56 if(*pC
== '/' && *(pC
+1) == '*') { cont
++; }
60 /* test for symbol - copy to buffer */
62 if(strchr(SYMBOLS
, ch
) != NULL
)
70 /* should be at beginning of token - copy to buffer */
71 cont
= 0; in_quote
= 0;
74 in_quote
++; /* inside quote */
75 pC
++; /* skip quote itself */
80 if(*pC
== '"') { pC
++; break; } /* found corresponding quote, stop */
82 if(((strchr(SPACES
, ch
)) != NULL
) || ((strchr(SYMBOLS
, ch
)) != NULL
))
97 token
token_type(char pT
[])
102 /* check token for symbols */
103 if(strchr(SYMBOLS
, pT
[0]) != NULL
) { t
= SYMBOL
; }
105 /* check token for integer constants */
108 if(isdigit(pT
[i
]) == 0)
115 if(j
== 0) { t
= INT_CONST
; }
117 /* check token for keywords */
120 j
= strcmp(keywords
[i
], pT
);
122 } while ((j
!= 0) && (i
< KEYWORD_COUNT
));
124 if(j
== 0) { t
= KEYWORD
; }
129 ttype
keyword(char pT
[])
134 } while (strcmp(pT
, keywords
[i
]) < 0 && i
< KEYWORD_COUNT
);
145 char *identifier(char *str
)
152 int int_val(char pT
[])