Index: src/Parser/RunParser.cpp
===================================================================
--- src/Parser/RunParser.cpp	(revision cbd1ba8c33d3d1c15174d3e8bd5026da204c3081)
+++ src/Parser/RunParser.cpp	(revision cbd1ba8c33d3d1c15174d3e8bd5026da204c3081)
@@ -0,0 +1,63 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// RunParser.cpp -- External interface to the parser.
+//
+// Author           : Andrew Beach
+// Created On       : Mon Dec 19 11:00:00 2022
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Dec 19 11:15:00 2022
+// Update Count     : 0
+//
+
+#include "RunParser.hpp"
+
+#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
+#include "Parser/TypedefTable.h"            // for TypedefTable
+
+// Variables global to the parsing code.
+LinkageSpec::Spec linkage = LinkageSpec::Cforall;
+TypedefTable typedefTable;
+DeclarationNode * parseTree = nullptr;
+
+void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit ) {
+	extern int yyparse( void );
+	extern FILE * yyin;
+	extern int yylineno;
+
+	// Set global information.
+	::linkage = linkage;
+	yyin = input;
+	yylineno = 1;
+
+	int parseStatus = yyparse();
+	fclose( input );
+	if ( alwaysExit || parseStatus != 0 ) {
+		exit( parseStatus );
+	} // if
+} // parse
+
+void dumpParseTree( std::ostream & out ) {
+	parseTree->printList( out );
+	delete parseTree;
+	parseTree = nullptr;
+}
+
+std::list<Declaration *> buildUnit(void) {
+	std::list<Declaration *> translationUnit;
+	buildList( parseTree, translationUnit );
+
+	delete parseTree;
+	parseTree = nullptr;
+
+	return translationUnit;
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/Parser/RunParser.hpp
===================================================================
--- src/Parser/RunParser.hpp	(revision cbd1ba8c33d3d1c15174d3e8bd5026da204c3081)
+++ src/Parser/RunParser.hpp	(revision cbd1ba8c33d3d1c15174d3e8bd5026da204c3081)
@@ -0,0 +1,43 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// RunParser.hpp -- External interface to the parser.
+//
+// Author           : Andrew Beach
+// Created On       : Mon Dec 19 10:42:00 2022
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Dec 19 11:15:00 2022
+// Update Count     : 0
+//
+
+#pragma once
+
+#include <iosfwd>                           // for ostream
+#include <list>                             // for list
+
+#include "SynTree/LinkageSpec.h"            // for Spec
+class Declaration;
+
+// The Parser does not have an enclosing namespace.
+
+/// Parse the contents of the input file, setting the initial linkage to the
+/// value provided. Results are saved to the internal accumulator.
+/// The input file is closed when complete. Exits instead of returning on
+/// error or if alwaysExit is true.
+void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit = false );
+
+/// Drain the internal accumulator of parsed code and print it to the stream.
+void dumpParseTree( std::ostream & );
+
+/// Drain the internal accumulator of parsed code and build a translation
+/// unit from it.
+std::list<Declaration *> buildUnit(void);
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/Parser/module.mk
===================================================================
--- src/Parser/module.mk	(revision e1d66c84e0c0d91acc25559fd73ab14706eee525)
+++ src/Parser/module.mk	(revision cbd1ba8c33d3d1c15174d3e8bd5026da204c3081)
@@ -30,4 +30,6 @@
        Parser/parserutility.cc \
        Parser/parserutility.h \
+       Parser/RunParser.cpp \
+       Parser/RunParser.hpp \
        Parser/StatementNode.cc \
        Parser/TypeData.cc \
Index: src/main.cc
===================================================================
--- src/main.cc	(revision e1d66c84e0c0d91acc25559fd73ab14706eee525)
+++ src/main.cc	(revision cbd1ba8c33d3d1c15174d3e8bd5026da204c3081)
@@ -59,6 +59,5 @@
 #include "InitTweak/GenInit.h"              // for genInit
 #include "MakeLibCfa.h"                     // for makeLibCfa
-#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
-#include "Parser/TypedefTable.h"            // for TypedefTable
+#include "Parser/RunParser.hpp"             // for buildList, dumpParseTree,...
 #include "ResolvExpr/CandidatePrinter.hpp"  // for printCandidates
 #include "ResolvExpr/Resolver.h"            // for resolve
@@ -109,8 +108,4 @@
 	Stats::Time::StopBlock();
 
-LinkageSpec::Spec linkage = LinkageSpec::Cforall;
-TypedefTable typedefTable;
-DeclarationNode * parseTree = nullptr;					// program parse tree
-
 static bool waiting_for_gdb = false;					// flag to set cfa-cpp to wait for gdb on start
 
@@ -118,5 +113,4 @@
 
 static void parse_cmdline( int argc, char * argv[] );
-static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false );
 static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
 static void dump( ast::TranslationUnit && transUnit, ostream & out = cout );
@@ -301,12 +295,9 @@
 
 		if ( parsep ) {
-			parseTree->printList( cout );
-			delete parseTree;
-			return EXIT_SUCCESS;
-		} // if
-
-		buildList( parseTree, translationUnit );
-		delete parseTree;
-		parseTree = nullptr;
+			dumpParseTree( cout );
+			return EXIT_SUCCESS;
+		} // if
+
+		translationUnit = buildUnit();
 
 		if ( astp ) {
@@ -748,20 +739,4 @@
 } // parse_cmdline
 
-static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit ) {
-	extern int yyparse( void );
-	extern FILE * yyin;
-	extern int yylineno;
-
-	::linkage = linkage;								// set globals
-	yyin = input;
-	yylineno = 1;
-	int parseStatus = yyparse();
-
-	fclose( input );
-	if ( shouldExit || parseStatus != 0 ) {
-		exit( parseStatus );
-	} // if
-} // parse
-
 static bool notPrelude( Declaration * decl ) {
 	return ! LinkageSpec::isBuiltin( decl->get_linkage() );
