fatal_error (UNKNOWN_LOCATION, "specified file %s is a directory",
filename);
- if ((source_file_size = get_source_size ()) == 0)
- {
- /* The source file is empty. */
- ret = false;
- goto done;
- }
+ source_file_size = get_source_size ();
/* Allocate A68_PARSER (scan_buf), which is an auxiliary buffer used by the
scanner known to be big enough to hold any string contained in the source
/* Include files. */
include_files (TOP_LINE (&A68_JOB));
- done:
if (fclose (FILE_SOURCE_FD (&A68_JOB)) != 0)
gcc_unreachable ();
return ret;
/* Tokenise source file, build initial syntax tree. */
bool
-a68_lexical_analyser (const char *filename)
+a68_lexical_analyser (const char *filename, bool *empty_program)
{
LINE_T *l = NO_LINE, *start_l = NO_LINE;
char *s = NO_TEXT, *start_c = NO_TEXT;
s = STRING (l);
tokenise_source (&root, 0, false, &l, &s, &start_l, &start_c);
+ /* Detemine whether the actual file contents resulted in some token. This is
+ used in order to provide better diagnostics for empty source files or
+ files containing only comments or pragmats. These are not valid Algol 68
+ packets. */
+
+ *empty_program = true;
+ for (NODE_T *p = TOP_NODE (&A68_JOB); p != NO_NODE; FORWARD (p))
+ {
+ LINE_T *l = LINE (INFO (p));
+ if (strcmp (FILENAME (l), "prelude") != 0
+ && strcmp (FILENAME (l), "postlude") != 0)
+ {
+ *empty_program = false;
+ break;
+ }
+ }
+
/* If the source is a prelude packet then we should remove the prelude and
postlude nodes from the token stream. We distinguish these nodes by
location.
/* Tokeniser. */
if (ERROR_COUNT (&A68_JOB) == 0)
{
- bool ok = a68_lexical_analyser (filename);
+ bool empty_program;
+ bool ok = a68_lexical_analyser (filename, &empty_program);
if (!ok)
return;
- /* An empty file is not a valid program. */
- if (TOP_NODE (&A68_JOB) == NO_NODE)
- {
- a68_error (NO_NODE, "file is empty, expected a program");
- return;
- }
+ if (empty_program)
+ a68_error (NO_NODE,
+ "particular program or prelude packet not found in source file");
TREE_LISTING_SAFE (&A68_JOB) = true;
renum = 0;