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
)
18 if(pC
== NULL
) { return false; }
28 char *advance(char *pC
, char pT
[])
31 int cont
; /* continue */
32 int in_quote
= 0; /* inside quotes? */
35 /* skip past C++ style comments */
36 if(*pC
== '/' && *(pC
+1) == '/')
38 pC
= strchr(pC
, '\n');
41 /* skip past C style comments */
42 if(*pC
== '/' && *(pC
+1) == '*')
47 } while((*pC
!= '/') || (*(pC
-1) != '*'));
51 /* advance past spaces and newline chars */
53 while((strchr(SPACES
, ch
)) != NULL
)
59 /* determine if more advancement is needed */
60 if(*pC
== '/' && *(pC
+1) == '/') { cont
++; }
61 if(*pC
== '/' && *(pC
+1) == '*') { cont
++; }
65 /* test for symbol - copy to buffer */
67 if(strchr(SYMBOLS
, ch
) != NULL
)
75 /* should be at beginning of token - copy to buffer */
76 cont
= 0; in_quote
= 0;
79 in_quote
++; /* inside quote */
80 pC
++; /* skip quote itself */
85 if(*pC
== '"') { pC
++; break; } /* found corresponding quote, stop */
87 if(((strchr(SPACES
, ch
)) != NULL
) || ((strchr(SYMBOLS
, ch
)) != NULL
))
102 token
token_type(char pT
[])
104 token t
= IDENTIFIER
;
107 /* check token for symbols */
108 if(strchr(SYMBOLS
, pT
[0]) != NULL
) { t
= SYMBOL
; }
110 /* check token for integer constants */
113 if(isdigit(pT
[i
]) == 0)
120 if(j
== 0) { t
= INT_CONST
; }
122 /* check token for keywords */
125 j
= strcmp(keywords
[i
], pT
);
127 } while ((j
!= 0) && (i
< KEYWORD_COUNT
));
129 if(j
== 0) { t
= KEYWORD
; }
134 ttype
keyword(char pT
[])
139 } while (strcmp(pT
, keywords
[i
]) < 0 && i
< KEYWORD_COUNT
);
150 char *identifier(char *str
)
157 int int_val(char pT
[])