changeset 430:8464d5778a09

[project @ 1994-05-25 08:33:54 by jwe]
author jwe
date Wed, 25 May 1994 08:33:54 +0000
parents f23cd37a0013
children f437f10ddb71
files src/lex.l src/user-prefs.cc src/user-prefs.h
diffstat 3 files changed, 213 insertions(+), 147 deletions(-) [+]
line wrap: on
line diff
--- a/src/lex.l	Wed May 25 06:39:43 1994 +0000
+++ b/src/lex.l	Wed May 25 08:33:54 1994 +0000
@@ -46,6 +46,7 @@
 // one of the macros defined there uses token_stack.
 static SLStack <token*> token_stack;
 
+#include "user-prefs.h"
 #include "variables.h"
 #include "octave.h"
 #include "symtab.h"
@@ -351,6 +352,9 @@
 <MATRIX>{SN}*\]{S}*	{
 			  fixup_column_count (yytext);
 
+// It's a pain in the ass to decide whether to insert a comma after
+// seeing a ']' character...
+
 			  in_brace_or_paren.pop ();
 			  braceflag--;
 			  if (braceflag == 0)
@@ -359,7 +363,7 @@
 				promptflag++;
 			      BEGIN 0;
 			    }
-			  else
+			  else if (user_pref.commas_in_literal_matrix != 2)
 			    {
 			      int c0 = yytext[yyleng-1];
 			      int spc_prev = (c0 == ' ' || c0 == '\t');
@@ -377,7 +381,7 @@
 				     && in_brace_or_paren.top ()
 				     && convert_spaces_to_comma)
 				{
-				  unput (','); /* XXX */
+				  unput (',');
 				  return ']';
 				}
 			    }
@@ -391,14 +395,20 @@
 <MATRIX>{S}*\,{S}*	{ TOK_RETURN (','); }
 
 <MATRIX>{S}+		{
-			  int bin_op = next_token_is_bin_op (1, yytext);
-			  int postfix_un_op
-			    = next_token_is_postfix_unary_op (1, yytext);
+
+// If commas are required, just eat the spaces.
 
- 			  if (! (postfix_un_op || bin_op)
-			      && in_brace_or_paren.top ()
-			      && convert_spaces_to_comma)
-			    TOK_RETURN (','); /* XXX */
+			  if (user_pref.commas_in_literal_matrix != 2)
+			    {
+			      int bin_op = next_token_is_bin_op (1, yytext);
+			      int postfix_un_op
+				= next_token_is_postfix_unary_op (1, yytext);
+
+			      if (! (postfix_un_op || bin_op)
+				  && in_brace_or_paren.top ()
+				  && convert_spaces_to_comma)
+				TOK_RETURN (',');
+			    }
 			}
 
 <MATRIX>{SN}*\;{SN}*	|
@@ -1444,7 +1454,9 @@
 
 // Check to see if we should insert a comma.
 
-  if (! in_brace_or_paren.empty () && in_brace_or_paren.top ()) 
+  if (user_pref.commas_in_literal_matrix != 2
+      && ! in_brace_or_paren.empty ()
+      && in_brace_or_paren.top ()) 
     {
       int c0 = yytext[yyleng-1];
       int spc_prev = (c0 == ' ' || c0 == '\t');
@@ -1456,11 +1468,12 @@
       int c1 = yyinput ();
       unput (c1);
       int other_op = match_any (c1, ",;\n]");
-
-      int index_op = (! spc_prev && c1 == '(');
+      int index_op = (c1 == '('
+		      && (user_pref.commas_in_literal_matrix == 0
+			  || ! spc_prev));
 
       if (! (postfix_un_op || bin_op || other_op || index_op))
-	unput (','); /* XXX */
+	unput (',');
     }
 
   return NAME;
--- a/src/user-prefs.cc	Wed May 25 06:39:43 1994 +0000
+++ b/src/user-prefs.cc	Wed May 25 08:33:54 1994 +0000
@@ -64,6 +64,57 @@
 }
 
 /*
+ * Should commas be required to separate elements in a literal matrix
+ * list?
+ *
+ *   user specifies   value of pref
+ *   --------------   -------------
+ *   "required"             2
+ *   "traditional"          1
+ *   anything else          0
+ *
+ * Octave will never insert a comma in a literal matrix list if the
+ * user specifies "required".  For example, the statement [1 2] will
+ * result in an error instead of being treated the same as [1, 2].
+ *
+ * Traditional behavior makes Octave convert spaces to a comma between
+ * identifiers and `('.  For example, the statement
+ *
+ *   [eye (2)]
+ *
+ * will be parsed as
+ *
+ *   [eye, (2)]
+ *
+ * and will result in an error since the eye function will be
+ * called with no arguments.  To get around this, you would have to
+ * omit the space between `eye' and the `('.
+ *
+ * The default value is 0, which results in behavior that is the same
+ * as traditional, except that Octave does not convert spaces to a
+ * comma between identifiers and `('.  For example, the statement
+ *
+ *   [eye (2)]
+ *
+ * will result in a call to linspace with the argument `2'. 
+ */
+int
+commas_in_literal_matrix (void)
+{
+  int pref = 0;
+  char *val = builtin_string_variable ("commas_in_literal_matrix");
+  if (val != (char *) NULL)
+    {
+      if (strncmp (val, "required", 8) == 0)
+	pref = 2;
+      else if (strncmp (val, "traditional", 11) == 0)
+	pref = 1;
+    }
+  user_pref.commas_in_literal_matrix = pref;
+  return 0;
+}
+
+/*
  * Should we allow assignments like:
  *
  *   octave> A(1) = 3; A(2) = 5
@@ -93,6 +144,30 @@
 }
 
 /*
+ * Should Octave always check to see if function files have changed
+ * since they were last compiled?
+ */
+int
+ignore_function_time_stamp (void)
+{
+  int pref = 0;
+
+  char *val = builtin_string_variable ("ignore_function_time_stamp");
+
+  if (val != (char *) NULL)
+    {
+      if (strncmp (val, "all", 3) == 0)
+	pref = 2;
+      if (strncmp (val, "system", 6) == 0)
+	pref = 1;
+    }
+
+  user_pref.ignore_function_time_stamp = pref;
+
+  return 0;
+}
+
+/*
  * Should we allow things like:
  *
  *   octave> 'abc' + 0
@@ -123,6 +198,18 @@
 }
 
 /*
+ * If possible, send all output intended for the screen through the
+ * pager. 
+ */
+int
+page_screen_output (void)
+{
+  user_pref.page_screen_output = check_str_pref ("page_screen_output");
+
+  return 0;
+}
+
+/*
  * When doing assignments like:
  *
  *   octave> A(1) = 3; A(2) = 5
@@ -174,6 +261,18 @@
 }
 
 /*
+ * Should we also print the dimensions of empty matrices?
+ */
+int
+print_empty_dimensions (void)
+{
+  user_pref.print_empty_dimensions =
+    check_str_pref ("print_empty_dimensions");
+
+  return 0;
+}
+
+/*
  * Should operations on empty matrices return empty matrices or an
  * error?
  */
@@ -187,18 +286,6 @@
 }
 
 /*
- * Should we also print the dimensions of empty matrices?
- */
-int
-print_empty_dimensions (void)
-{
-  user_pref.print_empty_dimensions =
-    check_str_pref ("print_empty_dimensions");
-
-  return 0;
-}
-
-/*
  * When doing assignments, should we resize matrices if the indices
  * are outside the current bounds?
  */
@@ -237,30 +324,6 @@
 }
 
 /*
- * Should Octave always check to see if function files have changed
- * since they were last compiled?
- */
-int
-ignore_function_time_stamp (void)
-{
-  int pref = 0;
-
-  char *val = builtin_string_variable ("ignore_function_time_stamp");
-
-  if (val != (char *) NULL)
-    {
-      if (strncmp (val, "all", 3) == 0)
-	pref = 2;
-      if (strncmp (val, "system", 6) == 0)
-	pref = 1;
-    }
-
-  user_pref.ignore_function_time_stamp = pref;
-
-  return 0;
-}
-
-/*
  * Should should big matrices be split into smaller slices for output?
  */
 int
@@ -288,6 +351,24 @@
 }
 
 /*
+ * Generate a warning for the assignment in things like
+ *
+ *   octave> if (a = 2 < n)
+ *
+ * but not
+ *
+ *   octave> if ((a = 2) < n)
+ */
+int
+warn_assign_as_truth_value (void)
+{
+  user_pref.warn_assign_as_truth_value =
+    check_str_pref ("warn_assign_as_truth_value");
+
+  return 0;
+}
+
+/*
  * Generate a warning for the comma in things like
  *
  *   octave> global a, b = 2
@@ -312,36 +393,6 @@
   return 0;
 }
 
-/*
- * Generate a warning for the assignment in things like
- *
- *   octave> if (a = 2 < n)
- *
- * but not
- *
- *   octave> if ((a = 2) < n)
- */
-int
-warn_assign_as_truth_value (void)
-{
-  user_pref.warn_assign_as_truth_value =
-    check_str_pref ("warn_assign_as_truth_value");
-
-  return 0;
-}
-
-/*
- * If possible, send all output intended for the screen through the
- * pager. 
- */
-int
-page_screen_output (void)
-{
-  user_pref.page_screen_output = check_str_pref ("page_screen_output");
-
-  return 0;
-}
-
 int
 set_output_max_field_width (void)
 {
@@ -430,19 +481,39 @@
 }
 
 int
-sv_loadpath (void)
+sv_editor (void)
 {
   int status = 0;
 
-  char *s = builtin_string_variable ("LOADPATH");
+  char *s = builtin_string_variable ("EDITOR");
   if (s != (char *) NULL)
     {
-      delete [] user_pref.loadpath;
-      user_pref.loadpath = s;
+      delete [] user_pref.editor;
+      user_pref.editor = s;
     }
   else
     {
-      warning ("invalid value specified for LOADPATH");
+      warning ("invalid value specified for EDITOR");
+      status = -1;
+    }
+
+  return status;
+}
+
+int
+sv_gnuplot_binary (void)
+{
+  int status = 0;
+
+  char *s = builtin_string_variable ("gnuplot_binary");
+  if (s != (char *) NULL)
+    {
+      delete [] user_pref.gnuplot_binary;
+      user_pref.gnuplot_binary = s;
+    }
+  else
+    {
+      warning ("invalid value specified for gnuplot_binary");
       status = -1;
     }
 
@@ -470,19 +541,39 @@
 }
 
 int
-sv_editor (void)
+sv_loadpath (void)
 {
   int status = 0;
 
-  char *s = builtin_string_variable ("EDITOR");
+  char *s = builtin_string_variable ("LOADPATH");
   if (s != (char *) NULL)
     {
-      delete [] user_pref.editor;
-      user_pref.editor = s;
+      delete [] user_pref.loadpath;
+      user_pref.loadpath = s;
     }
   else
     {
-      warning ("invalid value specified for EDITOR");
+      warning ("invalid value specified for LOADPATH");
+      status = -1;
+    }
+
+  return status;
+}
+
+int
+sv_pager_binary (void)
+{
+  int status = 0;
+
+  char *s = builtin_string_variable ("PAGER");
+  if (s != (char *) NULL)
+    {
+      delete [] user_pref.pager_binary;
+      user_pref.pager_binary = s;
+    }
+  else
+    {
+      warning ("invalid value specified for PAGER");
       status = -1;
     }
 
@@ -549,46 +640,6 @@
   return status;
 }
 
-int
-sv_gnuplot_binary (void)
-{
-  int status = 0;
-
-  char *s = builtin_string_variable ("gnuplot_binary");
-  if (s != (char *) NULL)
-    {
-      delete [] user_pref.gnuplot_binary;
-      user_pref.gnuplot_binary = s;
-    }
-  else
-    {
-      warning ("invalid value specified for gnuplot_binary");
-      status = -1;
-    }
-
-  return status;
-}
-
-int
-sv_pager_binary (void)
-{
-  int status = 0;
-
-  char *s = builtin_string_variable ("PAGER");
-  if (s != (char *) NULL)
-    {
-      delete [] user_pref.pager_binary;
-      user_pref.pager_binary = s;
-    }
-  else
-    {
-      warning ("invalid value specified for PAGER");
-      status = -1;
-    }
-
-  return status;
-}
-
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/user-prefs.h	Wed May 25 06:39:43 1994 +0000
+++ b/src/user-prefs.h	Wed May 25 08:33:54 1994 +0000
@@ -26,73 +26,75 @@
 
 struct user_preferences
 {
+  int commas_in_literal_matrix;
   int do_fortran_indexing;
   int empty_list_elements_ok;
+  int ignore_function_time_stamp;
   int implicit_str_to_num_ok;
   int ok_to_lose_imaginary_part;
+  int output_max_field_width;
+  int output_precision;
+  int page_screen_output;
   int prefer_column_vectors;
   int prefer_zero_one_indexing;
   int print_answer_id_name;
+  int print_empty_dimensions;
   int propagate_empty_matrices;
-  int print_empty_dimensions;
   int resize_on_range_error;
   int return_last_computed_value;
+  int save_precision;
   int silent_functions;
-  int ignore_function_time_stamp;
   int split_long_rows;
   int treat_neg_dim_as_zero;
+  int warn_assign_as_truth_value;
   int warn_comma_in_global_decl;
   int warn_divide_by_zero;
-  int warn_assign_as_truth_value;
-  int page_screen_output;
-  int output_max_field_width;
-  int output_precision;
-  int save_precision;
 
-  char *loadpath;
+  char *editor;
+  char *gnuplot_binary;
   char *info_file;
-  char *editor;
+  char *loadpath;
+  char *pager_binary;
   char *ps1;
   char *ps2;
   char *pwd;
-  char *gnuplot_binary;
-  char *pager_binary;
 };
 
 extern user_preferences user_pref;
 
+extern int commas_in_literal_matrix (void);
 extern int do_fortran_indexing (void);
 extern int empty_list_elements_ok (void);
+extern int ignore_function_time_stamp (void);
 extern int implicit_str_to_num_ok (void);
 extern int ok_to_lose_imaginary_part (void);
+extern int page_screen_output (void);
 extern int prefer_column_vectors (void);
 extern int prefer_zero_one_indexing (void);
 extern int print_answer_id_name (void);
+extern int print_empty_dimensions (void);
 extern int propagate_empty_matrices (void);
-extern int print_empty_dimensions (void);
 extern int resize_on_range_error (void);
 extern int return_last_computed_value (void);
 extern int silent_functions (void);
-extern int ignore_function_time_stamp (void);
 extern int split_long_rows (void);
 extern int treat_neg_dim_as_zero (void);
+extern int warn_assign_as_truth_value (void);
 extern int warn_comma_in_global_decl (void);
 extern int warn_divide_by_zero (void);
-extern int warn_assign_as_truth_value (void);
-extern int page_screen_output (void);
 
 extern int set_output_max_field_width (void);
 extern int set_output_precision (void);
 extern int set_save_precision (void);
 
-extern int sv_loadpath (void);
+extern int sv_editor (void);
+extern int sv_gnuplot_binary (void);
 extern int sv_info_file (void);
-extern int sv_editor (void);
+extern int sv_loadpath (void);
 extern int sv_pager_binary (void);
 extern int sv_ps1 (void);
 extern int sv_ps2 (void);
 extern int sv_pwd (void);
-extern int sv_gnuplot_binary (void);
 
 #endif