update
This commit is contained in:
+53
-12
@@ -9,27 +9,39 @@ int start(char* src) {
|
||||
return _STOP_; // stopping the state machine in any other case
|
||||
}
|
||||
|
||||
int getNextCharacter(char* pos) {
|
||||
if (isLetter(*pos)) {
|
||||
return _READ_IDENTIFIER_; // continues to read the identifier
|
||||
}
|
||||
int getNextCharacter(char** ptr_current) {
|
||||
char* pos = *ptr_current;
|
||||
while(isWhiteSpace(*pos)) pos++;
|
||||
if (isLetter(*pos)) return _READ_IDENTIFIER_;
|
||||
if (isNum(*pos)) return _READ_NUM_LIT_;
|
||||
if (isOperator(*pos)) return _READ_OPERATOR_;
|
||||
return _STOP_; // stopping the state machine in any other case
|
||||
}
|
||||
|
||||
int readIdentifier(char* src) {
|
||||
return _STOP_; // placeholder
|
||||
int readIdentifier(char** ptr_current) {
|
||||
char* pos = *ptr_current;
|
||||
printf("%c - Identifier\n", *pos);
|
||||
pos++;
|
||||
*ptr_current = pos;
|
||||
return _GET_NEXT_CHARACTER_;
|
||||
}
|
||||
|
||||
int readNumLit(char* src) {
|
||||
return _STOP_; // placeholder
|
||||
int readNumLit(char** ptr_current) {
|
||||
char* pos = *ptr_current;
|
||||
printf("%c - Number\n", *pos);
|
||||
return _GET_NEXT_CHARACTER_;
|
||||
}
|
||||
|
||||
int readOperator(char* src) {
|
||||
return _STOP_; // placeholder
|
||||
int readOperator(char** ptr_current) {
|
||||
char* pos = *ptr_current;
|
||||
printf("%c - Operator\n", *pos);
|
||||
return _GET_NEXT_CHARACTER_;
|
||||
}
|
||||
|
||||
int readPunctuation(char* src) {
|
||||
return _STOP_; // placeholder
|
||||
int readPunctuation(char** ptr_current) {
|
||||
char* pos = *ptr_current;
|
||||
printf("%c - Punctuation\n", *pos);
|
||||
return _GET_NEXT_CHARACTER_;
|
||||
}
|
||||
|
||||
int isLetter(char in) {
|
||||
@@ -45,3 +57,32 @@ int isLetter(char in) {
|
||||
}
|
||||
return 0; // returning 0 if it's no letter
|
||||
}
|
||||
|
||||
int isWhiteSpace(char in) {
|
||||
if (in == ' ' || in == '\n') return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isNum(char in) {
|
||||
if (in >= '0' && in <= 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isOperator(char in) {
|
||||
switch(in) {
|
||||
case '=':
|
||||
break;
|
||||
case '*':
|
||||
break;
|
||||
case '+':
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int isPunctuation(char in) {
|
||||
if (in == ';') return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user