}
switch (c) {
- case 0:
+ case '\n':
return 0;
case ' ':
case '\t':
case '\r':
- case '\n':
lexptr++;
goto retry;
/* Parse STRING as an expression, and complain if this fails
to use up all of the contents of STRING. */
+/* STRING may contain '\0' bytes; it is terminated by the first '\n'
+ outside a string constant, so that we can diagnose '\0' properly. */
/* We do not support C comments. They should be removed before
this function is called. */
if (yyparse ())
return 0; /* actually this is never reached
the way things stand. */
- if (*lexptr)
+ if (*lexptr != '\n')
error ("Junk after end of expression.");
return expression_value; /* set by yyparse () */
for (;;) {
printf ("enter expression: ");
n = 0;
- while ((buf[n] = getchar ()) != '\n' && buf[n] != EOF)
+ while ((buf[n] = c = getchar ()) != '\n' && c != EOF)
n++;
- if (buf[n] == EOF)
+ if (c == EOF)
break;
- buf[n] = '\0';
printf ("parser returned %ld\n", parse_c_expression (buf));
}