diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c
index ec16de5348..ca928bd35e 100644
--- a/tools/lemon/lemon.c
+++ b/tools/lemon/lemon.c
@@ -1446,6 +1446,14 @@ static void handle_D_option(char *z){
   *z = 0;
 }
 
+static char *user_templatename = NULL;
+static void handle_T_option(char *z){
+  user_templatename = malloc( lemonStrlen(z)+1 );
+  if( user_templatename==0 ){
+    memory_error();
+  }
+  strcpy(user_templatename, z);
+}
 
 /* The main program.  Parse the command line and do it... */
 int main(argc,argv)
@@ -1464,6 +1472,7 @@ char **argv;
     {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
     {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
     {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
+    {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
     {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
     {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."},
     {OPT_FLAG, "l", (char*)&nolinenosflag, "Do not print #line statements."},
@@ -3147,6 +3156,23 @@ struct lemon *lemp;
   char *cp;
   Boolean tpltnameinbuf;
 
+  /* first, see if user specified a template filename on the command line. */
+  if (user_templatename != 0) {
+    if( access(user_templatename,004)==-1 ){
+      fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
+        user_templatename);
+      lemp->errorcnt++;
+      return 0;
+    }
+    in = fopen(user_templatename,"rb");
+    if( in==0 ){
+      fprintf(stderr,"Can't open the template file \"%s\".\n",user_templatename);
+      lemp->errorcnt++;
+      return 0;
+    }
+    return in;
+  }
+
   cp = strrchr(lemp->filename,'.');
   if( cp ){
     sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename);