tags:

views:

139

answers:

3

Hello, I'm new at Bison, but in C/C++ no and at this time of development and regular expressions i never heard something like this, only the \n that's used for a new line, but i want to know what is the explanation of \t%.10g, that in the code is like this:

line:     '\n'
        | exp '\n'  { printf ("\t%.10g\n", $1); }
;

Best Regards.

+3  A: 

Have a look at the printf reference to decode the pattern:

g Use the shorter of %e or %f

e Scientific notation (mantise/exponent) using e character

f Decimal floating point

Thus, %.10g prints a decimal number with ten significant digits.

Konrad Rudolph
Actually, there is a slight difference between %g and [either %e or %f]: the precision specifies the number of significant digits, for [%e or %f] it specifies the number of digits after the decimal point.
avakar
+5  A: 

It means "print a tab character (\t) followed by a floating point number with 10 decimal places, either in scientific or fixed point notation depending on the order of magnitude (%.10g), followed by a newline (\n)".

Drew Hall
Thanks very much!
Nathan Campos
@Nathan: You betcha! Good luck with Bison!
Drew Hall
+2  A: 

It's not a regex but a printf format specification : Print a tab character followed by a floating point number with 10 digits behind the decimal point, either %f (floating point notation) way or %e (scientific notatation) way, whichever is shorter, and end with a newline.

man printf
fvu