changeset 1497:48a0b289f1be

[project @ 1995-09-30 22:04:27 by jwe]
author jwe
date Sat, 30 Sep 1995 22:06:19 +0000
parents 8bd5499ae4ef
children f079328d7a2e
files src/Makefile.in src/lex.l
diffstat 2 files changed, 132 insertions(+), 192 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.in	Sat Sep 30 21:57:45 1995 +0000
+++ b/src/Makefile.in	Sat Sep 30 22:06:19 1995 +0000
@@ -59,9 +59,9 @@
 
 INCLUDES := arith-ops.h builtins.h defaults.h.in defun.h defun-dld.h \
 	defun-int.h dirfns.h dynamic-ld.h error.h file-info.h \
-	file-io.h fnmatch.h \
-	getopt.h gripes.h help.h idx-vector.h input.h lex.h \
-	load-save.h mappers.h missing-math.h octave.h octave-hist.h \
+	file-io.h fnmatch.h getopt.h gripes.h help.h idx-vector.h \
+	input.h lex.h load-save.h mappers.h missing-math.h \
+	oct-gperf.h octave.h octave-hist.h \
 	oct-map.h oct-obj.h oct-str.h pager.h parse.h pathlen.h \
 	pathsearch.h pr-output.h procstream.h sighandlers.h \
 	statdefs.h symtab.h sysdep.h sysdir.h systime.h syswait.h \
@@ -188,19 +188,19 @@
 
 maintainer-clean: distclean
 	rm -f tags TAGS y.tab.c y.tab.h y.output yy.lex.c \
-	lex.cc parse.cc
+	lex.cc parse.cc oct-gperf.h
 .PHONY: maintainer-clean
 
-local-dist: parse.cc lex.cc
+local-dist: parse.cc lex.cc oct-gperf.h
 	ln $(DISTFILES) ../`cat ../.fname`/src
 	rm -f parse.cc lex.cc y.tab.h y.output yy.lex.c
-	rm -f lex.cc parse.cc defaults.h *.d *.def
+	rm -f oct-gperf.h defaults.h *.d *.def
 .PHONY: local-dist
 
-dist: parse.cc lex.cc
+dist: parse.cc lex.cc oct-gperf.h
 	ln $(DISTFILES) ../`cat ../.fname`/src
 	rm -f parse.cc lex.cc y.tab.h y.output yy.lex.c
-	rm -f lex.cc parse.cc defaults.h *.d *.def builtins.cc
+	rm -f oct-gperf.h defaults.h *.d *.def builtins.cc
 .PHONY: dist
 
 # Special rules -- these files need special things to be defined.
@@ -230,6 +230,11 @@
 	  -e "s;%CXXLIB_PATH%;\"${CXXLIB_PATH}\";")
 	@$(top_srcdir)/move-if-change $@.tmp $@
 
+oct-gperf.h: octave.gperf
+	gperf -a -C -E -H octave_kw_hash -g -N octave_kw_lookup -p -t \
+	  $< > $@.tmp
+	@$(top_srcdir)/move-if-change $@.tmp $@
+
 extract_stat = sed 's/@l@//g; s/@L@//g; /@LSTAT_ONLY@/d'
 extract_lstat = sed 's/@l@/l/g; s/@L@/L/g; s/	*@LSTAT_ONLY@//'
 
--- a/src/lex.l	Sat Sep 30 21:57:45 1995 +0000
+++ b/src/lex.l	Sat Sep 30 22:06:19 1995 +0000
@@ -37,6 +37,12 @@
 
 #include "SLStack.h"
 
+// These would be alphabetical, but y.tab.h must be included before
+// oct-gperf.h and y.tab.h must be included after token.h and the tree
+// class declarations.  We can't include y.tab.h in oct-gperf.h
+// because it may not be protected to allow it to be included multiple
+// times.
+
 #include "error.h"
 #include "input.h"
 #include "lex.h"
@@ -54,6 +60,7 @@
 #include "utils.h"
 #include "variables.h"
 #include "y.tab.h"
+#include "oct-gperf.h"
 
 // Stack to hold tokens so that we can delete them when the parser is
 // reset and avoid growing forever just because we are stashing some
@@ -931,195 +938,123 @@
   int l = input_line_number;
   int c = current_input_column;
 
-// XXX FIXME XXX -- this has really become too large a list to search
-// like this...
+  int len = strlen (s);
 
-  int end_found = 0;
-  if (strcmp ("break", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return BREAK;
-    }
-  else if (strcmp ("continue", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return CONTINUE;
-    }
-  else if (strcmp ("else", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return ELSE;
-    }
-  else if (strcmp ("elseif", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return ELSEIF;
-    }
-  else if (strcmp ("end", s) == 0)
-    {
-      end_found = 1;
-      yylval.tok_val = new token (token::simple_end, l, c);
-      token_stack.push (yylval.tok_val);
-    }
-  else if (strcmp ("endfor", s) == 0)
-    {
-      end_found = 1;
-      yylval.tok_val = new token (token::for_end, l, c);
-      token_stack.push (yylval.tok_val);
-    }
-  else if (strcmp ("endfunction", s) == 0)
-    {
-      end_found = 1;
-      yylval.tok_val = new token (token::function_end, l, c);
-      token_stack.push (yylval.tok_val);
-    }
-  else if (strcmp ("endif", s) == 0)
-    {
-      end_found = 1;
-      yylval.tok_val = new token (token::if_end, l, c);
-      token_stack.push (yylval.tok_val);
-    }
-  else if (strcmp ("endwhile", s) == 0)
-    {
-      end_found = 1;
-      yylval.tok_val = new token (token::while_end, l, c);
-      token_stack.push (yylval.tok_val);
-    }
-  else if (strcmp ("for", s) == 0)
-    {
-      promptflag--;
-      looping++;
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return FOR;
-    }
-  else if (strcmp ("function", s) == 0)
-    {
-      if (defining_func)
-	{
-	  error ("function keyword invalid within a function body");
+  const octave_kw *kw = octave_kw_lookup (s, len);
 
-	  if ((reading_fcn_file || reading_script_file)
-	      && curr_fcn_file_name)
-	    error ("defining new function near line %d of file `%s.m'",
-		   input_line_number, curr_fcn_file_name);
-	  else
-	    error ("defining new function near line %d", input_line_number);
-
-	  return LEXICAL_ERROR;
-	}
-      else
-	{
-	  tmp_local_sym_tab = new symbol_table ();
-	  curr_sym_tab = tmp_local_sym_tab;
-	  defining_func = 1;
-	  promptflag--;
-	  beginning_of_function = 1;
-	  if (! (reading_fcn_file || reading_script_file))
-	    input_line_number = 1;
-	  return FCN;
-	}
-    }
-  else if (strcmp ("global", s) == 0)
+  if (kw)
     {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return GLOBAL;
-    }
-  else if (strcmp ("gplot", s) == 0)
-    {
-      plotting = 1;
-      yylval.tok_val = new token (token::two_dee, l, c);
-      token_stack.push (yylval.tok_val);
-      return PLOT;
-    }
-  else if (strcmp ("gsplot", s) == 0)
-    {
-      plotting = 1;
-      yylval.tok_val = new token (token::three_dee, l, c);
-      token_stack.push (yylval.tok_val);
-      return PLOT;
-    }
-  else if (strcmp ("replot", s) == 0)
-    {
-      plotting = 1;
-      yylval.tok_val = new token (token::replot, l, c);
+      yylval.tok_val = 0;
+
+      switch (kw->kw_id)
+	{
+	case all_va_args_kw:
+	case break_kw:
+	case catch_kw:
+	case continue_kw:
+	case else_kw:
+	case elseif_kw:
+	case global_kw:
+	case return_kw:
+	case unwind_protect_cleanup_kw:
+ 	  break;
+
+	case end_kw:
+	  yylval.tok_val = new token (token::simple_end, l, c);
+	  break;
+
+	case end_try_catch_kw:
+	  yylval.tok_val = new token (token::try_catch_end, l, c);
+	  break;
+
+	case end_unwind_protect_kw:
+	  yylval.tok_val = new token (token::unwind_protect_end, l, c);
+	  break;
+
+	case endfor_kw:
+	  yylval.tok_val = new token (token::for_end, l, c);
+	  break;
+
+	case endfunction_kw:
+	  yylval.tok_val = new token (token::function_end, l, c);
+	  break;
+
+	case endif_kw:
+	  yylval.tok_val = new token (token::if_end, l, c);
+	  break;
+
+	case endwhile_kw:
+	  yylval.tok_val = new token (token::while_end, l, c);
+	  break;
+
+	case for_kw:
+	case while_kw:
+	  promptflag--;
+	  looping++;
+	  break;
+
+	case if_kw:
+	  iffing++;
+	  promptflag--;
+	  break;
+
+	case try_kw:
+	case unwind_protect_kw:
+	  promptflag--;
+	  break;
+
+	case gplot_kw:
+	  plotting = 1;
+	  yylval.tok_val = new token (token::two_dee, l, c);
+	  break;
+
+	case gsplot_kw:
+	  plotting = 1;
+	  yylval.tok_val = new token (token::three_dee, l, c);
+	  break;
+
+	case replot_kw:
+	  plotting = 1;
+	  yylval.tok_val = new token (token::replot, l, c);
+	  break;
+
+	case function_kw:
+	  if (defining_func)
+	    {
+	      error ("function keyword invalid within a function body");
+
+	      if ((reading_fcn_file || reading_script_file)
+		  && curr_fcn_file_name)
+		error ("defining new function near line %d of file `%s.m'",
+		       input_line_number, curr_fcn_file_name);
+	      else
+		error ("defining new function near line %d", input_line_number);
+
+	      return LEXICAL_ERROR;
+	    }
+	  else
+	    {
+	      tmp_local_sym_tab = new symbol_table ();
+	      curr_sym_tab = tmp_local_sym_tab;
+	      defining_func = 1;
+	      promptflag--;
+	      beginning_of_function = 1;
+	      if (! (reading_fcn_file || reading_script_file))
+		input_line_number = 1;
+	    }
+	  break;
+
+	default:
+	  panic_impossible ();
+	}
+
+      if (! yylval.tok_val)
+	yylval.tok_val = new token (l, c);
+
       token_stack.push (yylval.tok_val);
-      return PLOT;
-    }
-  else if (strcmp ("if", s) == 0)
-    {
-      iffing++;
-      promptflag--;
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return IF;
-    }
-  else if (strcmp ("return", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return FUNC_RET;
-    }
-  else if (strcmp ("while", s) == 0)
-    {
-      promptflag--;
-      looping++;
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return WHILE;
+
+      return kw->tok;
     }
-  else if (strcmp ("unwind_protect", s) == 0)
-    {
-      promptflag--;
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return UNWIND;
-    }
-  else if (strcmp ("unwind_protect_cleanup", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return CLEANUP;
-    }
-  else if (strcmp ("end_unwind_protect", s) == 0)
-    {
-      end_found = 1;
-      yylval.tok_val = new token (token::unwind_protect_end, l, c);
-      token_stack.push (yylval.tok_val);
-    }
-  else if (strcmp ("try", s) == 0)
-    {
-      promptflag--;
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return TRY;
-    }
-  else if (strcmp ("catch", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return CATCH;
-    }
-  else if (strcmp ("end_try_catch", s) == 0)
-    {
-      end_found = 1;
-      yylval.tok_val = new token (token::try_catch_end, l, c);
-      token_stack.push (yylval.tok_val);
-    }
-  else if (strcmp ("all_va_args", s) == 0)
-    {
-      yylval.tok_val = new token (l, c);
-      token_stack.push (yylval.tok_val);
-      return ALL_VA_ARGS;
-    }
-
-  if (end_found)
-    return END;
 
   return 0;
 }