📄 bc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>bc</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_000_153"> </a>NAME</h4><blockquote>bc - arbitrary-precision arithmetic language</blockquote><h4><a name = "tag_000_000_154"> </a>SYNOPSIS</h4><blockquote><pre><code>bc <b>[</b>-l<b>] [</b><i>file</i> ...<b>]</b></code></pre></blockquote><h4><a name = "tag_000_000_155"> </a>DESCRIPTION</h4><blockquote>The<i>bc</i>utility implements an arbitrary precision calculator.It takes input from any files given, then reads from the standard input.If the standard input and standard output to<i>bc</i>are attachedto a terminal, the invocation of<i>bc</i>is considered to be<i>interactive</i>,causing behavioural constraints described in the following sections.</blockquote><h4><a name = "tag_000_000_156"> </a>OPTIONS</h4><blockquote>The<i>bc</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> .<p>The following option is supported:<dl compact><dt><b>-l</b><dd>(The letter ell.)Define the math functions and initialise<b>scale</b>to 20, instead of the default zero.See the EXTENDED DESCRIPTION section.</dl></blockquote><h4><a name = "tag_000_000_157"> </a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><i>file</i><dd>A pathname of a text file containing<i>bc</i>program statements.After all cases of<i>file</i>have been read,<i>bc</i>will read the standard input.</dl></blockquote><h4><a name = "tag_000_000_158"> </a>STDIN</h4><blockquote>See the INPUT FILES section.</blockquote><h4><a name = "tag_000_000_159"> </a>INPUT FILES</h4><blockquote>Input files must be text files containing a sequence of comments,statements and function definitionsthat will be executed as they are read.</blockquote><h4><a name = "tag_000_000_160"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>bc</i>:<dl compact><dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard error.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES</i>.</dl></blockquote><h4><a name = "tag_000_000_161"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_000_000_162"> </a>STDOUT</h4><blockquote>The output of the<i>bc</i>utility is controlled by the program read,and consists of zero ormore lines containing the value of all executedexpressions without assignments.The radix and precision of the output are controlledby the values of the<b>obase</b>and<b>scale</b>variables.See the EXTENDED DESCRIPTION section.</blockquote><h4><a name = "tag_000_000_163"> </a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_000_000_164"> </a>OUTPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_000_165"> </a>EXTENDED DESCRIPTION</h4><blockquote><h5><a name = "tag_000_000_165_001"> </a>Grammar</h5>The grammar in this section and the lexicalconventions in the following section together describe the syntax for<i>bc</i>programs.The general conventions for this style of grammar are described in<xref href=grammar></xref>.A valid program can be represented as the non-terminal symbol<b>program</b>in the grammar.This formal syntax takes precedence overthe preceding text syntax description.<p><table <tr valign=top><th align=left>%token<th align=left>EOF NEWLINE STRING LETTER NUMBER<tr valign=top><td align=left>%token<td align=left>MUL_OP<tr valign=top><td align=left>/*<td align=left>'*', '/', '%' */<tr valign=top><td align=left>%token<td align=left>ASSIGN_OP<tr valign=top><td align=left>/*<td align=left>'=', '+=', '-=', '*=', '/=', '%=', '^=' */<tr valign=top><td align=left>%token<td align=left>REL_OP<tr valign=top><td align=left>/*<td align=left>'==', '<=', '>=', '!=', '<', '>' */<tr valign=top><td align=left>%token<td align=left>INCR_DECR<tr valign=top><td align=left>/*<td align=left>'++', '--' */<tr valign=top><td align=left>%token<td align=left> Define Break Quit Length<tr valign=top><td align=left>/*<td align=left>'define', 'break', 'quit', 'length' */<tr valign=top><td align=left>%token<td align=left> Return For If While Sqrt<tr valign=top><td align=left>/*<td align=left>'return', 'for', 'if', 'while', 'sqrt' */<tr valign=top><td align=left>%token<td align=left> Scale Ibase Obase Auto<tr valign=top><td align=left>/*<td align=left>'scale', 'ibase', 'obase', 'auto' */<tr valign=top><td align=left>%start<td align=left>program</table><p><table <tr valign=top><th align=left>%%<tr valign=top><td align=left>program<td align=left>:<td align=center>EOF<tr valign=top><td align=left><td align=left>|<td align=center>input_item program<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>input_item<td align=left>:<td align=center>semicolon_list NEWLINE<tr valign=top><td align=left><td align=left>|<td align=center>function<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>semicolon_list<td align=left>:<td align=center>/* empty */<tr valign=top><td align=left><td align=left>|<td align=center>statement<tr valign=top><td align=left><td align=left>|<td align=center>semicolon_list ';' statement<tr valign=top><td align=left><td align=left>|<td align=center>semicolon_list ';'<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>statement_list<td align=left>:<td align=center>/* empty */<tr valign=top><td align=left><td align=left>|<td align=center>statement<tr valign=top><td align=left><td align=left>|<td align=center>statement_list NEWLINE<tr valign=top><td align=left><td align=left>|<td align=center>statement_list NEWLINE statement<tr valign=top><td align=left><td align=left>|<td align=center>statement_list ';'<tr valign=top><td align=left><td align=left>|<td align=center>statement_list ';' statement<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>statement<td align=left>:<td align=center>expression<tr valign=top><td align=left><td align=left>|<td align=center>STRING<tr valign=top><td align=left><td align=left>|<td align=center>Break<tr valign=top><td align=left><td align=left>|<td align=center>Quit<tr valign=top><td align=left><td align=left>|<td align=center>Return<tr valign=top><td align=left><td align=left>|<td align=center>Return '(' return_expression ')'<tr valign=top><td align=left><td align=left>|<td align=center>For '(' expression ';'<tr valign=top><td align=left><td align=left><td align=center> relational_expression ';'<tr valign=top><td align=left><td align=left><td align=center> expression ')' statement<tr valign=top><td align=left><td align=left>|<td align=center>If '(' relational_expression ')' statement<tr valign=top><td align=left><td align=left>|<td align=center>While '(' relational_expression ')' statement<tr valign=top><td align=left><td align=left>|<td align=center>'{' statement_list '}'<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>function<td align=left>:<td align=center>Define LETTER '(' opt_parameter_list ')'<tr valign=top><td align=left><td align=left><td align=center> '{' NEWLINE opt_auto_define_list<tr valign=top><td align=left><td align=left><td align=center> statement_list '}'<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>opt_parameter_list<td align=left>:<td align=center>/* empty */<tr valign=top><td align=left><td align=left>|<td align=center>parameter_list<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>parameter_list<td align=left>:<td align=center>LETTER<tr valign=top><td align=left><td align=left>|<td align=center>define_list ',' LETTER<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>opt_auto_define_list<td align=left>:<td align=center>/* empty */<tr valign=top><td align=left><td align=left>|<td align=center>Auto define_list NEWLINE<tr valign=top><td align=left><td align=left>|<td align=center>Auto define_list ';'<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>define_list<td align=left>:<td align=center>LETTER<tr valign=top><td align=left><td align=left>|<td align=center>LETTER '[' ']'<tr valign=top><td align=left><td align=left>|<td align=center>define_list ',' LETTER<tr valign=top><td align=left><td align=left>|<td align=center>define_list ',' LETTER '[' ']'<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>opt_argument_list<td align=left>:<td align=center>/* empty */<tr valign=top><td align=left><td align=left>|<td align=center>argument_list<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>argument_list<td align=left>:<td align=center>expression<tr valign=top><td align=left><td align=left>|<td align=center>argument_list ',' expression<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>relational_expression<td align=left>:<td align=center>expression<tr valign=top><td align=left><td align=left>|<td align=center>expression REL_OP expression<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>return_expression<td align=left>:<td align=center>/* empty */<tr valign=top><td align=left><td align=left>|<td align=center>expression<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>expression<td align=left>:<td align=center>named_expression<tr valign=top><td align=left><td align=left>|<td align=center>NUMBER<tr valign=top><td align=left><td align=left>|<td align=center>'(' expression ')'<tr valign=top><td align=left><td align=left>|<td align=center>LETTER '(' opt_argument_list ')'<tr valign=top><td align=left><td align=left>|<td align=center>'-' expression<tr valign=top><td align=left><td align=left>|<td align=center>expression '+' expression<tr valign=top><td align=left><td align=left>|<td align=center>expression '-' expression<tr valign=top><td align=left><td align=left>|<td align=center>expression MUL_OP expression<tr valign=top><td align=left><td align=left>|<td align=center>expression '^' expression<tr valign=top><td align=left><td align=left>|<td align=center>INCR_DECR named_expression<tr valign=top><td align=left><td align=left>|<td align=center>named_expression INCR_DECR<tr valign=top><td align=left><td align=left>|<td align=center>named_expression ASSIGN_OP expression<tr valign=top><td align=left><td align=left>|<td align=center>Length '(' expression ')'<tr valign=top><td align=left><td align=left>|<td align=center>Sqrt '(' expression ')'<tr valign=top><td align=left><td align=left>|<td align=center>Scale '(' expression ')'<tr valign=top><td align=left><td align=left>;<tr valign=top><td align=left>named_expression<td align=left>:<td align=center>LETTER<tr valign=top><td align=left><td align=left>|<td align=center>LETTER '[' expression ']'<tr valign=top><td align=left><td align=left>|<td align=center>Scale<tr valign=top><td align=left><td align=left>|<td align=center>Ibase<tr valign=top><td align=left><td align=left>|<td align=center>Obase<tr valign=top><td align=left><td align=left>;</table><h5><a name = "tag_000_000_165_002"> </a>Lexical Conventions in bc</h5><xref type="5" name="bclex"></xref>The lexical conventions for<i>bc</i>programs, with respect to the preceding grammar, are as follows:<ol><p><li>Except as noted,<i>bc</i>recognises the longest possibletoken or delimiter beginning at a given point.<p><li>A comment consists of any characters beginning with the twoadjacent characters /* and terminated by the next occurrence ofthe two adjacent characters */.Comments have no effect except to delimit lexical tokens.<p><li>The characternewlineis recognised as the token<b>NEWLINE</b>.<br><p><li>The token<b>STRING</b>represents a string constant; it consists ofany characters beginning with the double-quote character( )and terminated byanother occurrence of the double-quote character.The value of the stringis the sequence of all characters between, but not including, thetwo double-quote characters.All characters are taken literally from theinput, and there is no way to specify a string containing a double-quotecharacter.The length of the value of each string is limited to{BC_STRING_MAX}bytes.<p><li>A blank characterhas no effect except as an ordinarycharacter if it appears within a<b>STRING</b>token, or to delimit a lexical token other than<b>STRING</b>.<p><li>The combination of a backslash character immediately followed by anewline characterhas no effect other than todelimit lexical tokens with the following exceptions:<ul><p><li>It is interpreted as the character sequence\newlinein<b>STRING</b>tokens.<p><li>It is ignored as part of a multi-line<b>NUMBER</b>token.<p></ul><p><li>The token<b>NUMBER</b>represents a numeric constant.It is recognised by the following grammar:<pre><code><table <tr valign=top><th align=left>NUMBER<th align=left>:<th align=center>integer<tr valign=top><td align=left><td align=left>|<td align=center>'.' integer<tr valign=top><td align=left><td align=left>|<td align=center>integer '.'<tr valign=top><td align=left><td align=left>|<td align=center>integer '.' integer<tr valign=top><td align=left>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -