bc: Comparison with Other Implementations

1 
1 8 Comparison with Other Implementations
1 ***************************************
1 
1 This version of 'bc' was implemented from the POSIX P1003.2/D11 draft
1 and contains several differences and extensions relative to the draft
1 and traditional implementations.  It is not implemented in the
1 traditional way using 'dc'.  This version is a single process which
1 parses and runs a byte code translation of the program.  There is an
1 "undocumented" option (-c) that causes the program to output the byte
1 code to the standard output instead of running it.  It was mainly used
1 for debugging the parser and preparing the math library.
1 
1    A major source of differences is extensions, where a feature is
1 extended to add more functionality and additions, where new features are
1 added.  The following is the list of differences and extensions.
1 
1 LANG environment
1      This version does not conform to the POSIX standard in the
1      processing of the LANG environment variable and all environment
1      variables starting with LC_.
1 
1 names
1      Traditional and POSIX 'bc' have single letter names for functions,
1      variables and arrays.  They have been extended to be
1      multi-character names that start with a letter and may contain
1      letters, numbers and the underscore character.
1 
1 Strings
1      Strings are not allowed to contain NUL characters.  POSIX says all
1      characters must be included in strings.
1 
1 last
1      POSIX 'bc' does not have a \fBlast variable.  Some implementations
1      of 'bc' use the period (.)  in a similar way.
1 
1 comparisons
1      POSIX 'bc' allows comparisons only in the 'if' statement, the
1      'while' statement, and the second expression of the 'for'
1      statement.  Also, only one relational operation is allowed in each
1      of those statements.
1 
1 'if' statement, 'else' clause
1      POSIX 'bc' does not have an 'else' clause.
1 
1 'for' statement
1      POSIX 'bc' requires all expressions to be present in the 'for'
1      statement.
1 
1 '&&,' '||', '!'
1      POSIX 'bc' does not have the logical operators.
1 
1 'read' function
1      POSIX 'bc' does not have a 'read' function.
1 
1 'print' statement
1      POSIX 'bc' does not have a 'print' statement.
1 
1 'continue' statement
1      POSIX 'bc' does not have a continue statement.
1 
1 array parameters
1      POSIX 'bc' does not (currently) support array parameters in full.
1      The POSIX grammar allows for arrays in function definitions, but
1      does not provide a method to specify an array as an actual
1      parameter.  (This is most likely an oversight in the grammar.)
1      Traditional implementations of 'bc' have only call by value array
1      parameters.
1 
1 function format
1      POSIX 'bc' requires the opening brace on the same line as the
1      'define' key word and the 'auto' statement on the next line.
1 
1 '=+', '=-', '=*', '=/', '=%', '=^'
1      POSIX 'bc' does not require these "old style" assignment operators
1      to be defined.  This version may allow these "old style"
1      assignments.  Use the 'limits' statement to see if the installed
1      version supports them.  If it does support the "old style"
1      assignment operators, the statement "a =- 1" will decrement 'a' by
1      1 instead of setting 'a' to the value -1.
1 
1 spaces in numbers
1      Other implementations of 'bc' allow spaces in numbers.  For
1      example, "x=1 3" would assign the value 13 to the variable x.  The
1      same statement would cause a syntax error in this version of 'bc'.
1 
1 errors and execution
1      This implementation varies from other implementations in terms of
1      what code will be executed when syntax and other errors are found
1      in the program.  If a syntax error is found in a function
1      definition, error recovery tries to find the beginning of a
1      statement and continue to parse the function.  Once a syntax error
1      is found in the function, the function will not be callable and
1      becomes undefined.  Syntax errors in the interactive execution code
1      will invalidate the current execution block.  The execution block
1      is terminated by an end of line that appears after a complete
1      sequence of statements.  For example,
1 
1           a = 1
1           b = 2
1 
1      has two execution blocks and
1 
1           { a = 1
1             b = 2 }
1 
1      has one execution block.  Any runtime error will terminate the
1      execution of the current execution block.  A runtime warning will
1      not terminate the current execution block.
1 
1 Interrupts
1      During an interactive session, the SIGINT signal (usually generated
1      by the control-C character from the terminal) will cause execution
1      of the current execution block to be interrupted.  It will display
1      a "runtime" error indicating which function was interrupted.  After
1      all runtime structures have been cleaned up, a message will be
1      printed to notify the user that 'bc' is ready for more input.  All
1      previously defined functions remain defined and the value of all
1      non-auto variables are the value at the point of interruption.  All
1      auto variables and function parameters are removed during the clean
1      up process.  During a non-interactive session, the SIGINT signal
1      will terminate the entire run of 'bc'.
1