📄 bc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>bc</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="bc"></a> <a name="tag_04_09"></a><!-- bc --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_09_01"></a>NAME</h4><blockquote>bc - arbitrary-precision arithmetic language</blockquote><h4><a name="tag_04_09_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>bc</tt> <b>[</b><tt>-l</tt><b>] [</b><i>file</i> <tt>...</tt><b>]</b></code></p></blockquote><h4><a name="tag_04_09_03"></a>DESCRIPTION</h4><blockquote><p>The <i>bc</i> utility shall implement an arbitrary precision calculator. It shall take input from any files given, then readfrom the standard input. If the standard input and standard output to <i>bc</i> are attached to a terminal, the invocation of<i>bc</i> shall be considered to be <i>interactive</i>, causing behavioral constraints described in the following sections.</p></blockquote><h4><a name="tag_04_09_04"></a>OPTIONS</h4><blockquote><p>The <i>bc</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p><p>The following option shall be supported:</p><dl compact><dt><b>-l</b></dt><dd>(The letter ell.) Define the math functions and initialize <i>scale</i> to 20, instead of the default zero; see the EXTENDEDDESCRIPTION section.</dd></dl></blockquote><h4><a name="tag_04_09_05"></a>OPERANDS</h4><blockquote><p>The following operand shall be supported:</p><dl compact><dt><i>file</i></dt><dd>A pathname of a text file containing <i>bc</i> program statements. After all <i>file</i>s have been read, <i>bc</i> shall readthe standard input.</dd></dl></blockquote><h4><a name="tag_04_09_06"></a>STDIN</h4><blockquote><p>See the INPUT FILES section.</p></blockquote><h4><a name="tag_04_09_07"></a>INPUT FILES</h4><blockquote><p>Input files shall be text files containing a sequence of comments, statements, and function definitions that shall be executedas they are read.</p></blockquote><h4><a name="tag_04_09_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>bc</i>:</p><dl compact><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments and input files).</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standarderror.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><h4><a name="tag_04_09_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_09_10"></a>STDOUT</h4><blockquote><p>The output of the <i>bc</i> utility shall be controlled by the program read, and consist of zero or more lines containing thevalue of all executed expressions without assignments. The radix and precision of the output shall be controlled by the values ofthe <b>obase</b> and <b>scale</b> variables; see the EXTENDED DESCRIPTION section.</p></blockquote><h4><a name="tag_04_09_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_09_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_09_13"></a>EXTENDED DESCRIPTION</h4><blockquote><h5><a name="tag_04_09_13_01"></a>Grammar</h5><p>The grammar in this section and the lexical conventions in the following section shall together describe the syntax for<i>bc</i> programs. The general conventions for this style of grammar are described in <a href="xcu_chap01.html#tag_01_10"><i>Grammar Conventions</i></a> . A valid program can be represented as the non-terminal symbol<b>program</b> in the grammar. This formal syntax shall take precedence over the text syntax description.</p><pre><tt>%token EOF NEWLINE STRING LETTER NUMBER<br>%token MUL_OP/* '*', '/', '%' */<br>%token ASSIGN_OP/* '=', '+=', '-=', '*=', '/=', '%=', '^=' */<br>%token REL_OP/* '==', '<=', '>=', '!=', '<', '>' */<br>%token INCR_DECR/* '++', '--' */<br>%token Define Break Quit Length/* 'define', 'break', 'quit', 'length' */<br>%token Return For If While Sqrt/* 'return', 'for', 'if', 'while', 'sqrt' */<br>%token Scale Ibase Obase Auto/* 'scale', 'ibase', 'obase', 'auto' */<br>%start program<br>%%<br>program : EOF | input_item program ;<br>input_item : semicolon_list NEWLINE | function ;<br>semicolon_list : /* empty */ | statement | semicolon_list ';' statement | semicolon_list ';' ;<br>statement_list : /* empty */ | statement | statement_list NEWLINE | statement_list NEWLINE statement | statement_list ';' | statement_list ';' statement ;<br>statement : expression | STRING | Break | Quit | Return | Return '(' return_expression ')' | For '(' expression ';' relational_expression ';' expression ')' statement | If '(' relational_expression ')' statement | While '(' relational_expression ')' statement | '{' statement_list '}' ;<br>function : Define LETTER '(' opt_parameter_list ')' '{' NEWLINE opt_auto_define_list statement_list '}' ;<br>opt_parameter_list : /* empty */ | parameter_list ;<br>parameter_list : LETTER | define_list ',' LETTER ;<br>opt_auto_define_list : /* empty */ | Auto define_list NEWLINE | Auto define_list ';' ;<br>define_list : LETTER | LETTER '[' ']' | define_list ',' LETTER | define_list ',' LETTER '[' ']' ;<br>opt_argument_list : /* empty */ | argument_list ;<br>argument_list : expression | LETTER '[' ']' ',' argument_list ;<br>relational_expression : expression | expression REL_OP expression ;<br>return_expression : /* empty */ | expression ;<br>expression : named_expression | NUMBER | '(' expression ')' | LETTER '(' opt_argument_list ')' | '-' expression | expression '+' expression | expression '-' expression | expression MUL_OP expression | expression '^' expression | INCR_DECR named_expression | named_expression INCR_DECR | named_expression ASSIGN_OP expression | Length '(' expression ')' | Sqrt '(' expression ')' | Scale '(' expression ')' ;<br>named_expression : LETTER | LETTER '[' expression ']' | Scale | Ibase | Obase ;</tt></pre><h5><a name="tag_04_09_13_02"></a>Lexical Conventions in bc</h5><p>The lexical conventions for <i>bc</i> programs, with respect to the preceding grammar, shall be as follows:</p><ol><li><p>Except as noted, <i>bc</i> shall recognize the longest possible token or delimiter beginning at a given point.</p></li><li><p>A comment shall consist of any characters beginning with the two adjacent characters <tt>"/*"</tt> and terminated by the nextoccurrence of the two adjacent characters <tt>"*/"</tt> . Comments shall have no effect except to delimit lexical tokens.</p></li><li><p>The <newline> shall be recognized as the token <b>NEWLINE</b>.</p></li><li><p>The token <b>STRING</b> shall represent a string constant; it shall consist of any characters beginning with the double-quotecharacter ( <tt>' )'</tt> and terminated by another occurrence of the double-quote character. The value of the string is thesequence of all characters between, but not including, the two double-quote characters. All characters shall be taken literallyfrom the input, and there is no way to specify a string containing a double-quote character. The length of the value of each stringshall be limited to {BC_STRING_MAX} bytes.</p></li><li><p>A <blank> shall have no effect except as an ordinary character if it appears within a <b>STRING</b> token, or to delimit alexical token other than <b>STRING</b>.</p></li><li><p>The combination of a backslash character immediately followed by a <newline> shall have no effect other than to delimitlexical tokens with the following exceptions:</p><ul>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -