Skip to content

Commit

Permalink
Excluding new line characters from strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ckirsch committed Aug 17, 2016
1 parent d8c8309 commit 2f93229
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions selfie.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,16 @@ void syntaxErrorCharacter(int character);

void getCharacter();

int isCharacterNewLine();
int isCharacterWhitespace();

int findNextCharacter();

int isCharacterLetter();
int isCharacterDigit();
int isCharacterLetterOrDigitOrUnderscore();
int isNotDoubleQuoteOrEOF();
int isCharacterNotDoubleQuoteOrNewLineOrEOF();

int identifierStringMatch(int stringIndex);
int identifierOrKeyword();

Expand Down Expand Up @@ -1712,17 +1716,22 @@ void getCharacter() {
}
}

int isCharacterNewLine() {
if (character == CHAR_LF)
return 1;
else if (character == CHAR_CR)
return 1;
else
return 0;
}

int isCharacterWhitespace() {
if (character == CHAR_SPACE)
return 1;
else if (character == CHAR_TAB)
return 1;
else if (character == CHAR_LF)
return 1;
else if (character == CHAR_CR)
return 1;
else
return 0;
return isCharacterNewLine();
}

int findNextCharacter() {
Expand All @@ -1737,11 +1746,8 @@ int findNextCharacter() {
if (inComment) {
getCharacter();

if (character == CHAR_LF)
// comments end with line feed
inComment = 0;
else if (character == CHAR_CR)
// and carriage return
if (isCharacterNewLine())
// comments end with new line
inComment = 0;
else if (character == CHAR_EOF)
return character;
Expand All @@ -1752,9 +1758,7 @@ int findNextCharacter() {

} else if (isCharacterWhitespace()) {
// keep track of line numbers for error reporting and code annotation
if (character == CHAR_LF)
lineNumber = lineNumber + 1;
else if (character == CHAR_CR)
if (isCharacterNewLine())
lineNumber = lineNumber + 1;

// count line feed and carriage return as ignored characters
Expand Down Expand Up @@ -1825,9 +1829,11 @@ int isCharacterLetterOrDigitOrUnderscore() {
return 0;
}

int isNotDoubleQuoteOrEOF() {
int isCharacterNotDoubleQuoteOrNewLineOrEOF() {
if (character == CHAR_DOUBLEQUOTE)
return 0;
else if (isCharacterNewLine())
return 0;
else if (character == CHAR_EOF)
return 0;
else
Expand Down Expand Up @@ -1964,7 +1970,7 @@ void getSymbol() {

i = 0;

while (isNotDoubleQuoteOrEOF()) {
while (isCharacterNotDoubleQuoteOrNewLineOrEOF()) {
if (i >= maxStringLength) {
syntaxErrorMessage((int*) "string too long");

Expand Down

0 comments on commit 2f93229

Please sign in to comment.