Skip to content

Instantly share code, notes, and snippets.

@Swoorup
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swoorup/28d90d10c0b56514e837 to your computer and use it in GitHub Desktop.
Save Swoorup/28d90d10c0b56514e837 to your computer and use it in GitHub Desktop.
Scan Input, build lexical tokens
// keep getline in a loop in case interruption occurs
int again = 1;
while (again) {
again = 0;
printf("%s", getprompt());
linebuffer = NULL;
len = 0;
ssize_t nread = getline(&linebuffer, &len, stdin);
if (nread <= 0 && errno == EINTR) {
again = 1; // signal interruption, read again
clearerr(stdin); // clear the error
}
}
// user pressed ctrl-D
if (feof(stdin)) {
exit(0);
return 0;
}
// lexically analyze and build a list of tokens
lexer_build(linebuffer, len, &lexerbuf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment