Function advance now recognizes C and C++ comments.
[Jack-Compiler.git] / token.c
blob005b59848ab2c1b7417540f05b6909caba522675
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
5 #include "token.h"
7 #define SYMBOLS "{}()[].,;+-*/&|<>=~"
8 #define SPACES "\t\n\r "
10 int has_more_tokens(char *pC)
12 if(*(pC+1) != EOF)
14 return TRUE;
15 } else {
16 return FALSE;
20 char *advance(char *pC)
22 char ch = NULL;
23 /* skip past C++ style comments */
24 if(*pC == '/' && *(pC+1) == '/')
26 while(*pC != '\n' && *pC != EOF)
27 { pC++; }
29 if(*pC == '\n') { pC++; }
31 /* skip past C style comments */
32 if(*pC == '/' && *(pC+1) == '*')
34 while(*(pC+1) != '/')
36 pC++;
38 pC += 2; /* move past end of comment */
41 /* advance past spaces and newline chars */
42 ch = *pC;
43 while((strchr(SPACES, ch)) != NULL)
45 pC++;
46 ch = *pC;
49 return pC;
53 ttype token_type(void)
55 return FALSE;
59 token keyword(void)
61 return KEYWORD;
65 char symbol()
67 return 'z';
71 char *identifier(char *str)
73 str = NULL;
74 return NULL;
78 int int_val()
80 return 0;
84 char *string_val()
86 return NULL;