[Nickle]printf formatting codes
Keith Packard
keithp@keithp.com
Wed, 07 Mar 2001 10:55:17 -0800
Nickle currently uses a variety of different formatting codes for printing
values, they're pretty randomly scattered through the alphabet and mean
different things for different values. We need to normalize their
meaning and then fix the code.
Here's what we've got today:
%b base = 2
%x base = 16
%X base = 16
%o base = 8
int
%c print a character
else print using base
integer:
print using base
rational:
%v numerator '/' denominator
%f integer '.' fraction
%e integer '.' fraction
else integer '.' fixed-part '{' repeating-part '}'
float:
%e mant 'E' exponent
%f integer '.' fraction
else choose between 'e' and 'f' depending on exponent
array
%g '[' dimensions ']' '{' contents '}'
%v '[' dimensions ']' '{' contents '}'
else contents
string
%s contents
else '"' escaped-contents '"'
struct
%v '{' name = value ',' ... '}'
else name = value ...
It seems like there should be some general requirements:
%v should print in a format parsable by the lexer
%e should print numbers in exponential form
%f should print numbers in non-exponential form
%d should probably be like %f? Or integer part only?
%g should print in a human readable format
%c should print a character
Should the printing function typecheck the arguments against the format
letter?
-keith