Index: configure.in
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/configure.in,v
retrieving revision 1.151.2.4.2.6
diff -u -r1.151.2.4.2.6 configure.in
--- configure.in	2002/08/24 04:52:07	1.151.2.4.2.6
+++ configure.in	2002/08/29 05:34:36
@@ -351,6 +351,7 @@
 with_widgets=''
 with_dialogs=''
 with_file_coding=''
+with_syntax_tables=''
 cpp='' cppflags='' libs='' ldflags=''
 extra_includes=''
 dynamic=''
@@ -380,6 +381,8 @@
 with_dragndrop="no"
 dnl Too annoying, even if mandated by IPv6 (and I'm not even sure of that)
 with_ipv6_cname="no"
+dnl Too slow, way too slow.
+with_syntax_tables="no"
 
 dnl ------------------
 dnl Options Processing
@@ -492,6 +495,7 @@
 	with_i18n3	| \
 	with_mule	| \
 	with_file_coding| \
+	with_syntax_tables| \
 	with_canna	| \
 	with_wnn	| \
 	with_wnn6	| \
@@ -4828,6 +4832,7 @@
 test "$use_union_type"     = "yes" && AC_DEFINE(USE_UNION_TYPE)
 test "$pdump"              = "yes" && AC_DEFINE(PDUMP)
 test "$with_ipv6_cname"    = "yes" && AC_DEFINE(IPV6_CANONICALIZE)
+test "$with_syntax_tables"    = "yes" && AC_DEFINE(SYNTAX_TABLES)
 
 dnl -------------------------------
 dnl Report on what we decided to do
@@ -5042,6 +5047,7 @@
 test "$with_tooltalk" = yes && echo "  Compiling in support for ToolTalk."
 test "$with_workshop" = yes && echo "  Compiling in support for Sun WorkShop."
 test "$with_socks" = yes && echo "  Compiling in support for SOCKS."
+test "$with_syntax_tables" = yes && echo "  Compiling in support for syntax tables."
 test "$with_dnet" = yes && echo "  Compiling in support for DNET."
 test "$with_modules" = "yes" && echo "  Compiling in support for dynamic shared object modules."
 test "$use_union_type" = yes && echo "  Using the union type for Lisp_Objects."
Index: lisp/font-lock.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lisp/font-lock.el,v
retrieving revision 1.13.2.2.2.1
diff -u -r1.13.2.2.2.1 font-lock.el
--- lisp/font-lock.el	2002/08/24 04:46:58	1.13.2.2.2.1
+++ lisp/font-lock.el	2002/08/29 05:34:44
@@ -1319,6 +1319,59 @@
     ;; in add-log, but I think this encompasses more modes.
     (string-match "lisp\\|scheme" (symbol-name mode))))
 
+(defun font-lock-fontify-syntactically-region (start end &optional loudly)
+  (if (boundp 'lookup-syntax-properties)
+      (font-lock-fontify-syntactically-region-1 start end loudly)
+    (font-lock-fontify-syntactically-region-2 start end loudly)))
+
+;; This is the original XEmacs version
+(defun font-lock-fontify-syntactically-region-1 (start end &optional loudly)
+  "Put proper face on each string and comment between START and END.
+START should be at the beginning of a line."
+  (if font-lock-keywords-only
+      nil
+    (when (and font-lock-verbose
+	       (>= (- end start) font-lock-message-threshold))
+      (progress-feedback-with-label 'font-lock
+				    "Fontifying %s... (syntactically)" 5
+				    (buffer-name)))
+    (font-lock-unfontify-region start end loudly)
+    (goto-char start)
+    (if (> end (point-max)) (setq end (point-max)))
+    (let ((lisp-like (font-lock-lisp-like major-mode)))
+      (syntactically-sectionize
+       #'(lambda (s e context depth)
+	   (let (face)
+	     (cond ((eq context 'string)
+		    (setq face
+			  ;; #### It would be nice if we handled
+			  ;; Python and other non-Lisp languages with
+			  ;; docstrings correctly.
+			  (if (and lisp-like (= depth 1))
+			      ;; really we should only use this if
+			      ;;  in position 3 depth 1, but that's
+			      ;;  too expensive to compute.
+			      'font-lock-doc-string-face
+			    'font-lock-string-face)))
+		   ((or (eq context 'comment)
+			(eq context 'block-comment))
+		    (setq face 'font-lock-comment-face)
+;		 ;; Don't fontify whitespace at the beginning of lines;
+;		 ;;  otherwise comment blocks may not line up with code.
+;		 ;; (This is sometimes a good idea, sometimes not; in any
+;		 ;; event it should be in C for speed --jwz)
+;		 (save-excursion
+;		     (goto-char s)
+;		     (while (prog1 (search-forward "\n" (1- e) 'move)
+;			      (setq face 'font-lock-comment-face)
+;			      (setq e (point)))
+;		       (skip-chars-forward " \t\n")
+;		       (setq s (point)))
+		   ))
+	     (font-lock-set-face s e face)))
+       start end)
+      )))
+
 ;; fontify-syntactically-region used to use syntactically-sectionize, which
 ;; was supposedly much faster than the FSF version because it was written in
 ;; C. However, the FSF version uses parse-partial-sexp, which is also
@@ -1326,7 +1379,7 @@
 ;; syntactically-sectionize code to be slower overall. So here's the FSF
 ;; version, modified to support font-lock-doc-string-face.
 ;; -- mct 2000-12-29
-(defun font-lock-fontify-syntactically-region (start end &optional loudly)
+(defun font-lock-fontify-syntactically-region-2 (start end &optional loudly)
   "Put proper face on each string and comment between START and END.
 START should be at the beginning of a line."
   (if font-lock-keywords-only
Index: src/config.h.in
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/config.h.in,v
retrieving revision 1.61.2.1.4.1
diff -u -r1.61.2.1.4.1 config.h.in
--- src/config.h.in	2002/04/27 22:34:10	1.61.2.1.4.1
+++ src/config.h.in	2002/08/29 05:34:50
@@ -566,6 +566,9 @@
 /* Define this if you want file coding support */
 #undef FILE_CODING
 
+/* Define this if you want syntax table support */
+#undef SYNTAX_TABLES
+
 /* Do we want to use X window input methods for use with Mule? (requires X11R5)
    If so, use raw Xlib or higher level Motif interface? */
 #undef HAVE_XIM
Index: src/dired.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/dired.c,v
retrieving revision 1.19.8.2
diff -u -r1.19.8.2 dired.c
--- src/dired.c	2002/05/04 21:31:17	1.19.8.2
+++ src/dired.c	2002/08/29 05:34:51
@@ -33,7 +33,6 @@
 #include "elhash.h"
 #include "regex.h"
 #include "opaque.h"
-#include "syntax.h"
 
 Lisp_Object Vcompletion_ignored_extensions;
 Lisp_Object Qdirectory_files;
@@ -123,9 +122,6 @@
   d = opendir ((char *) XSTRING_DATA (directory));
   if (!d)
     report_file_error ("Opening directory", list1 (directory));
-
-  regex_match_object = Qt;
-  regex_emacs_buffer = current_buffer;
 
   record_unwind_protect (close_directory_unwind, make_opaque_ptr ((void *)d));
 
Index: src/extents.h
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/extents.h,v
retrieving revision 1.11.10.1
diff -u -r1.11.10.1 extents.h
--- src/extents.h	2002/04/23 18:20:05	1.11.10.1
+++ src/extents.h	2002/08/29 05:34:54
@@ -315,10 +315,14 @@
 EXFUN (Fmake_extent, 3);
 EXFUN (Fprevious_single_property_change, 4);
 EXFUN (Fset_extent_endpoints, 4);
+#ifdef SYNTAX_TABLES
 EXFUN (Fnext_extent_change, 2);
 EXFUN (Fprevious_extent_change, 2);
+#endif /* SYNTAX_TABLES */
 EXFUN (Fset_extent_parent, 2);
+#ifdef SYNTAX_TABLES
 EXFUN (Fget_char_property, 4);
+#endif /* SYNTAX_TABLES */
 
 extern int inside_undo;
 extern int in_modeline_generation;
Index: src/font-lock.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/font-lock.c,v
retrieving revision 1.5.8.1
diff -u -r1.5.8.1 font-lock.c
--- src/font-lock.c	2002/08/24 04:47:42	1.5.8.1
+++ src/font-lock.c	2002/08/29 05:34:55
@@ -59,9 +59,13 @@
   context_none,
   context_string,
   context_comment,
+#ifndef SYNTAX_TABLES
+  context_block_comment
+#else /* SYNTAX_TABLES */
   context_block_comment,
   context_generic_comment,
   context_generic_string
+#endif /* SYNTAX_TABLES */
 };
 
 enum block_comment_context
@@ -335,8 +339,10 @@
       context_cache.style = comment_style_none;
       context_cache.scontext = '\000';
       context_cache.depth = 0;
+#ifdef SYNTAX_TABLES
       /* #### shouldn't this be checking the character's syntax instead of
          explicitly testing for backslash characters? */
+#endif /* SYNTAX_TABLES */
       context_cache.backslash_p = ((pt > 1) &&
 				   (BUF_FETCH_CHAR (buf, pt - 1) == '\\'));
       /* Note that the BOL context cache may not be at the beginning
@@ -391,13 +397,36 @@
   }
 }
 
+#ifndef SYNTAX_TABLES
+#define SYNTAX_START_STYLE(table, c1, c2)				 \
+  (SYNTAX_STYLES_MATCH_START_P (table, c1, c2, SYNTAX_COMMENT_STYLE_A) ? \
+   comment_style_a :							 \
+   SYNTAX_STYLES_MATCH_START_P (table, c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
+   comment_style_b :							 \
+#else /* SYNTAX_TABLES */
 #define SYNTAX_START_STYLE(c1, c2)					\
   (SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_A) ?	\
    comment_style_a :							\
    SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_B) ?	\
    comment_style_b :							\
+#endif /* SYNTAX_TABLES */
    comment_style_none)
 
+#ifndef SYNTAX_TABLES
+#define SYNTAX_END_STYLE(table, c1, c2)					\
+  (SYNTAX_STYLES_MATCH_END_P (table, c1, c2, SYNTAX_COMMENT_STYLE_A) ?	\
+     comment_style_a :							\
+   SYNTAX_STYLES_MATCH_END_P (table, c1, c2, SYNTAX_COMMENT_STYLE_B) ?	\
+     comment_style_b :							\
+     comment_style_none)
+  
+#define SINGLE_SYNTAX_STYLE(table, c)					\
+      (SYNTAX_STYLES_MATCH_1CHAR_P (table, c, SYNTAX_COMMENT_STYLE_A) ?	\
+         comment_style_a :						\
+       SYNTAX_STYLES_MATCH_1CHAR_P (table, c, SYNTAX_COMMENT_STYLE_B) ?	\
+         comment_style_b :						\
+         comment_style_none)
+#else /* SYNTAX_TABLES */
 #define SYNTAX_END_STYLE(c1, c2)				\
   (SYNTAX_CODES_MATCH_END_P (c1, c2, SYNTAX_COMMENT_STYLE_A) ?	\
    comment_style_a :						\
@@ -413,6 +442,7 @@
        SYNTAX_CODE_MATCHES_1CHAR_P (c, SYNTAX_COMMENT_STYLE_B) ?	\
        comment_style_b :						\
        comment_style_none))
+#endif /* SYNTAX_TABLES */
 
 /* Set up context_cache for position PT in BUF. */
 
@@ -420,27 +450,43 @@
 find_context (struct buffer *buf, Bufpos pt)
 {
   /* This function can GC */
+#ifdef SYNTAX_TABLES
 #ifndef emacs
+#endif /* SYNTAX_TABLES */
   Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
   Lisp_Object syntaxtab = buf->syntax_table;
+#ifdef SYNTAX_TABLES
 #endif
+#endif /* SYNTAX_TABLES */
   Emchar prev_c, c;
+#ifdef SYNTAX_TABLES
   int prev_syncode, syncode;
+#endif /* SYNTAX_TABLES */
   Bufpos target = pt;
   setup_context_cache (buf, pt);
   pt = context_cache.cur_point;
 
+#ifdef SYNTAX_TABLES
   SETUP_SYNTAX_CACHE (pt - 1, 1);
+#endif /* SYNTAX_TABLES */
   if (pt > BUF_BEGV (buf))
+#ifndef SYNTAX_TABLES
+    c = BUF_FETCH_CHAR (buf, pt - 1);
+#else /* SYNTAX_TABLES */
     {
       c = BUF_FETCH_CHAR (buf, pt - 1);
       syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
     }
+#endif /* SYNTAX_TABLES */
   else
+#ifndef SYNTAX_TABLES
+    c = '\n'; /* to get bol_context_cache at point-min */
+#else /* SYNTAX_TABLES */
     {
       c = '\n'; /* to get bol_context_cache at point-min */
       syncode = Swhitespace;
     }
+#endif /* SYNTAX_TABLES */
 
   for (; pt < target; pt++, context_cache.cur_point = pt)
     {
@@ -475,11 +521,17 @@
 	    }
 	}
 
+#ifdef SYNTAX_TABLES
       UPDATE_SYNTAX_CACHE_FORWARD (pt);
+#endif /* SYNTAX_TABLES */
       prev_c = c;
+#ifdef SYNTAX_TABLES
       prev_syncode = syncode;
+#endif /* SYNTAX_TABLES */
       c = BUF_FETCH_CHAR (buf, pt);
+#ifdef SYNTAX_TABLES
       syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
 
       if (prev_c == '\n')
 	bol_context_cache = context_cache;
@@ -490,7 +542,11 @@
 	  continue;
 	}
 
+#ifndef SYNTAX_TABLES
+      switch (SYNTAX (mirrortab, c))
+#else /* SYNTAX_TABLES */
       switch (SYNTAX_FROM_CACHE (mirrortab, c))
+#endif /* SYNTAX_TABLES */
 	{
 	case Sescape:
 	  context_cache.backslash_p = 1;
@@ -511,13 +567,21 @@
 	    {
 	      context_cache.context = context_comment;
 	      context_cache.ccontext = ccontext_none;
+#ifndef SYNTAX_TABLES
+	      context_cache.style = SINGLE_SYNTAX_STYLE (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	      context_cache.style = SINGLE_SYNTAX_STYLE (syncode);
+#endif /* SYNTAX_TABLES */
 	      if (context_cache.style == comment_style_none) abort ();
 	    }
 	  break;
 
 	case Sendcomment:
+#ifndef SYNTAX_TABLES
+	  if (context_cache.style != SINGLE_SYNTAX_STYLE (mirrortab, c))
+#else /* SYNTAX_TABLES */
 	  if (context_cache.style != SINGLE_SYNTAX_STYLE (syncode))
+#endif /* SYNTAX_TABLES */
 	    ;
 	  else if (context_cache.context == context_comment)
 	    {
@@ -544,8 +608,12 @@
 	      }
             else if (context_cache.context == context_none)
 	      {
+#ifndef SYNTAX_TABLES
+		Lisp_Object stringtermobj = syntax_match (syntaxtab, c);
+#else /* SYNTAX_TABLES */
 		Lisp_Object stringtermobj =
 		  syntax_match (syntax_cache.current_syntax_table, c);
+#endif /* SYNTAX_TABLES */
 		Emchar stringterm;
 
 		if (CHARP (stringtermobj))
@@ -558,6 +626,7 @@
 	      }
             break;
           }
+#ifdef SYNTAX_TABLES
 
 	case Scomment_fence:
 	  {
@@ -587,6 +656,7 @@
 	    break;
 	  }
 
+#endif /* SYNTAX_TABLES */
 	default:
 	  ;
 	}
@@ -595,18 +665,34 @@
 	 Now we've got to hack multi-char sequences that start
 	 and end block comments.
        */
+#ifndef SYNTAX_TABLES
+      if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
+#else /* SYNTAX_TABLES */
       if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
+#endif /* SYNTAX_TABLES */
 	   SYNTAX_SECOND_CHAR_START) &&
 	  context_cache.context == context_none &&
 	  context_cache.ccontext == ccontext_start1 &&
+#ifndef SYNTAX_TABLES
+	  SYNTAX_START_P (mirrortab, prev_c, c) /* the two chars match */
+#else /* SYNTAX_TABLES */
 	  SYNTAX_CODES_START_P (prev_syncode, syncode) /* the two chars match */
+#endif /* SYNTAX_TABLES */
 	  )
 	{
 	  context_cache.ccontext = ccontext_start2;
+#ifndef SYNTAX_TABLES
+	  context_cache.style = SYNTAX_START_STYLE (mirrortab, prev_c, c);
+#else /* SYNTAX_TABLES */
 	  context_cache.style = SYNTAX_START_STYLE (prev_syncode, syncode);
+#endif /* SYNTAX_TABLES */
 	  if (context_cache.style == comment_style_none) abort ();
 	}
+#ifndef SYNTAX_TABLES
+      else if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
+#else /* SYNTAX_TABLES */
       else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
+#endif /* SYNTAX_TABLES */
 		SYNTAX_FIRST_CHAR_START) &&
 	       context_cache.context == context_none &&
 	       (context_cache.ccontext == ccontext_none ||
@@ -615,30 +701,56 @@
 	  context_cache.ccontext = ccontext_start1;
 	  context_cache.style = comment_style_none; /* should be this already*/
 	}
+#ifndef SYNTAX_TABLES
+      else if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
+#else /* SYNTAX_TABLES */
       else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
+#endif /* SYNTAX_TABLES */
 		SYNTAX_SECOND_CHAR_END) &&
 	       context_cache.context == context_block_comment &&
 	       context_cache.ccontext == ccontext_end1 &&
+#ifndef SYNTAX_TABLES
+	       SYNTAX_END_P (mirrortab, prev_c, c) &&
+#else /* SYNTAX_TABLES */
 	       SYNTAX_CODES_END_P (prev_syncode, syncode) &&
+#endif /* SYNTAX_TABLES */
 	       /* the two chars match */
 	       context_cache.style ==
+#ifndef SYNTAX_TABLES
+	       SYNTAX_END_STYLE (mirrortab, prev_c, c)
+#else /* SYNTAX_TABLES */
 	       SYNTAX_END_STYLE (prev_syncode, syncode)
+#endif /* SYNTAX_TABLES */
 	       )
 	{
 	  context_cache.context = context_none;
 	  context_cache.ccontext = ccontext_none;
 	  context_cache.style = comment_style_none;
 	}
+#ifndef SYNTAX_TABLES
+      else if ((SYNTAX_COMMENT_BITS (mirrortab, c) &
+#else /* SYNTAX_TABLES */
       else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
+#endif /* SYNTAX_TABLES */
 		SYNTAX_FIRST_CHAR_END) &&
 	       context_cache.context == context_block_comment &&
+#ifndef SYNTAX_TABLES
+	       (context_cache.style ==
+		SYNTAX_END_STYLE (mirrortab, c,
+				  BUF_FETCH_CHAR (buf, pt+1))) &&
+#else /* SYNTAX_TABLES */
 	       context_cache.style == SINGLE_SYNTAX_STYLE (syncode) &&
+#endif /* SYNTAX_TABLES */
 	       (context_cache.ccontext == ccontext_start2 ||
 		context_cache.ccontext == ccontext_end1))
+#ifndef SYNTAX_TABLES
+	/* #### is it right to check for end1 here?? */
+#else /* SYNTAX_TABLES */
 	/* #### is it right to check for end1 here?? 
 	   yes, because this might be a repetition of the first char
 	   of a comment-end sequence. ie, '/xxx foo xxx/' or
 	   '/xxx foo x/', where 'x' = '*' -- mct */
+#endif /* SYNTAX_TABLES */
 	{
 	  if (context_cache.style == comment_style_none) abort ();
 	  context_cache.ccontext = ccontext_end1;
@@ -677,12 +789,19 @@
 {
   switch (context)
     {
+#ifndef SYNTAX_TABLES
+    case context_none:		return Qnil;
+    case context_string:	return Qstring;
+    case context_comment:	return Qcomment;
+    case context_block_comment:	return Qblock_comment;
+#else /* SYNTAX_TABLES */
     case context_none:			return Qnil;
     case context_string:		return Qstring;
     case context_comment:		return Qcomment;
     case context_block_comment:		return Qblock_comment;
     case context_generic_comment:	return Qblock_comment;
     case context_generic_string:	return Qstring;
+#endif /* SYNTAX_TABLES */
     default: abort (); return Qnil; /* suppress compiler warning */
     }
 }
@@ -773,9 +892,13 @@
       if (this_context == context_block_comment &&
 	  context_cache.ccontext == ccontext_start2)
 	estart -= 2;
+#ifndef SYNTAX_TABLES
+      else if (this_context == context_comment)
+#else /* SYNTAX_TABLES */
       else if (this_context == context_comment
 	       || this_context == context_generic_comment
 	       )
+#endif /* SYNTAX_TABLES */
 	estart -= 1;
 
       edepth = context_cache.depth;
@@ -791,9 +914,13 @@
 	 a part of the comment.
        */
       if ((this_context == context_block_comment ||
+#ifndef SYNTAX_TABLES
+	   this_context == context_comment)
+#else /* SYNTAX_TABLES */
 	   this_context == context_comment
 	   || this_context == context_generic_comment
 	   )
+#endif /* SYNTAX_TABLES */
 	  && pt < e)
 	eend++;
 
Index: src/regex.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/regex.c,v
retrieving revision 1.25.2.2
diff -u -r1.25.2.2 regex.c
--- src/regex.c	2001/05/17 13:37:45	1.25.2.2
+++ src/regex.c	2002/08/29 05:35:00
@@ -47,6 +47,7 @@
 #define _GNU_SOURCE 1
 #endif
 
+#ifdef SYNTAX_TABLES
 #ifdef emacs
 /* Converts the pointer to the char to BEG-based offset from the start.	 */
 #define PTR_TO_OFFSET(d) (MATCHING_IN_FIRST_STRING			\
@@ -55,6 +56,7 @@
 #define PTR_TO_OFFSET(d) 0
 #endif
 
+#endif /* SYNTAX_TABLES */
 /* We assume non-Mule if emacs isn't defined. */
 #ifndef emacs
 #undef MULE
@@ -190,8 +192,10 @@
 #endif /* SYNTAX_TABLE */
 
 #define SYNTAX_UNSAFE(ignored, c) re_syntax_table[c]
+#ifdef SYNTAX_TABLES
 #undef SYNTAX_FROM_CACHE
 #define SYNTAX_FROM_CACHE SYNTAX_UNSAFE
+#endif /* SYNTAX_TABLES */
 
 #define RE_TRANSLATE(c) translate[(unsigned char) (c)]
 #define TRANSLATE_P(tr) tr
@@ -381,7 +385,11 @@
 /* Type of source-pattern and string chars.  */
 typedef const unsigned char re_char;
 
+#ifndef SYNTAX_TABLES
+typedef char boolean;
+#else /* SYNTAX_TABLES */
 typedef char re_bool;
+#endif /* SYNTAX_TABLES */
 #define false 0
 #define true 1
 
@@ -1793,10 +1801,19 @@
 			unsigned char *end);
 static void insert_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2,
 			unsigned char *end);
+#ifndef SYNTAX_TABLES
+static boolean at_begline_loc_p (re_char *pattern, re_char *p,
+#else /* SYNTAX_TABLES */
 static re_bool at_begline_loc_p (re_char *pattern, re_char *p,
+#endif /* SYNTAX_TABLES */
 				 reg_syntax_t syntax);
+#ifndef SYNTAX_TABLES
+static boolean at_endline_loc_p (re_char *p, re_char *pend, int syntax);
+static boolean group_in_compile_stack (compile_stack_type compile_stack,
+#else /* SYNTAX_TABLES */
 static re_bool at_endline_loc_p (re_char *p, re_char *pend, int syntax);
 static re_bool group_in_compile_stack (compile_stack_type compile_stack,
+#endif /* SYNTAX_TABLES */
 				       regnum_t regnum);
 static reg_errcode_t compile_range (re_char **p_ptr, re_char *pend,
 				    RE_TRANSLATE_TYPE translate,
@@ -1809,12 +1826,24 @@
 					     reg_syntax_t syntax,
 					     Lisp_Object rtab);
 #endif /* MULE */
+#ifndef SYNTAX_TABLES
+static boolean group_match_null_string_p (unsigned char **p,
+#else /* SYNTAX_TABLES */
 static re_bool group_match_null_string_p (unsigned char **p,
+#endif /* SYNTAX_TABLES */
 					  unsigned char *end,
 					  register_info_type *reg_info);
+#ifndef SYNTAX_TABLES
+static boolean alt_match_null_string_p (unsigned char *p, unsigned char *end,
+#else /* SYNTAX_TABLES */
 static re_bool alt_match_null_string_p (unsigned char *p, unsigned char *end,
+#endif /* SYNTAX_TABLES */
 					register_info_type *reg_info);
+#ifndef SYNTAX_TABLES
+static boolean common_op_match_null_string_p (unsigned char **p,
+#else /* SYNTAX_TABLES */
 static re_bool common_op_match_null_string_p (unsigned char **p,
+#endif /* SYNTAX_TABLES */
 					      unsigned char *end,
 					      register_info_type *reg_info);
 static int bcmp_translate (const unsigned char *s1, const unsigned char *s2,
@@ -2061,11 +2090,20 @@
 
           {
 	    /* true means zero/many matches are allowed. */
+#ifndef SYNTAX_TABLES
+	    boolean zero_times_ok = c != '+';
+            boolean many_times_ok = c != '?';
+#else /* SYNTAX_TABLES */
 	    re_bool zero_times_ok = c != '+';
             re_bool many_times_ok = c != '?';
+#endif /* SYNTAX_TABLES */
 
             /* true means match shortest string possible. */
+#ifndef SYNTAX_TABLES
+            boolean minimal = false;
+#else /* SYNTAX_TABLES */
             re_bool minimal = false;
+#endif /* SYNTAX_TABLES */
 
             /* If there is a sequence of repetition chars, collapse it
                down to just one (the right one).  We can't combine
@@ -2169,7 +2207,11 @@
             else
               {
                 /* Are we optimizing this jump?  */
+#ifndef SYNTAX_TABLES
+                boolean keep_string_p = false;
+#else /* SYNTAX_TABLES */
                 re_bool keep_string_p = false;
+#endif /* SYNTAX_TABLES */
 
                 if (many_times_ok)
                   { /* More than one repetition is allowed, so put in
@@ -2245,9 +2287,17 @@
         case '[':
           {
 	    /* XEmacs change: this whole section */
+#ifndef SYNTAX_TABLES
+            boolean had_char_class = false;
+#else /* SYNTAX_TABLES */
             re_bool had_char_class = false;
+#endif /* SYNTAX_TABLES */
 #ifdef MULE
+#ifndef SYNTAX_TABLES
+	    boolean has_extended_chars = false;
+#else /* SYNTAX_TABLES */
 	    re_bool has_extended_chars = false;
+#endif /* SYNTAX_TABLES */
 	    REGISTER Lisp_Object rtab = Qnil;
 #endif
 
@@ -2429,6 +2479,20 @@
                     if (c == ':' && *p == ']')
                       {
                         int ch;
+#ifndef SYNTAX_TABLES
+                        boolean is_alnum = STREQ (str, "alnum");
+                        boolean is_alpha = STREQ (str, "alpha");
+                        boolean is_blank = STREQ (str, "blank");
+                        boolean is_cntrl = STREQ (str, "cntrl");
+                        boolean is_digit = STREQ (str, "digit");
+                        boolean is_graph = STREQ (str, "graph");
+                        boolean is_lower = STREQ (str, "lower");
+                        boolean is_print = STREQ (str, "print");
+                        boolean is_punct = STREQ (str, "punct");
+                        boolean is_space = STREQ (str, "space");
+                        boolean is_upper = STREQ (str, "upper");
+                        boolean is_xdigit = STREQ (str, "xdigit");
+#else /* SYNTAX_TABLES */
                         re_bool is_alnum = STREQ (str, "alnum");
                         re_bool is_alpha = STREQ (str, "alpha");
                         re_bool is_blank = STREQ (str, "blank");
@@ -2441,6 +2505,7 @@
                         re_bool is_space = STREQ (str, "space");
                         re_bool is_upper = STREQ (str, "upper");
                         re_bool is_xdigit = STREQ (str, "xdigit");
+#endif /* SYNTAX_TABLES */
 
                         if (!IS_CHAR_CLASS (str))
 			  FREE_STACK_RETURN (REG_ECTYPE);
@@ -3226,11 +3291,19 @@
    after an alternative or a begin-subexpression.  We assume there is at
    least one character before the ^.  */
 
+#ifndef SYNTAX_TABLES
+static boolean
+#else /* SYNTAX_TABLES */
 static re_bool
+#endif /* SYNTAX_TABLES */
 at_begline_loc_p (re_char *pattern, re_char *p, reg_syntax_t syntax)
 {
   re_char *prev = p - 2;
+#ifndef SYNTAX_TABLES
+  boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\';
+#else /* SYNTAX_TABLES */
   re_bool prev_prev_backslash = prev > pattern && prev[-1] == '\\';
+#endif /* SYNTAX_TABLES */
 
   return
        /* After a subexpression?  */
@@ -3243,11 +3316,19 @@
 /* The dual of at_begline_loc_p.  This one is for $.  We assume there is
    at least one character after the $, i.e., `P < PEND'.  */
 
+#ifndef SYNTAX_TABLES
+static boolean
+#else /* SYNTAX_TABLES */
 static re_bool
+#endif /* SYNTAX_TABLES */
 at_endline_loc_p (re_char *p, re_char *pend, int syntax)
 {
   re_char *next = p;
+#ifndef SYNTAX_TABLES
+  boolean next_backslash = *next == '\\';
+#else /* SYNTAX_TABLES */
   re_bool next_backslash = *next == '\\';
+#endif /* SYNTAX_TABLES */
   re_char *next_next = p + 1 < pend ? p + 1 : 0;
 
   return
@@ -3263,7 +3344,11 @@
 /* Returns true if REGNUM is in one of COMPILE_STACK's elements and
    false if it's not.  */
 
+#ifndef SYNTAX_TABLES
+static boolean
+#else /* SYNTAX_TABLES */
 static re_bool
+#endif /* SYNTAX_TABLES */
 group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
 {
   int this_element;
@@ -3434,10 +3519,18 @@
      proven otherwise.  We set this false at the bottom of switch
      statement, to which we get only if a particular path doesn't
      match the empty string.  */
+#ifndef SYNTAX_TABLES
+  boolean path_can_be_null = true;
+#else /* SYNTAX_TABLES */
   re_bool path_can_be_null = true;
+#endif /* SYNTAX_TABLES */
 
   /* We aren't doing a `succeed_n' to begin with.  */
+#ifndef SYNTAX_TABLES
+  boolean succeed_n_p = false;
+#else /* SYNTAX_TABLES */
   re_bool succeed_n_p = false;
+#endif /* SYNTAX_TABLES */
 
   assert (fastmap != NULL && p != NULL);
 
@@ -3637,6 +3730,7 @@
 	  }
 
 #ifdef emacs
+#ifdef SYNTAX_TABLES
 	case wordbound:
 	case notwordbound:
 	case wordbeg:
@@ -3650,9 +3744,12 @@
 
 #ifdef emacs
 #if 0   /* Removed during syntax-table properties patch -- 2000/12/07 mct */
+#endif /* SYNTAX_TABLES */
         case syntaxspec:
 	  k = *p++;
+#ifdef SYNTAX_TABLES
 #endif
+#endif /* SYNTAX_TABLES */
 	  matchsyntax:
 #ifdef MULE
 	  for (j = 0; j < 0x80; j++)
@@ -3692,10 +3789,14 @@
 	  break;
 
 
+#ifdef SYNTAX_TABLES
 #if 0   /* Removed during syntax-table properties patch -- 2000/12/07 mct */
+#endif /* SYNTAX_TABLES */
 	case notsyntaxspec:
 	  k = *p++;
+#ifdef SYNTAX_TABLES
 #endif
+#endif /* SYNTAX_TABLES */
 	  matchnotsyntax:
 #ifdef MULE
 	  for (j = 0; j < 0x80; j++)
@@ -3733,7 +3834,9 @@
 	      fastmap[j] = 1;
 #endif /* MULE */
 	  break;
+#ifdef SYNTAX_TABLES
 #endif /* emacs */
+#endif /* SYNTAX_TABLES */
 
 #ifdef MULE
 /* 97/2/17 jhod category patch */
@@ -3760,12 +3863,16 @@
         case endline:
 	case begbuf:
 	case endbuf:
+#ifdef SYNTAX_TABLES
 #ifndef emacs
+#endif /* SYNTAX_TABLES */
 	case wordbound:
 	case notwordbound:
 	case wordbeg:
 	case wordend:
+#ifdef SYNTAX_TABLES
 #endif
+#endif /* SYNTAX_TABLES */
         case push_dummy_failure:
           continue;
 
@@ -4006,6 +4113,7 @@
 	}
     }
 
+#ifdef SYNTAX_TABLES
 #ifdef emacs
   /* In a forward search for something that starts with \=.
      don't keep searching past point.  */
@@ -4018,6 +4126,7 @@
     }
 #endif /* emacs */
 
+#endif /* SYNTAX_TABLES */
   /* Update the fastmap now if not correct already.  */
   if (fastmap && !bufp->fastmap_accurate)
     if (re_compile_fastmap (bufp) == -2)
@@ -4039,6 +4148,7 @@
   }
 #endif
 
+#ifdef SYNTAX_TABLES
 #ifdef emacs
     SETUP_SYNTAX_CACHE_FOR_OBJECT (regex_match_object,
 				   regex_emacs_buffer,
@@ -4048,6 +4158,7 @@
 				   1);
 #endif
 
+#endif /* SYNTAX_TABLES */
   /* Loop through the string, looking for a place to start matching.  */
   for (;;)
     {
@@ -4311,6 +4422,11 @@
 	    int size1, const char *string2, int size2, int pos,
 	    struct re_registers *regs, int stop)
 {
+#ifndef SYNTAX_TABLES
+  int result = re_match_2_internal (bufp, (re_char *) string1, size1,
+				    (re_char *) string2, size2,
+				    pos, regs, stop);
+#else /* SYNTAX_TABLES */
   int result;
 
 #ifdef emacs
@@ -4326,6 +4442,7 @@
 				(re_char *) string2, size2,
 				pos, regs, stop);
 
+#endif /* SYNTAX_TABLES */
   alloca (0);
   return result;
 }
@@ -4460,10 +4577,18 @@
 
   /* 1 if this match ends in the same string (string1 or string2)
      as the best previous match.  */
+#ifndef SYNTAX_TABLES
+  boolean same_str_p;
+#else /* SYNTAX_TABLES */
   re_bool same_str_p;
+#endif /* SYNTAX_TABLES */
 
   /* 1 if this match is the best seen so far.  */
+#ifndef SYNTAX_TABLES
+  boolean best_match_p;
+#else /* SYNTAX_TABLES */
   re_bool best_match_p;
+#endif /* SYNTAX_TABLES */
 
   DEBUG_PRINT1 ("\n\nEntering re_match_2.\n");
 
@@ -4824,7 +4949,11 @@
 	case charset_not:
 	  {
 	    REGISTER unsigned char c;
+#ifndef SYNTAX_TABLES
+	    boolean not_p = (re_opcode_t) *(p - 1) == charset_not;
+#else /* SYNTAX_TABLES */
 	    re_bool not_p = (re_opcode_t) *(p - 1) == charset_not;
+#endif /* SYNTAX_TABLES */
 
             DEBUG_PRINT2 ("EXECUTING charset%s.\n", not_p ? "_not" : "");
 
@@ -4851,7 +4980,11 @@
 	case charset_mule_not:
 	  {
 	    REGISTER Emchar c;
+#ifndef SYNTAX_TABLES
+	    boolean not_p = (re_opcode_t) *(p - 1) == charset_mule_not;
+#else /* SYNTAX_TABLES */
 	    re_bool not_p = (re_opcode_t) *(p - 1) == charset_mule_not;
+#endif /* SYNTAX_TABLES */
 
             DEBUG_PRINT2 ("EXECUTING charset_mule%s.\n", not_p ? "_not" : "");
 
@@ -4998,7 +5131,11 @@
                || just_past_start_mem == p - 1)
 	      && (p + 2) < pend)
             {
+#ifndef SYNTAX_TABLES
+              boolean is_a_jump_n = false;
+#else /* SYNTAX_TABLES */
               re_bool is_a_jump_n = false;
+#endif /* SYNTAX_TABLES */
 
               p1 = p + 2;
               mcnt = 0;
@@ -5543,20 +5680,33 @@
 	      result = 1;
 	    else
 	      {
+#ifndef SYNTAX_TABLES
+		const unsigned char *d_before =
+		  (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
+		const unsigned char *d_after =
+		  (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
+#else /* SYNTAX_TABLES */
 		re_char *d_before = POS_BEFORE_GAP_UNSAFE (d);
 		re_char *d_after = POS_AFTER_GAP_UNSAFE (d);
 
 		/* emch1 is the character before d, syn1 is the syntax of emch1,
 		   emch2 is the character at d, and syn2 is the syntax of emch2. */
+#endif /* SYNTAX_TABLES */
 		Emchar emch1, emch2;
+#ifdef SYNTAX_TABLES
 		int syn1, syn2;
 #ifdef emacs
 		int pos_before;
 #endif
+#endif /* SYNTAX_TABLES */
 
 		DEC_CHARPTR (d_before);
 		emch1 = charptr_emchar (d_before);
 		emch2 = charptr_emchar (d_after);
+#ifndef SYNTAX_TABLES
+		result = (WORDCHAR_P_UNSAFE (emch1) !=
+			  WORDCHAR_P_UNSAFE (emch2));
+#else /* SYNTAX_TABLES */
 
 #ifdef emacs
 		pos_before = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d)) - 1;
@@ -5571,6 +5721,7 @@
 					  emch2);
 
 		result = ((syn1 == Sword) != (syn2 == Sword));
+#endif /* SYNTAX_TABLES */
 	      }
 	    if (result == should_succeed)
 	      break;
@@ -5584,8 +5735,10 @@
 
 	case wordbeg:
           DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
+#ifdef SYNTAX_TABLES
 	  if (AT_STRINGS_END (d))
 	    goto fail;
+#endif /* SYNTAX_TABLES */
 	  {
 	    /* XEmacs: this originally read:
 
@@ -5593,33 +5746,52 @@
 	      break;
 
 	      */
+#ifndef SYNTAX_TABLES
+	    const unsigned char *dtmp =
+	      (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
+#else /* SYNTAX_TABLES */
 	    re_char *dtmp = POS_AFTER_GAP_UNSAFE (d);
+#endif /* SYNTAX_TABLES */
 	    Emchar emch = charptr_emchar (dtmp);
+#ifndef SYNTAX_TABLES
+	    if (!WORDCHAR_P_UNSAFE (emch))
+#else /* SYNTAX_TABLES */
 #ifdef emacs
 	    int charpos = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d));
 	    UPDATE_SYNTAX_CACHE (charpos);
 #endif
 	    if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
 				   emch) != Sword)
+#endif /* SYNTAX_TABLES */
 	      goto fail;
 	    if (AT_STRINGS_BEG (d))
 	      break;
+#ifndef SYNTAX_TABLES
+	    dtmp = (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
+#else /* SYNTAX_TABLES */
 	    dtmp = POS_BEFORE_GAP_UNSAFE (d);
+#endif /* SYNTAX_TABLES */
 	    DEC_CHARPTR (dtmp);
 	    emch = charptr_emchar (dtmp);
+#ifndef SYNTAX_TABLES
+	    if (!WORDCHAR_P_UNSAFE (emch))
+#else /* SYNTAX_TABLES */
 #ifdef emacs
 	    UPDATE_SYNTAX_CACHE_BACKWARD (charpos - 1);
 #endif
 	    if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
 				   emch) != Sword)
+#endif /* SYNTAX_TABLES */
 	      break;
 	    goto fail;
 	  }
 
 	case wordend:
           DEBUG_PRINT1 ("EXECUTING wordend.\n");
+#ifdef SYNTAX_TABLES
 	  if (AT_STRINGS_BEG (d))
 	    goto fail;
+#endif /* SYNTAX_TABLES */
 	  {
 	    /* XEmacs: this originally read:
 
@@ -5629,27 +5801,49 @@
 
 	      The or condition is incorrect (reversed).
 	      */
+#ifndef SYNTAX_TABLES
+	    const unsigned char *dtmp;
+#else /* SYNTAX_TABLES */
 	    re_char *dtmp;
+#endif /* SYNTAX_TABLES */
 	    Emchar emch;
+#ifndef SYNTAX_TABLES
+	    if (AT_STRINGS_BEG (d))
+	      goto fail;
+	    dtmp = (const unsigned char *) POS_BEFORE_GAP_UNSAFE (d);
+#else /* SYNTAX_TABLES */
 #ifdef emacs
 	    int charpos = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d)) - 1;
 	    UPDATE_SYNTAX_CACHE (charpos);
 #endif
 	    dtmp = POS_BEFORE_GAP_UNSAFE (d);
+#endif /* SYNTAX_TABLES */
 	    DEC_CHARPTR (dtmp);
 	    emch = charptr_emchar (dtmp);
+#ifndef SYNTAX_TABLES
+	    if (!WORDCHAR_P_UNSAFE (emch))
+#else /* SYNTAX_TABLES */
 	    if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
 				   emch) != Sword)
+#endif /* SYNTAX_TABLES */
 	      goto fail;
 	    if (AT_STRINGS_END (d))
 	      break;
+#ifndef SYNTAX_TABLES
+	    dtmp = (const unsigned char *) POS_AFTER_GAP_UNSAFE (d);
+#else /* SYNTAX_TABLES */
 	    dtmp = POS_AFTER_GAP_UNSAFE (d);
+#endif /* SYNTAX_TABLES */
 	    emch = charptr_emchar (dtmp);
+#ifndef SYNTAX_TABLES
+	    if (!WORDCHAR_P_UNSAFE (emch))
+#else /* SYNTAX_TABLES */
 #ifdef emacs
 	    UPDATE_SYNTAX_CACHE_FORWARD (charpos + 1);
 #endif
 	    if (SYNTAX_FROM_CACHE (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
 				   emch) != Sword)
+#endif /* SYNTAX_TABLES */
 	      break;
 	    goto fail;
 	  }
@@ -5657,7 +5851,11 @@
 #ifdef emacs
   	case before_dot:
           DEBUG_PRINT1 ("EXECUTING before_dot.\n");
+#ifndef SYNTAX_TABLES
+ 	  if (!regex_emacs_buffer_p
+#else /* SYNTAX_TABLES */
  	  if (! (NILP (regex_match_object) || BUFFERP (regex_match_object))
+#endif /* SYNTAX_TABLES */
 	      || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
 		  >= BUF_PT (regex_emacs_buffer)))
   	    goto fail;
@@ -5665,7 +5863,11 @@
 
   	case at_dot:
           DEBUG_PRINT1 ("EXECUTING at_dot.\n");
+#ifndef SYNTAX_TABLES
+ 	  if (!regex_emacs_buffer_p
+#else /* SYNTAX_TABLES */
  	  if (! (NILP (regex_match_object) || BUFFERP (regex_match_object))
+#endif /* SYNTAX_TABLES */
 	      || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
 		  != BUF_PT (regex_emacs_buffer)))
   	    goto fail;
@@ -5673,7 +5875,11 @@
 
   	case after_dot:
           DEBUG_PRINT1 ("EXECUTING after_dot.\n");
+#ifndef SYNTAX_TABLES
+          if (!regex_emacs_buffer_p
+#else /* SYNTAX_TABLES */
           if (! (NILP (regex_match_object) || BUFFERP (regex_match_object))
+#endif /* SYNTAX_TABLES */
 	      || (BUF_PTR_BYTE_POS (regex_emacs_buffer, (unsigned char *) d)
 		  <= BUF_PT (regex_emacs_buffer)))
   	    goto fail;
@@ -5703,6 +5909,7 @@
 	    Emchar emch;
 
 	    REGEX_PREFETCH ();
+#ifdef SYNTAX_TABLES
 #ifdef emacs
 	    {
 	      int charpos = SYNTAX_CACHE_BYTE_TO_CHAR (PTR_TO_OFFSET (d));
@@ -5710,8 +5917,14 @@
 	    }
 #endif
 
+#endif /* SYNTAX_TABLES */
 	    emch = charptr_emchar ((const Bufbyte *) d);
+#ifndef SYNTAX_TABLES
+	    matches = (SYNTAX_UNSAFE
+		       (XCHAR_TABLE (regex_emacs_buffer->mirror_syntax_table),
+#else /* SYNTAX_TABLES */
 	    matches = (SYNTAX_FROM_CACHE (regex_emacs_buffer->mirror_syntax_table,
+#endif /* SYNTAX_TABLES */
 			emch) == (enum syntaxcode) mcnt);
 	    INC_CHARPTR (d);
 	    if (matches != should_succeed)
@@ -5799,7 +6012,11 @@
 	  assert (p <= pend);
           if (p < pend)
             {
+#ifndef SYNTAX_TABLES
+              boolean is_a_jump_n = false;
+#else /* SYNTAX_TABLES */
               re_bool is_a_jump_n = false;
+#endif /* SYNTAX_TABLES */
 
               /* If failed to a backwards jump that's part of a repetition
                  loop, need to pop this failure point and use the next one.  */
@@ -5852,7 +6069,11 @@
 
    We don't handle duplicates properly (yet).  */
 
+#ifndef SYNTAX_TABLES
+static boolean
+#else /* SYNTAX_TABLES */
 static re_bool
+#endif /* SYNTAX_TABLES */
 group_match_null_string_p (unsigned char **p, unsigned char *end,
 			   register_info_type *reg_info)
 {
@@ -5960,7 +6181,11 @@
    It expects P to be the first byte of a single alternative and END one
    byte past the last. The alternative can contain groups.  */
 
+#ifndef SYNTAX_TABLES
+static boolean
+#else /* SYNTAX_TABLES */
 static re_bool
+#endif /* SYNTAX_TABLES */
 alt_match_null_string_p (unsigned char *p, unsigned char *end,
 			 register_info_type *reg_info)
 {
@@ -5996,12 +6221,20 @@
 
    Sets P to one after the op and its arguments, if any.  */
 
+#ifndef SYNTAX_TABLES
+static boolean
+#else /* SYNTAX_TABLES */
 static re_bool
+#endif /* SYNTAX_TABLES */
 common_op_match_null_string_p (unsigned char **p, unsigned char *end,
 			       register_info_type *reg_info)
 {
   int mcnt;
+#ifndef SYNTAX_TABLES
+  boolean ret;
+#else /* SYNTAX_TABLES */
   re_bool ret;
+#endif /* SYNTAX_TABLES */
   int reg_no;
   unsigned char *p1 = *p;
 
@@ -6327,7 +6560,11 @@
   struct re_registers regs;
   regex_t private_preg;
   int len = strlen (string);
+#ifndef SYNTAX_TABLES
+  boolean want_reg_info = !preg->no_sub && nmatch > 0;
+#else /* SYNTAX_TABLES */
   re_bool want_reg_info = !preg->no_sub && nmatch > 0;
+#endif /* SYNTAX_TABLES */
 
   private_preg = *preg;
 
Index: src/search.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/search.c,v
retrieving revision 1.17.2.1.4.2
diff -u -r1.17.2.1.4.2 search.c
--- src/search.c	2002/08/24 04:47:52	1.17.2.1.4.2
+++ src/search.c	2002/08/29 05:35:01
@@ -313,8 +313,13 @@
   s1 = p2 - p1;
   s2 = BI_BUF_ZV (buf) - p2;
 
+#ifdef SYNTAX_TABLES
   regex_match_object = Qnil;
+#endif /* SYNTAX_TABLES */
   regex_emacs_buffer = buf;
+#ifndef SYNTAX_TABLES
+  regex_emacs_buffer_p = 1;
+#endif /* ! SYNTAX_TABLES */
   i = re_match_2 (bufp, (char *) BI_BUF_BYTE_ADDRESS (buf, p1),
 		  s1, (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2,
 		  BI_BUF_PT (buf) - BI_BUF_BEGV (buf), &search_regs,
@@ -404,8 +409,13 @@
   QUIT;
   {
     Bytecount bis = charcount_to_bytecount (XSTRING_DATA (string), s);
+#ifdef SYNTAX_TABLES
     regex_match_object = string;
+#endif /* SYNTAX_TABLES */
     regex_emacs_buffer = buf;
+#ifndef SYNTAX_TABLES
+    regex_emacs_buffer_p = 0;
+#endif /* ! SYNTAX_TABLES */
     val = re_search (bufp, (char *) XSTRING_DATA (string),
 		     XSTRING_LENGTH (string), bis,
 		     XSTRING_LENGTH (string) - bis,
@@ -496,8 +506,13 @@
     }
 
   /* #### evil current-buffer dependency */
+#ifdef SYNTAX_TABLES
   regex_match_object = reloc;
+#endif /* SYNTAX_TABLES */
   regex_emacs_buffer = current_buffer;
+#ifndef SYNTAX_TABLES
+  regex_emacs_buffer_p = 0;
+#endif /* ! SYNTAX_TABLES */
   val = re_search (bufp, (char *) newnonreloc + offset, length, 0,
 		   length, 0);
 
@@ -786,9 +801,13 @@
   unsigned char fastmap[0400];
   int negate = 0;
   REGISTER int i;
+#ifdef SYNTAX_TABLES
 #ifndef emacs
+#endif /* SYNTAX_TABLES */
   Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table);
+#ifdef SYNTAX_TABLES
 #endif
+#endif /* SYNTAX_TABLES */
   Bufpos limit;
 
   if (NILP (lim))
@@ -888,7 +907,9 @@
 
     if (syntaxp)
       {
+#ifdef SYNTAX_TABLES
 	SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, pos, forwardp ? 1 : -1);
+#endif /* SYNTAX_TABLES */
 	/* All syntax designators are normal chars so nothing strange
 	   to worry about */
 	if (forwardp)
@@ -896,15 +917,23 @@
 	    if (pos < limit)
 	      while (fastmap[(unsigned char)
 			     syntax_code_spec
+#ifndef SYNTAX_TABLES
+			     [(int) SYNTAX (syntax_table,
+					    BUF_FETCH_CHAR
+					    (buf, BUF_PT (buf)))]])
+#else /* SYNTAX_TABLES */
 			     [(int) SYNTAX_FROM_CACHE
 			      (syntax_table,
 			       BI_BUF_FETCH_CHAR (buf, pos_byte))]])
+#endif /* SYNTAX_TABLES */
 		{
 		  pos++;
 		  INC_BYTIND (buf, pos_byte);
 		  if (pos >= limit)
 		    break;
+#ifdef SYNTAX_TABLES
 		  UPDATE_SYNTAX_CACHE_FORWARD (pos);
+#endif /* SYNTAX_TABLES */
 		}
 	  }
 	else
@@ -914,12 +943,20 @@
 		Bufpos savepos = pos_byte;
 		pos--;
 		DEC_BYTIND (buf, pos_byte);
+#ifdef SYNTAX_TABLES
 		UPDATE_SYNTAX_CACHE_BACKWARD (pos);
+#endif /* SYNTAX_TABLES */
 		if (!fastmap[(unsigned char)
 			     syntax_code_spec
+#ifndef SYNTAX_TABLES
+			     [(int) SYNTAX (syntax_table,
+					    BUF_FETCH_CHAR
+					    (buf, BUF_PT (buf)))]])
+#else /* SYNTAX_TABLES */
 			     [(int) SYNTAX_FROM_CACHE
 			      (syntax_table,
 			       BI_BUF_FETCH_CHAR (buf, pos_byte))]])
+#endif /* SYNTAX_TABLES */
 		  {
 		    pos++;
 		    pos_byte = savepos;
@@ -1196,13 +1233,18 @@
       p2 = BI_BUF_CEILING_OF (buf, p1);
       s1 = p2 - p1;
       s2 = BI_BUF_ZV (buf) - p2;
+#ifdef SYNTAX_TABLES
       regex_match_object = Qnil;
+#endif /* SYNTAX_TABLES */
 
       while (n < 0)
 	{
 	  Bytecount val;
 	  QUIT;
           regex_emacs_buffer = buf;
+#ifndef SYNTAX_TABLES
+	  regex_emacs_buffer_p = 1;
+#endif /* ! SYNTAX_TABLES */
 	  val = re_search_2 (bufp,
 			     (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1,
 			     (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2,
@@ -1241,6 +1283,9 @@
 	  Bytecount val;
 	  QUIT;
           regex_emacs_buffer = buf;
+#ifndef SYNTAX_TABLES
+	  regex_emacs_buffer_p = 1;
+#endif /* ! SYNTAX_TABLES */
           val = re_search_2 (bufp,
 			     (char *) BI_BUF_BYTE_ADDRESS (buf, p1), s1,
 			     (char *) BI_BUF_BYTE_ADDRESS (buf, p2), s2,
Index: src/syntax.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/syntax.c,v
retrieving revision 1.9.2.1
diff -u -r1.9.2.1 syntax.c
--- src/syntax.c	2001/07/25 07:45:37	1.9.2.1
+++ src/syntax.c	2002/08/29 05:35:02
@@ -28,7 +28,9 @@
 
 #include "buffer.h"
 #include "syntax.h"
+#ifdef SYNTAX_TABLES
 #include "extents.h"
+#endif /* SYNTAX_TABLES */
 
 /* Here is a comment from Ken'ichi HANDA <handa@etl.go.jp>
    explaining the purpose of the Sextword syntax category:
@@ -56,12 +58,14 @@
 /* Mule 2.4 doesn't seem to have Sextword - I'm removing it -- mrb */
 /* Recovered by tomo */
 
+#ifdef SYNTAX_TABLES
 #define ST_COMMENT_STYLE 0x101
 #define ST_STRING_STYLE  0x102
 
 Lisp_Object Qsyntax_table;
 int lookup_syntax_properties;
 
+#endif /* SYNTAX_TABLES */
 Lisp_Object Qsyntax_table_p;
 
 int words_include_escapes;
@@ -81,9 +85,14 @@
    and the like. */
 struct buffer *regex_emacs_buffer;
 
+#ifndef SYNTAX_TABLES
+/* Tell the regex routines whether buffer is used or not. */
+int regex_emacs_buffer_p;
+#else /* SYNTAX_TABLES */
 /* In Emacs, this is the string or buffer in which we
    are matching.  It is used for looking up syntax properties.	*/
 Lisp_Object regex_match_object;
+#endif /* SYNTAX_TABLES */
 
 Lisp_Object Vstandard_syntax_table;
 
@@ -96,7 +105,11 @@
   int depth;		/* Depth at end of parsing */
   Emchar instring;	/* -1 if not within string, else desired terminator */
   int incomment;	/* Nonzero if within a comment at end of parsing */
+#ifndef SYNTAX_TABLES
+  int comstyle;		/* comment style a=0, or b=1 */
+#else /* SYNTAX_TABLES */
   int comstyle;		/* comment style a=0, or b=1, or ST_COMMENT_STYLE */
+#endif /* SYNTAX_TABLES */
   int quoted;		/* Nonzero if just after an escape char at end of
 			   parsing */
   Bufpos thislevelstart;/* Char number of most recent start-of-expression
@@ -104,9 +117,13 @@
   Bufpos prevlevelstart;/* Char number of start of containing expression */
   Bufpos location;	/* Char number at which parsing stopped */
   int mindepth;		/* Minimum depth seen while scanning  */
+#ifndef SYNTAX_TABLES
+  Bufpos comstart;	/* Position just after last comment starter  */
+#else /* SYNTAX_TABLES */
   Bufpos comstr_start;	/* Position just after last comment/string starter  */
   Lisp_Object levelstarts;	/* Char numbers of starts-of-expression
                                    of levels (starting from outermost).  */
+#endif /* SYNTAX_TABLES */
 };
 
 /* These variables are a cache for finding the start of a defun.
@@ -130,6 +147,9 @@
 find_defun_start (struct buffer *buf, Bufpos pos)
 {
   Bufpos tem;
+#ifndef SYNTAX_TABLES
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#endif /* ! SYNTAX_TABLES */
 
   /* Use previous finding, if it's valid and applies to this inquiry.  */
   if (buf == find_start_buffer
@@ -145,13 +165,21 @@
   /* Back up to start of line.  */
   tem = find_next_newline (buf, pos, -1);
 
+#ifdef SYNTAX_TABLES
   SETUP_SYNTAX_CACHE (tem, 1);
+#endif /* SYNTAX_TABLES */
   while (tem > BUF_BEGV (buf))
     {
+#ifdef SYNTAX_TABLES
       UPDATE_SYNTAX_CACHE_BACKWARD(tem);
 
+#endif /* SYNTAX_TABLES */
       /* Open-paren at start of line means we found our defun-start.  */
+#ifndef SYNTAX_TABLES
+      if (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, tem)) == Sopen)
+#else /* SYNTAX_TABLES */
       if (SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, tem)) == Sopen)
+#endif /* SYNTAX_TABLES */
 	break;
       /* Move to beg of previous line.  */
       tem = find_next_newline (buf, tem, -2);
@@ -235,6 +263,7 @@
   return syntax_table;
 }
 
+#ifdef SYNTAX_TABLES
 /* The current syntax state */
 struct syntax_cache syntax_cache;
 
@@ -333,6 +362,7 @@
     }
 }
 
+#endif /* SYNTAX_TABLES */
 /* Convert a letter which signifies a syntax code
    into the code it signifies.
    This is used by modify-syntax-entry, and other things. */
@@ -356,10 +386,18 @@
   0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,   /* `, a, ... */
   0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377,
   0377, 0377, 0377, 0377, 0377, 0377, 0377, (char) Sword,
+#ifndef SYNTAX_TABLES
+  0377, 0377, 0377, 0377, 0377, 0377, 0377, 0377
+#else /* SYNTAX_TABLES */
   0377, 0377, 0377, 0377, (char) Sstring_fence, 0377, 0377, 0377
+#endif /* SYNTAX_TABLES */
 };
 
+#ifndef SYNTAX_TABLES
+const unsigned char syntax_code_spec[] =  " .w_()'\"$\\/<>@";
+#else /* SYNTAX_TABLES */
 const unsigned char syntax_code_spec[] =  " .w_()'\"$\\/<>@!|";
+#endif /* SYNTAX_TABLES */
 
 DEFUN ("syntax-designator-chars", Fsyntax_designator_chars, 0, 0, 0, /*
 Return a string of the recognized syntax designator chars.
@@ -461,11 +499,16 @@
 scan_words (struct buffer *buf, Bufpos from, int count)
 {
   Bufpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
+#ifndef SYNTAX_TABLES
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#endif /* ! SYNTAX_TABLES */
   Emchar ch0, ch1;
   enum syntaxcode code;
 
+#ifdef SYNTAX_TABLES
   SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, from, count);
 
+#endif /* SYNTAX_TABLES */
   /* #### is it really worth it to hand expand both cases? JV */
   while (count > 0)
     {
@@ -476,9 +519,15 @@
 	  if (from == limit)
 	    return 0;
 
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
 	  ch0 = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX_UNSAFE (mirrortab, ch0);
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, ch0);
+#endif /* SYNTAX_TABLES */
 
 	  from++;
 	  if (words_include_escapes
@@ -492,9 +541,15 @@
 
       while (from != limit)
 	{
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
 	  ch1 = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX_UNSAFE (mirrortab, ch1);
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, ch1);
+#endif /* SYNTAX_TABLES */
 	  if (!(words_include_escapes
 		&& (code == Sescape || code == Scharquote)))
 	    if (code != Sword
@@ -520,11 +575,20 @@
 	  if (from == limit)
 	    return 0;
 
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
+#endif /* SYNTAX_TABLES */
 	  ch1 = BUF_FETCH_CHAR (buf, from - 1);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX_UNSAFE (mirrortab, ch1);
+
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, ch1);
+#endif /* SYNTAX_TABLES */
 	  from--;
+#ifdef SYNTAX_TABLES
 
+#endif /* SYNTAX_TABLES */
 	  if (words_include_escapes
 	      && (code == Sescape || code == Scharquote))
 	    break;
@@ -536,10 +600,16 @@
 
       while (from != limit)
 	{
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
+#endif /* SYNTAX_TABLES */
 	  ch0 = BUF_FETCH_CHAR (buf, from - 1);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX_UNSAFE (mirrortab, ch0);
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, ch0);
 
+#endif /* SYNTAX_TABLES */
 	  if (!(words_include_escapes
 		&& (code == Sescape || code == Scharquote)))
 	    if (code != Sword
@@ -606,11 +676,18 @@
 				int commentstop);
 
 static int
+#ifndef SYNTAX_TABLES
+find_start_of_comment (struct buffer *buf, Bufpos from, Bufpos stop, int mask)
+#else /* SYNTAX_TABLES */
 find_start_of_comment (struct buffer *buf, Bufpos from, Bufpos stop,
 		       int comstyle)
+#endif /* SYNTAX_TABLES */
 {
   Emchar c;
   enum syntaxcode code;
+#ifndef SYNTAX_TABLES
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#endif /* ! SYNTAX_TABLES */
 
   /* Look back, counting the parity of string-quotes,
      and recording the comment-starters seen.
@@ -628,40 +705,86 @@
   Bufpos comstart_pos = 0;
   int comstart_parity = 0;
   int styles_match_p = 0;
+#ifdef SYNTAX_TABLES
   /* mask to match comment styles against; for ST_COMMENT_STYLE, this
      will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */
   int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
+#endif /* SYNTAX_TABLES */
 
   /* At beginning of range to scan, we're outside of strings;
      that determines quote parity to the comment-end.  */
   while (from != stop)
     {
+#ifdef SYNTAX_TABLES
       int syncode;
 
+#endif /* SYNTAX_TABLES */
       /* Move back and examine a character.  */
       from--;
+#ifdef SYNTAX_TABLES
       UPDATE_SYNTAX_CACHE_BACKWARD (from);
+#endif /* SYNTAX_TABLES */
 
       c = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+      code = SYNTAX_UNSAFE (mirrortab, c);
+#else /* SYNTAX_TABLES */
       code = SYNTAX_FROM_CACHE (mirrortab, c);
       syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
 
       /* is this a 1-char comment end sequence? if so, try
 	 to see if style matches previously extracted mask */
       if (code == Sendcomment)
 	{
+#ifndef SYNTAX_TABLES
+	  styles_match_p = SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask);
+	}
+
+      /* otherwise, is this a 2-char comment end sequence? */
+      else if (from >= stop
+	       && SYNTAX_END_P (mirrortab, c, BUF_FETCH_CHAR (buf, from+1)))
+	{
+	  code = Sendcomment;
+#endif /* ! SYNTAX_TABLES */
 	  styles_match_p =
+#ifndef SYNTAX_TABLES
+	    SYNTAX_STYLES_MATCH_END_P (mirrortab, c,
+				       BUF_FETCH_CHAR (buf, from+1),
+				       mask);
+#else /* SYNTAX_TABLES */
 	    SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
+#endif /* SYNTAX_TABLES */
 	}
 
       /* or are we looking at a 1-char comment start sequence
 	 of the style matching mask? */
+#ifndef SYNTAX_TABLES
+      else if (code == Scomment
+	       && SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask))
+  	{
+	  styles_match_p = 1;
+  	}
+  
+      /* or possibly, a 2-char comment start sequence */
+      else if (from >= stop
+	       && SYNTAX_STYLES_MATCH_START_P (mirrortab, c,
+					       BUF_FETCH_CHAR (buf, from+1),
+					       mask))
+#else /* SYNTAX_TABLES */
       else if (code == Scomment)
+#endif /* SYNTAX_TABLES */
 	{
+#ifndef SYNTAX_TABLES
+	  code = Scomment;
+	  styles_match_p = 1;
+#else /* SYNTAX_TABLES */
 	  styles_match_p =
 	    SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) & mask;
+#endif /* SYNTAX_TABLES */
 	}
 
+#ifdef SYNTAX_TABLES
       /* otherwise, is this a 2-char comment end or start sequence? */
       else if (from > stop)
 	do
@@ -711,6 +834,7 @@
 	      }
 	  } while (0);
 
+#endif /* SYNTAX_TABLES */
       /* Ignore escaped characters.  */
       if (char_quoted (buf, from))
 	continue;
@@ -727,6 +851,7 @@
 	    string_lossage = 1;
 	}
 
+#ifdef SYNTAX_TABLES
       if (code == Sstring_fence || code == Scomment_fence)
 	{
 	  parity ^= 1;
@@ -740,6 +865,7 @@
 	    string_lossage = 1;
 	}
 
+#endif /* SYNTAX_TABLES */
       /* Record comment-starters according to that
 	 quote-parity to the comment-end.  */
       if (code == Scomment && styles_match_p)
@@ -781,35 +907,57 @@
       scan_sexps_forward (buf, &state, find_defun_start (buf, comment_end),
 			  comment_end - 1, -10000, 0, Qnil, 0);
       if (state.incomment)
+#ifndef SYNTAX_TABLES
+	from = state.comstart;
+#else /* SYNTAX_TABLES */
 	from = state.comstr_start;
+#endif /* SYNTAX_TABLES */
       else
 	/* We can't grok this as a comment; scan it normally.  */
 	from = comment_end;
+#ifdef SYNTAX_TABLES
       UPDATE_SYNTAX_CACHE_FORWARD (from - 1);
+#endif /* SYNTAX_TABLES */
     }
   return from;
 }
 
 static Bufpos
+#ifndef SYNTAX_TABLES
+find_end_of_comment (struct buffer *buf, Bufpos from, Bufpos stop, int mask)
+#else /* SYNTAX_TABLES */
 find_end_of_comment (struct buffer *buf, Bufpos from, Bufpos stop, int comstyle)
+#endif /* SYNTAX_TABLES */
 {
   int c;
+#ifndef SYNTAX_TABLES
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#else /* SYNTAX_TABLES */
   int prev_code;
   /* mask to match comment styles against; for ST_COMMENT_STYLE, this
      will get set to SYNTAX_COMMENT_STYLE_B, but never get checked */
   int mask = comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
+#endif /* SYNTAX_TABLES */
 
+#ifdef SYNTAX_TABLES
   /* This is only called by functions which have already set up the
      syntax_cache and are keeping it up-to-date */
+#endif /* SYNTAX_TABLES */
   while (1)
     {
       if (from == stop)
 	{
 	  return -1;
 	}
+#ifdef SYNTAX_TABLES
 
       UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
       c = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+      if (SYNTAX_UNSAFE (mirrortab, c) == Sendcomment
+	  && SYNTAX_STYLES_MATCH_1CHAR_P (mirrortab, c, mask))
+#else /* SYNTAX_TABLES */
 
       /* Test for generic comments */
       if (comstyle == ST_COMMENT_STYLE)
@@ -829,33 +977,51 @@
 	if (SYNTAX_FROM_CACHE (mirrortab, c) == Sendcomment
 	    && SYNTAX_CODE_MATCHES_1CHAR_P
 	    (SYNTAX_CODE_FROM_CACHE (mirrortab, c), mask))
+#endif /* SYNTAX_TABLES */
 	/* we have encountered a comment end of the same style
 	   as the comment sequence which began this comment
 	   section */
+#ifndef SYNTAX_TABLES
+	break;
+#else /* SYNTAX_TABLES */
 	  {
 	    from++;
 	    UPDATE_SYNTAX_CACHE_FORWARD (from);
 	    break;
 	  }
+#endif /* SYNTAX_TABLES */
 
+#ifdef SYNTAX_TABLES
       prev_code = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
       from++;
+#ifdef SYNTAX_TABLES
       UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
       if (from < stop
+#ifndef SYNTAX_TABLES
+	  && SYNTAX_STYLES_MATCH_END_P (mirrortab, c,
+					BUF_FETCH_CHAR (buf, from), mask))
+#else /* SYNTAX_TABLES */
 	  && SYNTAX_CODES_MATCH_END_P
 	  (prev_code,
 	   SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from)),
 	   mask)
 
 	  )
+#endif /* SYNTAX_TABLES */
 	/* we have encountered a comment end of the same style
 	   as the comment sequence which began this comment
 	   section */
+#ifndef SYNTAX_TABLES
+	{ from++; break; }
+#else /* SYNTAX_TABLES */
 	{
 	  from++;
 	  UPDATE_SYNTAX_CACHE_FORWARD (from);
 	  break;
 	}
+#endif /* SYNTAX_TABLES */
     }
   return from;
 }
@@ -883,9 +1049,14 @@
   Bufpos stop;
   Emchar c;
   enum syntaxcode code;
+#ifdef SYNTAX_TABLES
   int syncode;
+#endif /* SYNTAX_TABLES */
   EMACS_INT n;
   struct buffer *buf = decode_buffer (buffer, 0);
+#ifndef SYNTAX_TABLES
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#endif /* ! SYNTAX_TABLES */
 
   if (NILP (count))
     n = 1;
@@ -897,7 +1068,9 @@
 
   from = BUF_PT (buf);
 
+#ifdef SYNTAX_TABLES
   SETUP_SYNTAX_CACHE (from, n);
+#endif /* SYNTAX_TABLES */
   while (n > 0)
     {
       QUIT;
@@ -905,7 +1078,11 @@
       stop = BUF_ZV (buf);
       while (from < stop)
 	{
+#ifndef SYNTAX_TABLES
+	  int mask = 0;         /* mask for finding matching comment style */
+#else /* SYNTAX_TABLES */
 	  int comstyle = 0;     /* mask for finding matching comment style */
+#endif /* SYNTAX_TABLES */
 
 	  if (char_quoted (buf, from))
 	    {
@@ -913,10 +1090,16 @@
 	      continue;
 	    }
 
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
 	  c = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, c);
 	  syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
 
 	  if (code == Scomment)
 	    {
@@ -925,13 +1108,33 @@
 		 we must record the comment style this character begins
 		 so that later, only a comment end of the same style actually
 		 ends the comment section */
+#ifndef SYNTAX_TABLES
+	      mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	      comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
 		== SYNTAX_COMMENT_STYLE_A ? 0 : 1;
+#endif /* SYNTAX_TABLES */
 	    }
 
+#ifndef SYNTAX_TABLES
+	  else if (from < stop
+		   && SYNTAX_START_P (mirrortab, c, BUF_FETCH_CHAR (buf, from+1)))
+#else /* SYNTAX_TABLES */
 	  else if (code == Scomment_fence)
+#endif /* SYNTAX_TABLES */
 	    {
+#ifndef SYNTAX_TABLES
+	      /* we have encountered a 2char comment start sequence and we
+		 are ignoring all text inside comments. we must record
+		 the comment style this sequence begins so that later,
+		 only a comment end of the same style actually ends
+		 the comment section */
+	      code = Scomment;
+	      mask = SYNTAX_COMMENT_MASK_START (mirrortab, c,
+						BUF_FETCH_CHAR (buf, from+1));
+#endif /* ! SYNTAX_TABLES */
 	      from++;
+#ifdef SYNTAX_TABLES
 	      code = Scomment;
 	      comstyle = ST_COMMENT_STYLE;
  	    }
@@ -958,11 +1161,18 @@
 		    == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
 		  from++;
 		}
+#endif /* SYNTAX_TABLES */
 	    }
 
 	  if (code == Scomment)
 	    {
+#ifndef SYNTAX_TABLES
+	      Bufpos newfrom;
+
+	      newfrom = find_end_of_comment (buf, from, stop, mask);
+#else /* SYNTAX_TABLES */
 	      Bufpos newfrom = find_end_of_comment (buf, from, stop, comstyle);
+#endif /* SYNTAX_TABLES */
 	      if (newfrom < 0)
 		{
 		  /* we stopped because from==stop */
@@ -995,7 +1205,11 @@
       stop = BUF_BEGV (buf);
       while (from > stop)
 	{
+#ifndef SYNTAX_TABLES
+          int mask = 0;         /* mask for finding matching comment style */
+#else /* SYNTAX_TABLES */
           int comstyle = 0;     /* mask for finding matching comment style */
+#endif /* SYNTAX_TABLES */
 
 	  from--;
 	  if (char_quoted (buf, from))
@@ -1005,21 +1219,46 @@
 	    }
 
 	  c = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, c);
 	  syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
 
 	  if (code == Sendcomment)
 	    {
 	      /* we have found a single char end comment. we must record
 		 the comment style encountered so that later, we can match
 		 only the proper comment begin sequence of the same style */
+#ifndef SYNTAX_TABLES
+	      mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	      comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
 		== SYNTAX_COMMENT_STYLE_A ? 0 : 1;
+#endif /* SYNTAX_TABLES */
 	    }
 
+#ifndef SYNTAX_TABLES
+	  else if (from > stop
+		   && SYNTAX_END_P (mirrortab, BUF_FETCH_CHAR (buf, from - 1), c)
+		   && !char_quoted (buf, from - 1))
+#else /* SYNTAX_TABLES */
 	  else if (code == Scomment_fence)
+#endif /* SYNTAX_TABLES */
 	    {
+#ifndef SYNTAX_TABLES
+	      /* We must record the comment style encountered so that
+		 later, we can match only the proper comment begin
+		 sequence of the same style.  */
+#endif /* ! SYNTAX_TABLES */
 	      code = Sendcomment;
+#ifndef SYNTAX_TABLES
+	      mask = SYNTAX_COMMENT_MASK_END (mirrortab,
+					      BUF_FETCH_CHAR (buf, from - 1),
+					      c);
+	      from--;
+#else /* SYNTAX_TABLES */
 	      comstyle = ST_COMMENT_STYLE;
 	    }
 
@@ -1041,17 +1280,27 @@
 		    (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
 		  from--;
 		}
+#endif /* SYNTAX_TABLES */
 	    }
 
 	  if (code == Sendcomment)
  	    {
+#ifndef SYNTAX_TABLES
+ 	      from = find_start_of_comment (buf, from, stop, mask);
+#else /* SYNTAX_TABLES */
  	      from = find_start_of_comment (buf, from, stop, comstyle);
+#endif /* SYNTAX_TABLES */
  	      break;
             }
 
 	  else if (code != Swhitespace
+#ifndef SYNTAX_TABLES
+		   && SYNTAX (mirrortab, c) != Scomment
+		   && SYNTAX (mirrortab, c) != Sendcomment)
+#else /* SYNTAX_TABLES */
 		   && code != Scomment
 		   && code != Sendcomment)
+#endif /* SYNTAX_TABLES */
 	    {
 	      BUF_SET_PT (buf, from + 1);
 	      return Qnil;
@@ -1075,12 +1324,20 @@
   int quoted;
   int mathexit = 0;
   enum syntaxcode code;
+#ifdef SYNTAX_TABLES
   int syncode;
+#endif /* SYNTAX_TABLES */
   int min_depth = depth;    /* Err out if depth gets less than this. */
+#ifndef SYNTAX_TABLES
+  Lisp_Object syntaxtab = buf->syntax_table;
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#endif /* ! SYNTAX_TABLES */
 
   if (depth > 0) min_depth = 0;
 
+#ifdef SYNTAX_TABLES
   SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, from, count);
+#endif /* SYNTAX_TABLES */
   while (count > 0)
     {
       QUIT;
@@ -1088,26 +1345,45 @@
       stop = BUF_ZV (buf);
       while (from < stop)
 	{
+#ifndef SYNTAX_TABLES
+          int mask = 0;         /* mask for finding matching comment style */
+#else /* SYNTAX_TABLES */
           int comstyle = 0;     /* mask for finding matching comment style */
+#endif /* SYNTAX_TABLES */
 
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
 	  c = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX_UNSAFE (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, c);
 	  syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
 	  from++;
 
 	  /* a 1-char comment start sequence */
 	  if (code == Scomment && parse_sexp_ignore_comments)
 	    {
+#ifndef SYNTAX_TABLES
+	      mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	      comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode) ==
 		SYNTAX_COMMENT_STYLE_A ? 0 : 1;
+#endif /* SYNTAX_TABLES */
 	    }
 
 	  /* else, a 2-char comment start sequence? */
 	  else if (from < stop
+#ifndef SYNTAX_TABLES
+		   && SYNTAX_START_P (mirrortab, c, BUF_FETCH_CHAR (buf, from))
+#else /* SYNTAX_TABLES */
 		   && SYNTAX_CODE_START_FIRST_P (syncode)
+#endif /* SYNTAX_TABLES */
 		   && parse_sexp_ignore_comments)
 	    {
+#ifdef SYNTAX_TABLES
 	      int next_syncode;
 	      UPDATE_SYNTAX_CACHE_FORWARD (from);
 	      next_syncode =
@@ -1115,20 +1391,32 @@
 
 	      if (SYNTAX_CODES_START_P (syncode, next_syncode))
 		{
+#endif /* SYNTAX_TABLES */
 	      /* we have encountered a comment start sequence and we
 		 are ignoring all text inside comments. we must record
 		 the comment style this sequence begins so that later,
 		 only a comment end of the same style actually ends
 		 the comment section */
 	      code = Scomment;
+#ifndef SYNTAX_TABLES
+	      mask = SYNTAX_COMMENT_MASK_START (mirrortab, c,
+						BUF_FETCH_CHAR (buf, from));
+#else /* SYNTAX_TABLES */
 		  comstyle = SYNTAX_CODES_COMMENT_MASK_START
 		    (syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
+#endif /* SYNTAX_TABLES */
 	      from++;
 	    }
+#ifdef SYNTAX_TABLES
 	    }
 	  UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
 
+#ifndef SYNTAX_TABLES
+	  if (SYNTAX_PREFIX_UNSAFE (mirrortab, c))
+#else /* SYNTAX_TABLES */
 	  if (SYNTAX_CODE_PREFIX (syncode))
+#endif /* SYNTAX_TABLES */
 	    continue;
 
 	  switch (code)
@@ -1144,9 +1432,13 @@
 	      /* This word counts as a sexp; return at end of it. */
 	      while (from < stop)
 		{
+#ifndef SYNTAX_TABLES
+		  switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
+#else /* SYNTAX_TABLES */
 		  UPDATE_SYNTAX_CACHE_FORWARD (from);
 		  switch (SYNTAX_FROM_CACHE (mirrortab,
 					     BUF_FETCH_CHAR (buf, from)))
+#endif /* SYNTAX_TABLES */
 		    {
 		    case Scharquote:
 		    case Sescape:
@@ -1164,15 +1456,23 @@
 		}
 	      goto done;
 
+#ifdef SYNTAX_TABLES
 	    case Scomment_fence:
 	      comstyle = ST_COMMENT_STYLE;
+#endif /* SYNTAX_TABLES */
 	    case Scomment:
 	      if (!parse_sexp_ignore_comments)
 		break;
+#ifdef SYNTAX_TABLES
 	      UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
 	      {
+#ifndef SYNTAX_TABLES
+		Bufpos newfrom = find_end_of_comment (buf, from, stop, mask);
+#else /* SYNTAX_TABLES */
 		Bufpos newfrom =
 		  find_end_of_comment (buf, from, stop, comstyle);
+#endif /* SYNTAX_TABLES */
 		if (newfrom < 0)
 		  {
 		    /* we stopped because from == stop in search forward */
@@ -1212,38 +1512,57 @@
 	      }
 	    break;
 
+#ifdef SYNTAX_TABLES
 	    case Sstring_fence:
+#endif /* SYNTAX_TABLES */
 	    case Sstring:
               {
+#ifdef SYNTAX_TABLES
 		Emchar stringterm;
 
 		if (code != Sstring_fence)
 		  {
+#endif /* SYNTAX_TABLES */
 		/* XEmacs change: call syntax_match on character */
                 Emchar ch = BUF_FETCH_CHAR (buf, from - 1);
+#ifndef SYNTAX_TABLES
+		Lisp_Object stermobj = syntax_match (syntaxtab, ch);
+		Emchar stringterm;
+#else /* SYNTAX_TABLES */
 		    Lisp_Object stermobj =
 		      syntax_match (syntax_cache.current_syntax_table, ch);
+#endif /* SYNTAX_TABLES */
 
 		if (CHARP (stermobj))
 		  stringterm = XCHAR (stermobj);
 		else
 		  stringterm = ch;
+#ifdef SYNTAX_TABLES
 		  }
 		else
 		  stringterm = '\0'; /* avoid compiler warnings */
+#endif /* SYNTAX_TABLES */
 
                 while (1)
 		  {
 		    if (from >= stop)
 		      goto lose;
+#ifndef SYNTAX_TABLES
+		    if (BUF_FETCH_CHAR (buf, from) == stringterm)
+#else /* SYNTAX_TABLES */
 		    UPDATE_SYNTAX_CACHE_FORWARD (from);
 		    c = BUF_FETCH_CHAR (buf, from);
 		    if (code == Sstring
 			? c == stringterm
 			: SYNTAX_FROM_CACHE (mirrortab, c) == Sstring_fence)
+#endif /* SYNTAX_TABLES */
 		      break;
+#ifndef SYNTAX_TABLES
+		    switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
+#else /* SYNTAX_TABLES */
 
 		    switch (SYNTAX_FROM_CACHE (mirrortab, c))
+#endif /* SYNTAX_TABLES */
 		      {
 		      case Scharquote:
 		      case Sescape:
@@ -1282,35 +1601,58 @@
       stop = BUF_BEGV (buf);
       while (from > stop)
 	{
+#ifndef SYNTAX_TABLES
+          int mask = 0;         /* mask for finding matching comment style */
+#else /* SYNTAX_TABLES */
           int comstyle = 0;     /* mask for finding matching comment style */
+#endif /* SYNTAX_TABLES */
 
 	  from--;
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_BACKWARD (from);
+#endif /* SYNTAX_TABLES */
           quoted = char_quoted (buf, from);
 	  if (quoted)
+#ifdef SYNTAX_TABLES
 	    {
+#endif /* SYNTAX_TABLES */
 	    from--;
+#ifdef SYNTAX_TABLES
 	      UPDATE_SYNTAX_CACHE_BACKWARD (from);
 	    }
+#endif /* SYNTAX_TABLES */
 
 	  c = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+	  code = SYNTAX_UNSAFE (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	  code = SYNTAX_FROM_CACHE (mirrortab, c);
 	  syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
 
 	  if (code == Sendcomment && parse_sexp_ignore_comments)
 	    {
 	      /* we have found a single char end comment. we must record
 		 the comment style encountered so that later, we can match
 		 only the proper comment begin sequence of the same style */
+#ifndef SYNTAX_TABLES
+	      mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab, c);
+#else /* SYNTAX_TABLES */
 	      comstyle = SYNTAX_CODE_COMMENT_1CHAR_MASK (syncode)
 		== SYNTAX_COMMENT_STYLE_A ? 0 : 1;
+#endif /* SYNTAX_TABLES */
 	    }
 
 	  else if (from > stop
+#ifndef SYNTAX_TABLES
+		   && SYNTAX_END_P (mirrortab, BUF_FETCH_CHAR (buf, from-1), c)
+#else /* SYNTAX_TABLES */
 		   && SYNTAX_CODE_END_SECOND_P (syncode)
+#endif /* SYNTAX_TABLES */
 		   && !char_quoted (buf, from - 1)
 		   && parse_sexp_ignore_comments)
 	    {
+#ifdef SYNTAX_TABLES
 	      int prev_syncode;
 	      UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
 	      prev_syncode = SYNTAX_CODE_FROM_CACHE
@@ -1318,17 +1660,30 @@
 
 	      if (SYNTAX_CODES_END_P (prev_syncode, syncode))
 		{
+#endif /* SYNTAX_TABLES */
 	      /* we must record the comment style encountered so that
 		 later, we can match only the proper comment begin
 		 sequence of the same style */
 	      code = Sendcomment;
+#ifndef SYNTAX_TABLES
+	      mask = SYNTAX_COMMENT_MASK_END (mirrortab,
+					      BUF_FETCH_CHAR (buf, from - 1),
+					      c);
+#else /* SYNTAX_TABLES */
 		  comstyle = SYNTAX_CODES_COMMENT_MASK_END
 		    (prev_syncode, syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
+#endif /* SYNTAX_TABLES */
 	      from--;
 	    }
+#ifdef SYNTAX_TABLES
 	    }
+#endif /* SYNTAX_TABLES */
 
+#ifndef SYNTAX_TABLES
+	  if (SYNTAX_PREFIX_UNSAFE (mirrortab, c))
+#else /* SYNTAX_TABLES */
 	  if (SYNTAX_CODE_PREFIX (syncode))
+#endif /* SYNTAX_TABLES */
 	    continue;
 
 	  switch (quoted ? Sword : code)
@@ -1340,15 +1695,23 @@
 		 passing it. */
 	      while (from > stop)
 		{
+#ifndef SYNTAX_TABLES
+		  enum syntaxcode syncode;
+#else /* SYNTAX_TABLES */
 		  UPDATE_SYNTAX_CACHE_BACKWARD (from);
+#endif /* SYNTAX_TABLES */
 		  quoted = char_quoted (buf, from - 1);
 
 		  if (quoted)
 		    from--;
 		  if (! (quoted
                          || (syncode =
+#ifndef SYNTAX_TABLES
+			     SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from - 1)))
+#else /* SYNTAX_TABLES */
 			     SYNTAX_FROM_CACHE (mirrortab,
 						BUF_FETCH_CHAR (buf, from - 1)))
+#endif /* SYNTAX_TABLES */
 			 == Sword
 			 || syncode == Ssymbol
 			 || syncode == Squote))
@@ -1384,36 +1747,57 @@
 	      }
 	    break;
 
+#ifdef SYNTAX_TABLES
 	    case Scomment_fence:
 	      comstyle = ST_COMMENT_STYLE;
+#endif /* SYNTAX_TABLES */
 	    case Sendcomment:
 	      if (parse_sexp_ignore_comments)
+#ifndef SYNTAX_TABLES
+		from = find_start_of_comment (buf, from, stop, mask);
+#else /* SYNTAX_TABLES */
 		from = find_start_of_comment (buf, from, stop, comstyle);
+#endif /* SYNTAX_TABLES */
 	      break;
 
+#ifdef SYNTAX_TABLES
 	    case Sstring_fence:
+#endif /* SYNTAX_TABLES */
 	    case Sstring:
               {
+#ifdef SYNTAX_TABLES
 		Emchar stringterm;
 
 		if (code != Sstring_fence)
 		  {
+#endif /* SYNTAX_TABLES */
 		/* XEmacs change: call syntax_match() on character */
                 Emchar ch = BUF_FETCH_CHAR (buf, from);
+#ifndef SYNTAX_TABLES
+		Lisp_Object stermobj = syntax_match (syntaxtab, ch);
+		Emchar stringterm;
+#else /* SYNTAX_TABLES */
 		    Lisp_Object stermobj =
 		      syntax_match (syntax_cache.current_syntax_table, ch);
+#endif /* SYNTAX_TABLES */
 
 		if (CHARP (stermobj))
 		  stringterm = XCHAR (stermobj);
 		else
 		  stringterm = ch;
+#ifdef SYNTAX_TABLES
 		  }
 		else
 		  stringterm = '\0'; /* avoid compiler warnings */
+#endif /* SYNTAX_TABLES */
 
                 while (1)
 		  {
 		    if (from == stop) goto lose;
+#ifndef SYNTAX_TABLES
+		    if (!char_quoted (buf, from - 1)
+			&& stringterm == BUF_FETCH_CHAR (buf, from - 1))
+#else /* SYNTAX_TABLES */
 
 		    UPDATE_SYNTAX_CACHE_BACKWARD (from - 1);
 		    c = BUF_FETCH_CHAR (buf, from - 1);
@@ -1423,9 +1807,12 @@
 			 : SYNTAX_FROM_CACHE (mirrortab, c) == Sstring_fence)
 			&& !char_quoted (buf, from - 1))
 		      {
+#endif /* SYNTAX_TABLES */
 		      break;
+#ifdef SYNTAX_TABLES
 		      }
 
+#endif /* SYNTAX_TABLES */
 		    from--;
 		  }
                 from--;
@@ -1460,13 +1847,24 @@
   enum syntaxcode code;
   Bufpos beg = BUF_BEGV (buf);
   int quoted = 0;
+#ifndef SYNTAX_TABLES
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#else /* SYNTAX_TABLES */
   Bufpos startpos = pos;
 
   while (pos > beg)
     {
       UPDATE_SYNTAX_CACHE_BACKWARD (pos - 1);
       code = SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, pos - 1));
+#endif /* SYNTAX_TABLES */
 
+#ifndef SYNTAX_TABLES
+  while (pos > beg
+	 && ((code = SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1)))
+	     == Scharquote
+	     || code == Sescape))
+    pos--, quoted = !quoted;
+#else /* SYNTAX_TABLES */
       if (code != Scharquote && code != Sescape)
 	break;
       pos--;
@@ -1474,6 +1872,7 @@
     }
 
   UPDATE_SYNTAX_CACHE (startpos);
+#endif /* SYNTAX_TABLES */
   return quoted;
 }
 
@@ -1549,18 +1948,27 @@
   struct buffer *buf = decode_buffer (buffer, 0);
   Bufpos beg = BUF_BEGV (buf);
   Bufpos pos = BUF_PT (buf);
+#ifdef SYNTAX_TABLES
 #ifndef emacs
+#endif /* SYNTAX_TABLES */
   Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#ifdef SYNTAX_TABLES
 #endif
   Emchar c = '\0'; /* initialize to avoid compiler warnings */
 
 
   SETUP_SYNTAX_CACHE_FOR_BUFFER (buf, pos, -1);
+#endif /* SYNTAX_TABLES */
 
   while (pos > beg && !char_quoted (buf, pos - 1)
+#ifndef SYNTAX_TABLES
+	 && (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1)) == Squote
+	     || SYNTAX_PREFIX (mirrortab, BUF_FETCH_CHAR (buf, pos - 1))))
+#else /* SYNTAX_TABLES */
 	 /* Previous statement updates syntax table.  */
 	 && (SYNTAX_FROM_CACHE (mirrortab, c = BUF_FETCH_CHAR (buf, pos - 1)) == Squote
 	     || SYNTAX_CODE_PREFIX (SYNTAX_CODE_FROM_CACHE (mirrortab, c))))
+#endif /* SYNTAX_TABLES */
     pos--;
 
   BUF_SET_PT (buf, pos);
@@ -1593,17 +2001,30 @@
 			   when the depth becomes negative.  */
   int mindepth;		/* Lowest DEPTH value seen.  */
   int start_quoted = 0;		/* Nonzero means starting after a char quote */
+#ifdef SYNTAX_TABLES
   int boundary_stop = commentstop == -1;
+#endif /* SYNTAX_TABLES */
   Lisp_Object tem;
+#ifndef SYNTAX_TABLES
+  int mask;				     /* comment mask */
+  Lisp_Object syntaxtab = buf->syntax_table;
+  Lisp_Char_Table *mirrortab = XCHAR_TABLE (buf->mirror_syntax_table);
+#endif /* ! SYNTAX_TABLES */
 
+#ifdef SYNTAX_TABLES
   SETUP_SYNTAX_CACHE (from, 1);
+#endif /* SYNTAX_TABLES */
   if (NILP (oldstate))
     {
       depth = 0;
       state.instring = -1;
       state.incomment = 0;
       state.comstyle = 0;	/* comment style a by default */
+#ifndef SYNTAX_TABLES
+      mask = SYNTAX_COMMENT_STYLE_A;
+#else /* SYNTAX_TABLES */
       state.comstr_start = -1;	/* no comment/string seen.  */
+#endif /* SYNTAX_TABLES */
     }
   else
     {
@@ -1617,12 +2038,21 @@
       oldstate = Fcdr (oldstate);
       oldstate = Fcdr (oldstate);
       tem = Fcar (oldstate);    /* elt 3, instring */
+#ifndef SYNTAX_TABLES
+      state.instring = !NILP (tem) ? XINT (tem) : -1;
+#else /* SYNTAX_TABLES */
       state.instring = ( !NILP (tem) 
 			 ? ( INTP (tem) ? XINT (tem) : ST_STRING_STYLE) 
 			 : -1);
+#endif /* SYNTAX_TABLES */
 
+#ifndef SYNTAX_TABLES
+      oldstate = Fcdr (oldstate); /* elt 4, incomment */
+      tem = Fcar (oldstate);
+#else /* SYNTAX_TABLES */
       oldstate = Fcdr (oldstate);
       tem = Fcar (oldstate);    /* elt 4, incomment */
+#endif /* SYNTAX_TABLES */
       state.incomment = !NILP (tem);
 
       oldstate = Fcdr (oldstate);
@@ -1630,10 +2060,15 @@
       start_quoted = !NILP (tem);
 
       /* if the eighth element of the list is nil, we are in comment style
+#ifndef SYNTAX_TABLES
+	 a. if it is non-nil, we are in comment style b */
+#else /* SYNTAX_TABLES */
 	 a; if it is t, we are in comment style b; if it is 'syntax-table,
 	 we are in a generic comment */
+#endif /* SYNTAX_TABLES */
       oldstate = Fcdr (oldstate);
       oldstate = Fcdr (oldstate);
+#ifdef SYNTAX_TABLES
       tem = Fcar (oldstate);    /* elt 7, comment style a/b/fence */
       state.comstyle = NILP (tem) ? 0 : ( EQ (tem, Qsyntax_table)
 					  ? ST_COMMENT_STYLE : 1 );
@@ -1644,7 +2079,13 @@
 
       /* elt 9, char numbers of starts-of-expression of levels
          (starting from outermost). */
+#endif /* SYNTAX_TABLES */
       oldstate = Fcdr (oldstate);
+#ifndef SYNTAX_TABLES
+      tem = Fcar (oldstate);    /* elt 8, comment style a */
+      state.comstyle = !NILP (tem);
+      mask = state.comstyle ? SYNTAX_COMMENT_STYLE_B : SYNTAX_COMMENT_STYLE_A;
+#else /* SYNTAX_TABLES */
       tem = Fcar (oldstate);    /* elt 9, intermediate data for
 				   continuation of parsing (subject
 				   to change). */
@@ -1657,6 +2098,7 @@
 	  curlevel->last = -1;
 	  tem = Fcdr (tem);
 	}
+#endif /* SYNTAX_TABLES */
     }
   state.quoted = 0;
   mindepth = depth;
@@ -1676,20 +2118,36 @@
 
   while (from < end)
     {
+#ifdef SYNTAX_TABLES
       Emchar c;
       int syncode;
 
+#endif /* SYNTAX_TABLES */
       QUIT;
 
+#ifndef SYNTAX_TABLES
+      code = SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from));
+#else /* SYNTAX_TABLES */
       UPDATE_SYNTAX_CACHE_FORWARD (from);
       c = BUF_FETCH_CHAR (buf, from);
       code = SYNTAX_FROM_CACHE (mirrortab, c);
       syncode = SYNTAX_CODE_FROM_CACHE (mirrortab, c);
+#endif /* SYNTAX_TABLES */
       from++;
 
+#ifndef SYNTAX_TABLES
+      if (code == Scomment)
+	{
+#endif /* ! SYNTAX_TABLES */
 	  /* record the comment style we have entered so that only the
 	     comment-ender sequence (or single char) of the same style
 	     actually terminates the comment section. */
+#ifndef SYNTAX_TABLES
+	  mask = SYNTAX_COMMENT_1CHAR_MASK (mirrortab,
+					    BUF_FETCH_CHAR (buf, from-1));
+	  state.comstyle = (mask == SYNTAX_COMMENT_STYLE_B);
+	  state.comstart = from - 1;
+#else /* SYNTAX_TABLES */
       if (code == Scomment)
 	{
 	  state.comstyle =
@@ -1704,9 +2162,14 @@
 	  state.comstyle = ST_COMMENT_STYLE;
 	  state.comstr_start = from - 1;
 	  code = Scomment;
+#endif /* SYNTAX_TABLES */
 	}
 
       else if (from < end &&
+#ifndef SYNTAX_TABLES
+	       SYNTAX_START_P (mirrortab, BUF_FETCH_CHAR (buf, from-1),
+			       BUF_FETCH_CHAR (buf, from)))
+#else /* SYNTAX_TABLES */
 	       SYNTAX_CODE_START_FIRST_P (syncode))
 	{
 	  int next_syncode;
@@ -1715,17 +2178,37 @@
 	    SYNTAX_CODE_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from));
 
 	  if (SYNTAX_CODES_START_P (syncode, next_syncode))
+#endif /* SYNTAX_TABLES */
 	{
+#ifndef SYNTAX_TABLES
+	  /* Record the comment style we have entered so that only
+	     the comment-end sequence of the same style actually
+	     terminates the comment section.  */
+#endif /* ! SYNTAX_TABLES */
 	  code = Scomment;
+#ifndef SYNTAX_TABLES
+	  mask = SYNTAX_COMMENT_MASK_START (mirrortab,
+                                            BUF_FETCH_CHAR (buf, from-1),
+					    BUF_FETCH_CHAR (buf, from));
+	  state.comstyle = (mask == SYNTAX_COMMENT_STYLE_B);
+	  state.comstart = from-1;
+#else /* SYNTAX_TABLES */
 	      state.comstyle = SYNTAX_CODES_COMMENT_MASK_START
 		(syncode, next_syncode) == SYNTAX_COMMENT_STYLE_A ? 0 : 1;
 	      state.comstr_start = from - 1;
+#endif /* SYNTAX_TABLES */
 	  from++;
+#ifdef SYNTAX_TABLES
 	      UPDATE_SYNTAX_CACHE_FORWARD (from);
 	    }
+#endif /* SYNTAX_TABLES */
 	}
 
+#ifndef SYNTAX_TABLES
+      if (SYNTAX_PREFIX (mirrortab, BUF_FETCH_CHAR (buf, from - 1)))
+#else /* SYNTAX_TABLES */
       if (SYNTAX_CODE_PREFIX (syncode))
+#endif /* SYNTAX_TABLES */
 	continue;
       switch (code)
 	{
@@ -1745,8 +2228,12 @@
 	symstarted:
 	  while (from < end)
 	    {
+#ifndef SYNTAX_TABLES
+	      switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
+#else /* SYNTAX_TABLES */
 	      UPDATE_SYNTAX_CACHE_FORWARD (from);
 	      switch (SYNTAX_FROM_CACHE (mirrortab, BUF_FETCH_CHAR (buf, from)))
+#endif /* SYNTAX_TABLES */
 		{
 		case Scharquote:
 		case Sescape:
@@ -1768,13 +2255,25 @@
 
 	case Scomment:
 	  state.incomment = 1;
+#ifdef SYNTAX_TABLES
 	  if (commentstop || boundary_stop) goto done;
+#endif /* SYNTAX_TABLES */
 	startincomment:
+#ifndef SYNTAX_TABLES
+	  if (commentstop)
+#else /* SYNTAX_TABLES */
 	  if (commentstop == 1)
+#endif /* SYNTAX_TABLES */
 	    goto done;
+#ifdef SYNTAX_TABLES
 	  UPDATE_SYNTAX_CACHE_FORWARD (from);
+#endif /* SYNTAX_TABLES */
 	  {
+#ifndef SYNTAX_TABLES
+	    Bufpos newfrom = find_end_of_comment (buf, from, end, mask);
+#else /* SYNTAX_TABLES */
 	    Bufpos newfrom = find_end_of_comment (buf, from, end, state.comstyle);
+#endif /* SYNTAX_TABLES */
 	    if (newfrom < 0)
 	      {
 		/* we terminated search because from == end */
@@ -1785,7 +2284,11 @@
 	  }
 	  state.incomment = 0;
 	  state.comstyle = 0;		     /* reset the comment style */
+#ifndef SYNTAX_TABLES
+	  mask = 0;
+#else /* SYNTAX_TABLES */
 	  if (boundary_stop) goto done;
+#endif /* SYNTAX_TABLES */
 	  break;
 
 	case Sopen:
@@ -1811,33 +2314,58 @@
 	  break;
 
 	case Sstring:
+#ifndef SYNTAX_TABLES
+          {
+            Emchar ch;
+#else /* SYNTAX_TABLES */
 	case Sstring_fence:
 	  state.comstr_start = from - 1;
+#endif /* SYNTAX_TABLES */
             if (stopbefore) goto stop; /* this arg means stop at sexp start */
             curlevel->last = from - 1;
+#ifndef SYNTAX_TABLES
+	    /* XEmacs change: call syntax_match() on character */
+            ch = BUF_FETCH_CHAR (buf, from - 1);
+#else /* SYNTAX_TABLES */
 	  if (code == Sstring_fence)
 	    {
 	      state.instring = ST_STRING_STYLE;
 	    }
 	  else
+#endif /* SYNTAX_TABLES */
 	    {
+#ifndef SYNTAX_TABLES
+	      Lisp_Object stermobj = syntax_match (syntaxtab, ch);
+#else /* SYNTAX_TABLES */
 	      /* XEmacs change: call syntax_match() on character */
 	      Emchar ch = BUF_FETCH_CHAR (buf, from - 1);
 	      Lisp_Object stermobj =
 		syntax_match (syntax_cache.current_syntax_table, ch);
+#endif /* SYNTAX_TABLES */
 
 	      if (CHARP (stermobj))
 		state.instring = XCHAR (stermobj);
 	      else
 		state.instring = ch;
+#ifndef SYNTAX_TABLES
+	    }
+#endif /* ! SYNTAX_TABLES */
           }
+#ifdef SYNTAX_TABLES
 	  if (boundary_stop) goto done;
+#endif /* SYNTAX_TABLES */
 	startinstring:
 	  while (1)
 	    {
+#ifdef SYNTAX_TABLES
 	      enum syntaxcode temp_code;
 
+#endif /* SYNTAX_TABLES */
 	      if (from >= end) goto done;
+#ifndef SYNTAX_TABLES
+	      if (BUF_FETCH_CHAR (buf, from) == state.instring) break;
+	      switch (SYNTAX (mirrortab, BUF_FETCH_CHAR (buf, from)))
+#else /* SYNTAX_TABLES */
 
 	      UPDATE_SYNTAX_CACHE_FORWARD (from);
 	      c = BUF_FETCH_CHAR (buf, from);
@@ -1849,11 +2377,14 @@
 		  c == state.instring) break;
 
 	      switch (temp_code)
+#endif /* SYNTAX_TABLES */
 		{
+#ifdef SYNTAX_TABLES
 		case Sstring_fence:
 		  if (state.instring == ST_STRING_STYLE)
 		    goto string_end;
 		  break;
+#endif /* SYNTAX_TABLES */
 		case Scharquote:
 		case Sescape:
                   {
@@ -1867,11 +2398,15 @@
 		}
 	      from++;
 	    }
+#ifdef SYNTAX_TABLES
 	string_end:
+#endif /* SYNTAX_TABLES */
 	  state.instring = -1;
 	  curlevel->prev = curlevel->last;
 	  from++;
+#ifdef SYNTAX_TABLES
 	  if (boundary_stop) goto done;
+#endif /* SYNTAX_TABLES */
 	  break;
 
 	case Smath:
@@ -1881,7 +2416,9 @@
         case Spunct:
         case Squote:
         case Sendcomment:
+#ifdef SYNTAX_TABLES
 	case Scomment_fence:
+#endif /* SYNTAX_TABLES */
 	case Sinherit:
         case Smax:
           break;
@@ -1902,10 +2439,12 @@
   state.prevlevelstart
     = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
   state.location = from;
+#ifdef SYNTAX_TABLES
   state.levelstarts = Qnil;
   while (--curlevel >= levelstart)
     state.levelstarts = Fcons (make_int (curlevel->last),
 			       state.levelstarts);
+#endif /* SYNTAX_TABLES */
 
   *stateptr = state;
 }
@@ -1916,31 +2455,51 @@
  point is set to where parsing stops.
 If fifth arg OLDSTATE is omitted or nil,
  parsing assumes that FROM is the beginning of a function.
+#ifndef SYNTAX_TABLES
+Value is a list of eight elements describing final state of parsing:
+#else /* SYNTAX_TABLES */
 Value is a list of nine elements describing final state of parsing:
+#endif /* SYNTAX_TABLES */
  0. depth in parens.
  1. character address of start of innermost containing list; nil if none.
  2. character address of start of last complete sexp terminated.
  3. non-nil if inside a string.
+#ifndef SYNTAX_TABLES
+    (It is the character that will terminate the string.)
+#else /* SYNTAX_TABLES */
     (It is the character that will terminate the string,
      or t if the string should be terminated by an explicit
      `syntax-table' property.)
+#endif /* SYNTAX_TABLES */
  4. t if inside a comment.
  5. t if following a quote character.
  6. the minimum paren-depth encountered during this scan.
+#ifndef SYNTAX_TABLES
+ 7. nil if in comment style a, or not in a comment; t if in comment style b
+#else /* SYNTAX_TABLES */
  7. nil if in comment style a, or not in a comment; t if in comment style b;
     `syntax-table' if given by an explicit `syntax-table' property.
  8. character address of start of last comment or string; nil if none.
  9. Intermediate data for continuation of parsing (subject to change).
+#endif /* SYNTAX_TABLES */
 If third arg TARGETDEPTH is non-nil, parsing stops if the depth
 in parentheses becomes equal to TARGETDEPTH.
 Fourth arg STOPBEFORE non-nil means stop when come to
  any character that starts a sexp.
+#ifndef SYNTAX_TABLES
+Fifth arg OLDSTATE is an eight-element list like what this function returns.
+#else /* SYNTAX_TABLES */
 Fifth arg OLDSTATE is a nine-element list like what this function returns.
+#endif /* SYNTAX_TABLES */
 It is used to initialize the state of the parse.  Its second and third
 elements are ignored.
+#ifndef SYNTAX_TABLES
+Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
+#else /* SYNTAX_TABLES */
 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment. If it
 is `syntax-table', stop after the start of a comment or a string, or after
 the end of a comment or string.
+#endif /* SYNTAX_TABLES */
 */
        (from, to, targetdepth, stopbefore, oldstate, commentstop, buffer))
 {
@@ -1961,24 +2520,37 @@
   get_buffer_range_char (buf, from, to, &start, &end, 0);
   scan_sexps_forward (buf, &state, start, end,
 		      target, !NILP (stopbefore), oldstate,
+#ifndef SYNTAX_TABLES
+		      !NILP (commentstop));
+
+#else /* SYNTAX_TABLES */
 		      (NILP (commentstop)
 		       ? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1)));
+#endif /* SYNTAX_TABLES */
   BUF_SET_PT (buf, state.location);
 
   /* reverse order */
   val = Qnil;
+#ifndef SYNTAX_TABLES
+  val = Fcons (state.comstyle  ? Qt : Qnil, val);
+#else /* SYNTAX_TABLES */
   val = Fcons (state.levelstarts, val);
   val = Fcons ((state.incomment || (state.instring >= 0))
 	       ? make_int (state.comstr_start) : Qnil, val);
   val = Fcons (state.comstyle  ? (state.comstyle == ST_COMMENT_STYLE
 				  ? Qsyntax_table : Qt) : Qnil, val);
+#endif /* SYNTAX_TABLES */
   val = Fcons (make_int (state.mindepth),   val);
   val = Fcons (state.quoted    ? Qt : Qnil, val);
   val = Fcons (state.incomment ? Qt : Qnil, val);
+#ifndef SYNTAX_TABLES
+  val = Fcons (state.instring       < 0 ? Qnil : make_int (state.instring),       val);
+#else /* SYNTAX_TABLES */
   val = Fcons (state.instring < 0
 	       ? Qnil
 	       : (state.instring == ST_STRING_STYLE
 		  ? Qt : make_int (state.instring)), val);
+#endif /* SYNTAX_TABLES */
   val = Fcons (state.thislevelstart < 0 ? Qnil : make_int (state.thislevelstart), val);
   val = Fcons (state.prevlevelstart < 0 ? Qnil : make_int (state.prevlevelstart), val);
   val = Fcons (make_int (state.depth), val);
@@ -2075,7 +2647,9 @@
 syms_of_syntax (void)
 {
   defsymbol (&Qsyntax_table_p, "syntax-table-p");
+#ifdef SYNTAX_TABLES
   defsymbol (&Qsyntax_table, "syntax-table");
+#endif /* SYNTAX_TABLES */
 
   DEFSUBR (Fsyntax_table_p);
   DEFSUBR (Fsyntax_table);
@@ -2105,6 +2679,7 @@
 */ );
   parse_sexp_ignore_comments = 0;
 
+#ifdef SYNTAX_TABLES
   DEFVAR_BOOL ("lookup-syntax-properties", &lookup_syntax_properties /*
 Non-nil means `forward-sexp', etc., grant `syntax-table' property.
 The value of this property should be either a syntax table, or a cons
@@ -2114,6 +2689,7 @@
 */ );
   lookup_syntax_properties = 1;
 
+#endif /* SYNTAX_TABLES */
   DEFVAR_BOOL ("words-include-escapes", &words_include_escapes /*
 Non-nil means `forward-word', etc., should treat escape chars part of words.
 */ );
Index: src/syntax.h
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/syntax.h,v
retrieving revision 1.5
diff -u -r1.5 syntax.h
--- src/syntax.h	2001/04/12 18:24:21	1.5
+++ src/syntax.h	2002/08/29 05:35:03
@@ -61,10 +61,12 @@
   Scomment,	/* a comment-starting character */
   Sendcomment,	/* a comment-ending character */
   Sinherit,	/* use the standard syntax table for this character */
+#ifdef SYNTAX_TABLES
   Scomment_fence, /* Starts/ends comment which is delimited on the
 		     other side by a char with the same syntaxcode.  */
   Sstring_fence,  /* Starts/ends string which is delimited on the
 		     other side by a char with the same syntaxcode.  */
+#endif /* SYNTAX_TABLES */
   Smax	 /* Upper bound on codes that are meaningful */
 };
 
@@ -258,13 +260,18 @@
 
 extern int no_quit_in_re_search;
 extern struct buffer *regex_emacs_buffer;
+#ifndef SYNTAX_TABLES
+extern int regex_emacs_buffer_p;
+#else /* SYNTAX_TABLES */
 
 /* This is the string or buffer in which we are matching.  It is used
    for looking up syntax properties.  */
 extern Lisp_Object regex_match_object;
+#endif /* SYNTAX_TABLES */
 
 void update_syntax_table (Lisp_Char_Table *ct);
 
+#ifdef SYNTAX_TABLES
 #ifdef emacs
 
 extern int lookup_syntax_properties;
@@ -473,4 +480,5 @@
        : 0)))
 
 
+#endif /* SYNTAX_TABLES */
 #endif /* INCLUDED_syntax_h_ */
