Sorry for the late reply, I forgot my password.
The thing is I don't think I can use struct for this. I have to keep it with this format sort of.
I did figure some things out. I got it to recognize the multi line comments, it just adds a bunch of new lines and doesn't indent it correctly
Code:
void tokenize(char *line, int length)
{
int start= 0;
int end=0;
static int inComment=0;
for (end=0; end <length; end++){
if ((line[end]=='/' && (line[end+1]=='*'))||inComment) {
//Lex token to start.
if(!inComment){
lex(line, start, end, length, "Token");
}
start=end;
//end++;
while(line[end] != '*' || line[end+1]!= '/') {
end++;
}
if(end>length){
while((line[end] != '*' || line[end+1]!= '/')) {
end++;
}
lex(line, start, end, length, "CommentD");
inComment=1;
return;
}
else if(end+1<length) {
end+=2;
lex(line, start, end, length, "CommentS");
start=end;
end++;
inComment=0;
}
inComment=0;
}
else if (line[end] == '"') //If double qotes then
{
lex(line, start, end, length,"Token");
start=end;
end++;
while(end<length && line[end]!='"')
{
end++;
}
if (end<length){
end++;
lex(line, start, end, length, "String");
start=end;
end--;
}
}
//If sees ' then is a char. end++ to enter char until ' then end++ and lex.
else if (line[end] =='\''){
end++;
while(end<length && line[end]!='\''){
end++;
}
end++;
lex(line, start, end, length, "Char");
start=end;
end--;
}
//while+lex After anything at start/zero has been tokened. It adds to the index, through the characters. Once it finds the double quote it lexes from start=wherever the last token ended to end+zero to get the ending quotes.
else if(isspace(line[end])) {
lex(line, start, end, length, "Token");
start = end;
// printf("%i: ", end);
}
}
}
This is the output I get
CommentS: /* Comment 4 */
CommentD: /*
CommentD: multi
CommentD: line
CommentS: comment */
CommentD: /*
CommentD: multi
CommentD: line
CommentD: comment
CommentS: */
Char: 'c'
CommentD: /*
CommentD: multi
CommentD: line
CommentD: comment
CommentS: */
Token: "string
The gaps between the multi line comment
And the final string is cut off and supposed to be string not token
And I still need to deal with not removing leading spaces when I am incomment