?? bc
字號:
x =+ y x = x+yx =\- y x = x\-yx =* y x = x*yx =/ y x = x/yx =% y x = x%yx =^ y x = x^yx++ (x=x+1)\-1x\-\- (x=x\-1)+1++x x = x+1\-\-x x = x\-1.DEEven if you don't intend to use the constructs,if you type one inadvertently, something correct but unexpectedmay happen..PPWARNING! In some of these constructions, spaces aresignificant.There is a real difference betweenx=\-y and x= \-y.The first replaces x by x\-y and the second by \-y..SHThree Important Things.PP1. To exit a BC program, type `quit'..PP2. There is a comment convention identical to that of C andof PL/I. Comments begin with `/*' and end with `*/'..PP3. There is a library of math functions which may be obtained bytyping at command level.DSbc \-l.DEThis command will load a set of library functionswhich, at the time of writing, consists of sine (named `s'),cosine (`c'), arctangent (`a'), natural logarithm (`l'),exponential (`e') and Bessel functions of integer order (`j(n,x)'). Doubtless more functions will be addedin time.The library sets the scale to 20. You can reset it to somethingelse if you like.The design of these mathematical library routinesis discussed elsewhere [3]..PPIf you type.DSbc file ....DEBC will read and execute the named file or files before acceptingcommands from the keyboard. In this way, you may load yourfavorite programs and function definitions..SHAcknowledgement.PPThe compiler is written in YACC [4]; its originalversion was written by S. C. Johnson..SHReferences.IP [1]K. Thompson and D. M. Ritchie,.ft IUNIX Programmer's Manual,.ftBell Laboratories,1978..IP [2]B. W. Kernighan andD. M. Ritchie,.ft IThe C Programming Language,.ftPrentice-Hall, 1978..IP [3]R. Morris,.ft IA Library of Reference Standard Mathematical Subroutines,.ftBell Laboratories internal memorandum, 1975..IP [4]S. C. Johnson,.ft IYACC \(em Yet Another Compiler-Compiler..ftBell Laboratories Computing Science Technical Report #32, 1978..IP [5]R. Morris and L. L. Cherry,.ft IDC \- An Interactive Desk Calculator..ft.LP.bp.ft B.DS CAppendix.DE.ft.NHNotation.PPIn the following pages syntactic categories are in \fIitalics\fP;literals are in \fBbold\fP; material in brackets [\|] is optional..NHTokens.PPTokens consist of keywords, identifiers, constants, operators,and separators.Token separators may be blanks, tabs or comments.Newline characters or semicolons separate statements..NH 2Comments.PPComments are introduced by the characters /* and terminated by*/..NH 2Identifiers.PPThere are three kinds of identifiers \- ordinary identifiers, array identifiersand function identifiers.All three types consist of single lower-case letters.Array identifiers are followed by square brackets, possiblyenclosing an expression describing a subscript.Arrays are singly dimensioned and may contain up to 2048elements.Indexing begins at zero so an array may be indexed from 0 to 2047.Subscripts are truncated to integers.Function identifiers are followed by parentheses, possibly enclosing arguments.The three types of identifiers do not conflict;a program can have a variable named \fBx\fP,an array named \fBx\fP and a function named \fBx\fP, all of which are separate anddistinct..NH 2Keywords.PPThe following are reserved keywords:.ft B.ta .5i 1.0i.nf ibase if obase break scale define sqrt auto length return while quit for.fi.ft.NH 2Constants.PPConstants consist of arbitrarily long numberswith an optional decimal point.The hexadecimal digits \fBA\fP\-\fBF\fP are also recognized as digits withvalues 10\-15, respectively..NH 1Expressions.PPThe value of an expression is printed unless the mainoperator is an assignment.Precedence is the same as the orderof presentation here, with highest appearing first.Left or right associativity, where applicable, isdiscussed with each operator..bp.NH 2Primitive expressions.NH 3Named expressions.PPNamed expressions areplaces where values are stored.Simply stated,named expressions are legal on the leftside of an assignment.The value of a named expression is the value stored in the place named..NH 4\fIidentifiers\fR.PPSimple identifiers are named expressions.They have an initial value of zero..NH 4\fIarray-name\fP\|[\|\fIexpression\fP\|].PPArray elements are named expressions.They have an initial value of zero..NH 4\fBscale\fR, \fBibase\fR and \fBobase\fR.PPThe internal registers\fBscale\fP, \fBibase\fP and \fBobase\fP are all named expressions.\fBscale\fP is the number of digits after the decimal point to beretained in arithmetic operations.\fBscale\fR has an initial value of zero.\fBibase\fP and \fBobase\fP are the input and output numberradix respectively.Both \fBibase\fR and \fBobase\fR have initial values of 10..NH 3Function calls.NH 4\fIfunction-name\fB\|(\fR[\fIexpression\fR\|[\fB,\|\fIexpression\|\fR.\|.\|.\|]\|]\fB).PPA function call consists of a function name followed by parenthesescontaining a comma-separated list ofexpressions, which are the function arguments.A whole array passed as an argument is specified by thearray name followed by empty square brackets.All function arguments are passed byvalue.As a result, changes made to the formal parameters haveno effect on the actual arguments.If the function terminates by executing a returnstatement, the value of the function isthe value of the expression in the parentheses of the returnstatement or is zero if no expression is providedor if there is no return statement..NH 4sqrt\|(\|\fIexpression\fP\|).PPThe result is the square root of the expression.The result is truncated in the least significant decimal place.The scale of the result isthe scale of the expression or thevalue of.ft Bscale,.ftwhichever is larger..NH 4length\|(\|\fIexpression\fP\|).PPThe result is the total number of significant decimal digits in the expression.The scale of the result is zero..NH 4scale\|(\|\fIexpression\fP\|).PPThe result is the scale of the expression.The scale of the result is zero..NH 3Constants.PPConstants are primitive expressions..NH 3Parentheses.PPAn expression surrounded by parentheses isa primitive expression.The parentheses are used to alter thenormal precedence..NH 2Unary operators.PPThe unary operatorsbind right to left..NH 3\-\|\fIexpression\fP.PPThe result is the negative of the expression..NH 3++\|\fInamed-expression\fP.PPThe named expression isincremented by one.The result is the value of the named expression afterincrementing..NH 3\-\-\|\fInamed-expression\fP.PPThe named expression isdecremented by one.The result is the value of the named expression afterdecrementing..NH 3\fInamed-expression\fP\|++.PPThe named expression isincremented by one.The result is the value of the named expression beforeincrementing..NH 3\fInamed-expression\fP\|\-\-.PPThe named expression isdecremented by one.The result is the value of the named expression beforedecrementing..NH 2Exponentiation operator.PPThe exponentiation operator binds right to left..NH 3\fIexpression\fP ^ \fIexpression\fP.PPThe result is the firstexpression raised to the power of thesecond expression.The second expression must be an integer.If \fIa\fPis the scale of the left expressionand \fIb\fP is the absolute valueof the right expression,then the scale of the result is:.PPmin\|(\|\fIa\(mub\fP,\|max\|(\|\fBscale\fP,\|\fIa\fP\|)\|).NH 2Multiplicative operators.PPThe operators *, /, % bind left to right..NH 3\fIexpression\fP * \fIexpression\fP.PPThe result is the productof the two expressions.If \fIa\fP and \fIb\fP are thescales of the two expressions,then the scale of the result is:.PPmin\|(\|\fIa+b\fP,\|max\|(\|\fBscale\fP,\|\fIa\fP,\|\fIb\fP\|)\|).NH 3\fIexpression\fP / \fIexpression\fP.PPThe result is the quotient of the two expressions.The scale of the result is the value of \fBscale\fR..NH 3\fIexpression\fP % \fIexpression\fP.PPThe % operator produces the remainder of the divisionof the two expressions.More precisely,\fIa\fP%\fIb\fP is \fIa\fP\-\fIa\fP/\fIb\fP*\fIb\fP..PPThe scale of the result is the sum of the scale ofthe divisor and the value of.ft Bscale.ft.NH 2Additive operators.PPThe additive operators bind left to right..NH 3\fIexpression\fP + \fIexpression\fP.PPThe result is the sum of the two expressions.The scale of the result isthe maximun of the scales of the expressions..NH 3\fIexpression\fP \- \fIexpression\fP.PPThe result is the difference of the two expressions.The scale of the result is themaximum of the scales of the expressions..NH 2assignment operators.PPThe assignment operators bind right to left..NH 3\fInamed-expression\fP = \fIexpression\fP.PPThis expression results in assigning the value of the expressionon the rightto the named expression on the left..NH 3\fInamed-expression\fP =+ \fIexpression\fP.NH 3\fInamed-expression\fP =\- \fIexpression\fP.NH 3\fInamed-expression\fP =* \fIexpression\fP.NH 3\fInamed-expression\fP =/ \fIexpression\fP.NH 3\fInamed-expression\fP =% \fIexpression\fP.NH 3\fInamed-expression\fP =^ \fIexpression\fP.PPThe result of the above expressions is equivalentto ``named expression = named expression OP expression'',where OP is the operator after the = sign..NH 1Relations.PPUnlike all other operators, the relational operatorsare only valid as the object of an \fBif\fP, \fBwhile\fP,or inside a \fBfor\fP statement..NH 2\fIexpression\fP < \fIexpression\fP.NH 2\fIexpression\fP > \fIexpression\fP.NH 2\fIexpression\fP <= \fIexpression\fP.NH 2\fIexpression\fP >= \fIexpression\fP.NH 2\fIexpression\fP == \fIexpression\fP.NH 2\fIexpression\fP != \fIexpression\fP.NH 1Storage classes.PPThere are only two storage classes in BC, global and automatic(local).Only identifiers that are to be local to a function need be declared with the \fBauto\fP command.The arguments to a functionare local to the function.All other identifiers are assumed to be globaland available to all functions.All identifiers, global and local, have initial valuesof zero.Identifiers declared as \fBauto\fP are allocated on entry to the function and released on returning from the function.They therefore do not retain values between function calls.\fBauto\fP arrays are specified by the array name followed by empty square brackets..PPAutomatic variables in BC do not work in exactly the same wayas in either C or PL/I. On entry to a function, the old values ofthe names that appear as parameters and as automaticvariables are pushed onto a stack. Until return is made from the function, reference to thesenames refers only to the new values..NH 1Statements.PPStatements must be separated by semicolon or newline.Except where altered by control statements, executionis sequential..NH 2Expression statements.PPWhen a statement is an expression, unlessthe main operator is an assignment, the valueof the expression is printed, followed by a newline character..NH 2Compound statements.PPStatements may be grouped together and used when one statement is expectedby surrounding them with { }..NH 2Quoted string statements.PP"any string".sp .5This statement prints the string inside the quotes..NH 2If statements.sp .5\fBif\|(\|\fIrelation\fB\|)\|\fIstatement\fR.PPThe substatement is executed if the relation is true..NH 2While statements.sp .5\fBwhile\|(\|\fIrelation\fB\|)\|\fIstatement\fR.PPThe statement is executed while the relationis true.The test occurs before each execution of the statement..NH 2For statements.sp .5\fBfor\|(\|\fIexpression\fB; \fIrelation\fB; \fIexpression\fB\|)\|\fIstatement\fR.PPThe for statement is the same as.nf.ft I first-expression \fBwhile\|(\fPrelation\|\fB) {\fP statement last-expression }.ft R.fi.PPAll three expressions must be present..NH 2Break statements.sp .5\fBbreak\fP.PP\fBbreak\fP causes termination of a \fBfor\fP or \fBwhile\fP statement..NH 2Auto statements.sp .5\fBauto \fIidentifier\fR\|[\|\fB,\fIidentifier\fR\|].PPThe auto statement causes the values of the identifiers to be pushed down.The identifiers can be ordinary identifiers or array identifiers.Array identifiers are specified by following the array name by empty squarebrackets.The auto statement must be the first statementin a function definition..NH 2Define statements.sp .5.nf\fBdefine(\|\fR[\fIparameter\|\fR[\fB\|,\|\fIparameter\|.\|.\|.\|\fR]\|]\|\fB)\|{\fI statements\|\fB}\fR.fi.PPThe define statement defines a function.The parameters maybe ordinary identifiers or array names.Array names must be followed by empty square brackets..NH 2Return statements.sp .5\fBreturn\fP.sp .5\fBreturn(\fI\|expression\|\fB)\fR.PPThe return statement causes termination of a function,popping of its auto variables, andspecifies the result of the function.The first form is equivalent to \fBreturn(0)\fR.The result of the function is the result of the expressionin parentheses..NH 2Quit.PPThe quit statement stops execution of a BC program and returnscontrol to UNIX when it is first encountered.Because it is not treated as an executable statement,it cannot be usedin a function definition or in an .ft Bif, for,.ftor.ft Bwhile.ftstatement.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -