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 */
86 if(*pC
== '"') { pC
++; break; } /* found corresponding quote, stop */
88 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
; }
133 ttype
keyword(char pT
[])
138 } while (strcmp(pT
, keywords
[i
]) < 0 && i
< KEYWORD_COUNT
);
147 char *identifier(char *str
)
153 int int_val(char pT
[])
163 void token_print(char *s
, ptoken print_spec
)
167 while(i
< space_count
)
176 printf("<%s>\r\n", s
);
179 printf("</%s>\r\n", s
);
182 /* convert '<' and '>' to HTML */
185 printf("<%s> < </%s>\r\n", s
, s
);
186 } else if (*pT
== '>')
188 printf("<%s> > </%s>\r\n", s
, s
);
189 } else if (*pT
== '&')
191 printf("<%s> & </%s>\r\n", s
, s
);
193 printf("<%s> %s </%s>\r\n", s
, pT
, s
);