Re: operator characters
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: operator characters
- From: withoff (David Withoff)
- Date: Thu, 26 May 1994 15:25:47 -0500
> Mathematica's parsing of symbols is claimed to be simple. There are > operator characters and text characters, where the latter are defined > as any character that is not the former. So, what I'd like is the > definitive list of operator characters. Should I use those characters > in the special forms list in appendix A? What characters other than > space qualify as a space? > > What I'd really like is a Mathematica built-in function that tests > for an operator character (OperatorQ?). Then if Mathematica ever > extends or contracts its set of operator characters, I wouldn't have > to worry about it. (This is for a simple parser as part of a $PreRead > function.) > > In the meantime though, I'd like to see the definitive list. I could > conclude from another part of appendix A that the operators are any > ASCII printable character that's not a letter, digit, or $. However, > I know that that's not complete, since tab can be a space. So what > else is missing? Carriage return? Line feed? Backspace maybe? > > Mark Adler > madler at cco.caltech.edu Symbol names can include any characters other than character 7 (bell), character 9 (tab), characters 10, 12, and 13 (return, formfeed, and newline, in various permutations, depending on your computer), and characters from 32 through 127 other than 36 ($), 48-57 (numbers), 65-90 (uppercase letters), 96 (backquote), and 97-122 (lowercase letters). Symbol names cannot start with a number or end with a backquote (`) character, and cannot contain adjacent backquote characters. Other than that, anything goes, including non-printing characters and multi-byte characters. In[9]:= SymbolCharacterQ[p_String] := With[{s = StringJoin["a", p, "z"]}, SyntaxQ[s] && ToHeldExpression[s][[1,0]] === Symbol ] In[10]:= First256Characters = Table[FromCharacterCode[k], {k, 0, 255}] ; In[11]:= ops = Select[First256Characters, (!SymbolCharacterQ[#]) &] ; In[12]:= Map[{ToCharacterCode[#], InputForm[#]} &, ops] //TableForm Out[12]//TableForm= 7 "\007" 9 "\t" 10 "\n" 12 "\f" 13 "\r" 32 " " 33 "!" 34 "\"" 35 "#" 37 "%" 38 "&" 39 "'" 40 "(" 41 ")" 42 "*" 43 "+" 44 "," 45 "-" 46 "." 47 "/" 58 ":" 59 ";" 60 "<" 61 "=" 62 ">" 63 "?" 64 "@" 91 "[" 92 "\\" 93 "]" 94 "^" 95 "_" 123 "{" 124 "|" 125 "}" 126 "~" 127 "\177" You can presumably produce an OperatorQ function using the same basic idea. Although the operator characters may very well be used in different ways in future versions of Mathematica, it is unlikely that the set of operator characters will change, since all of the obvious operator characters have already been used. Dave Withoff Research and Development Wolfram Research