1 /* 2 This file is part of GNU APL, a free implementation of the 3 ISO/IEC Standard 13751, "Programming Language APL, Extended" 4 5 Copyright (C) 2008-2015 Dr. Jürgen Sauermann 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef __QUAD_TF_HH_DEFINED__ 22 #define __QUAD_TF_HH_DEFINED__ 23 24 #include "QuadFunction.hh" 25 26 //----------------------------------------------------------------------------- 27 /** The system function Quad-TF (Transfer Form). */ 28 /// The class implementing ⎕TF 29 class Quad_TF : public QuadFunction 30 { 31 public: 32 /// Constructor. Quad_TF()33 Quad_TF() : QuadFunction(TOK_Quad_TF) {} 34 35 /// Overloaded Function::eval_AB(). 36 virtual Token eval_AB(Value_P A, Value_P B); 37 38 static Quad_TF * fun; ///< Built-in function. 39 static Quad_TF _fun; ///< Built-in function. 40 41 /// return true if val contains an 1⎕TF or 2⎕TF record 42 static bool is_inverse(const UCS_string & maybe_name); 43 44 /// return B in transfer format 1 (old APL format) 45 static Value_P tf1(const UCS_string & symbol_name); 46 47 /// return B in transfer format 2 (new APL2 format) 48 static Token tf2(const UCS_string & symbol_name); 49 50 /// return B in transfer format 3 (APL2 CDR format) 51 static Value_P tf3(const UCS_string & symbol_name); 52 53 /// append \b shape in tf2_format to \b ucs. Return true if (A⍴ was appended 54 static bool tf2_shape(UCS_string & ucs, const Shape & shape); 55 56 /// append ravel of \b value in tf2_format to \b ucs. Return true on error 57 static bool tf2_value(int level, UCS_string & ucs, Value_P value); 58 59 /// try inverse ⎕TF2 of ucs, set \b new_var_or_fun if successful 60 static UCS_string tf2_inv(const UCS_string & ravel); 61 62 /// store B in transfer format 2 (new APL format) into \b ucs 63 static void tf2_fun_ucs(UCS_string & ucs, const UCS_string & fun_name, 64 const Function & fun); 65 66 /// store simple character vector \b vec in \b ucs, either as 67 /// 'xxx' or as (UCS nn nnn ...) 68 static void tf2_char_vec(UCS_string & ucs, const UCS_string & vec); 69 70 /// undo ⎕UCS() created by tf2_char_vec 71 static UCS_string no_UCS(const UCS_string & ucs); 72 73 protected: 74 /// return B in transfer format 1 (old APL format) for a variable 75 static Value_P tf1(const UCS_string & var_name, Value_P val); 76 77 /// return B in transfer format 1 (old APL format) for a function 78 static Value_P tf1(const UCS_string & fun_name, const Function & fun); 79 80 /// return inverse transfer format 1 (old APL format) for a variable 81 static Value_P tf1_inv(const UCS_string & ravel); 82 83 /// return B in transfer format 2 (new APL format) for a variable 84 static Token tf2_var(const UCS_string & var_name, Value_P val); 85 86 /// simplify tos by removing UCS nnn etc. 87 static void tf2_simplify(Token_string & tos); 88 89 /// replace ⎕UCS n... by the corresponding Unicodes, 90 static void tf2_remove_UCS(Token_string & tos); 91 92 /// replace A ⍴ B by a reshaped B 93 static void tf2_remove_RHO(Token_string & tos, int & progress); 94 95 /// replace , B by a reshaped B 96 static void tf2_remove_COMMA(Token_string & tos, int & progress); 97 98 /// replace ⍴ ⊂ B by ⍴ enclosed B 99 static void tf2_remove_ENCLOSE1(Token_string & tos, int & progress); 100 101 /// replace ( ⊂ B ) by an enclosed B 102 static void tf2_remove_ENCLOSE(Token_string & tos, int & progress); 103 104 /// replace ⊂ ⊂ B by ⊂ B 105 static void tf2_remove_ENCLOSE_ENCLOSE(Token_string & tos, int & progress); 106 107 /// replace N - ⎕IO - ⍳ K by N N+1 ... N+K-1 108 static void tf2_remove_sequence(Token_string & tos, int & progress); 109 110 /// replace N - M × ⎕IO - ⍳ K by M × (N N+1 ... N+K-1) 111 static void tf2_remove_sequence1(Token_string & tos, int & progress); 112 113 /// replace ( value ) by value 114 static void tf2_remove_parentheses(Token_string & tos, int & progress); 115 116 /// replace value1 value2 by value 117 static void tf2_glue(Token_string & tos, int & progress); 118 119 /// return B in transfer format 2 (new APL format) for a function 120 static UCS_string tf2_fun(const UCS_string & fun_name, const Function & fun); 121 }; 122 //----------------------------------------------------------------------------- 123 #endif // __QUAD_TF_HH_DEFINED__ 124