Example: bankruptcy

The C-- Language Reference Manual

TheC-- Language Reference ManualSimon Peyton JonesThomas NordinDino OlivaPablo Nogueira IglesiasApril 23, 1998 Contents1 Introduction32 Syntax General .. Comments .. Names .. Name scope .. Theimportandexportdeclarations .. Constants .. Integer and floating point numbers .. Characters and strings .. 73 Fundamental concepts Memory .. Data segment .. Code segment .. Types .. Local variables (or registers) .. Addresses .. Names .. Foreign Language interface .. 94 Data layout Labels .. Initialisation .. Alignment .. 1215 Procedure definition .. Statements .. ;.. Declaration .. Assignment .. Memory write .. relational operations .. Local control labels andgoto.. Procedure call .. Foreign Language interface .. 196 Introduction.

A character constant is treated as an integer whose value is the character’s 8-bit ASCII code. There-fore, character constants have type word1. C--uses C’s escape sequences to denote special charac-ters, such as \nfor the new line and \tfor the tabulator. For example, character constant ’H’is a word1with value 72.

Tags:

  Manual, Language, Reference, Character, The c language reference manual

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of The C-- Language Reference Manual

1 TheC-- Language Reference ManualSimon Peyton JonesThomas NordinDino OlivaPablo Nogueira IglesiasApril 23, 1998 Contents1 Introduction32 Syntax General .. Comments .. Names .. Name scope .. Theimportandexportdeclarations .. Constants .. Integer and floating point numbers .. Characters and strings .. 73 Fundamental concepts Memory .. Data segment .. Code segment .. Types .. Local variables (or registers) .. Addresses .. Names .. Foreign Language interface .. 94 Data layout Labels .. Initialisation .. Alignment .. 1215 Procedure definition .. Statements .. ;.. Declaration .. Assignment .. Memory write .. relational operations .. Local control labels andgoto.. Procedure call .. Foreign Language interface .. 196 Introduction.

2 Memory read .. Operators, precedence, and evaluation order .. Primitives .. Exception handling .. Casting .. and primitives .. +and-.. *.. ,|, and .. <<and>>.. and primitives .. +f,-f, and*f.. 327 Further Work331 IntroductionC--is a portable assembly Language designed to be a good backendfor high level languages (par-ticularly for those that make use of garbage-collection) and to run fast on a number of todays majorcomputer architectures. It is also designed to have as few dependencies as possible on the under-lying hardware, but speed and ease of use has sometimes takenprecedence over orthogonality be rich enough to be a viable backend for most mainstream and paper should be sufficiently self-supporting so that anyone who knows an imperative languageand is acquainted with computers should be able to write her/his ownC--programs after reading Syntax definitionThe syntax ofC--is given in Figures 1 and GeneralAC--program file is written in eight bit ASCII characters.

3 It consists in a sequence ofdatalayoutdirectives (Section 4), and/or procedure definitions (Section 5), and/orimportdeclarations, and/orexportdeclarations (Section ), interleaved in any unitis aC--program file that can be successfully compiled and that is suitablefor not support input/output. Nevertheless, it can be accomplished using a foreign languagecall (Section ).3 Programprogram!pal[program]Palpal!dataj[ conv]Name(arg1,:::argn)[data]blockn 0jimportName1,:::Namen;n 1jexportName1,:::Namen;n 1 Datadata!data {datum1:::datumn}n 1 Datumdatum!Name:jtype[[sconst]][{expr1,: ::exprn}];n 1jtype[]{expr1,:::exprn} ;n 1jword1[]AsciiString;Abbreviationjword2[ ]UnicodeString;Abbreviationjalignn;Align mentdirectiveSimpleConstantssconst!NumIn tegerconstantj char Asciichar:constantjunicode( char )Unicodechar:constantConstantsconst!scon stSimpleconstantsjFNumFloatnumberconstan tjNameSymbolicconstantjAsciiStringString constantjUnicodeStringUnicodestringconst antStringsAsciiString!

4 "char1:::charn"n 0 UnicodeString!unicode("char1:::charn")n 0 Conventionconv!foreignconvkindConvention declarationConventionsconvkind!CCallingC onventionsjPascalj:::FormalArgumentsarg! typeNameTypetype!wordnjfloatmn2f1;2;4;8g ;m2f4;8gBlockblock!{stm1:::stmn}n 0 Figure 1:C--syntax4 Statementsstm!skip;NullstatementjtypeNam e1,:::Namen;Var:decl:;n 1jName=expr;Assignmentjtype[{alignn}][ex pr] =expr;Memorywrite;align:njifexprrelexprb lock[elseblock]jswitch[[ ]]expr{swt1:::swtn}n 1jblockScopingjName:Localcontrollabeljgo toName;Gotolocallabeljjumpexpr(expr1,::: exprn) ;n 0;Jumptoexprj[conv][Name1,:::Namem=]expr (expr1,:::exprn) ;n;m 0j[conv]return(expr1,:::exprn);n 0 Expressionsexpr!constjNameVariableorlabe ljtype[{alignn}][expr]Memoryread;align:n j(expr)jexpropexprjprim(expr1,:::,exprn) n 1 Operatorsop!+flagj-flagj*flagj/flagj%fla gArithmeticj&j|j j<<j>>flagj BitwisePrimitivesprim!

5 Negflagjabsflagjsignflagjexponentflagjfr actionflagjscaleflagjsuccflagjpredflagju lpflagjtruncflagjroundflagjintpartflagjf ractpartflagjtypeflagTypeCastsFlagsflag! NoFlagjoUnOrderedjujtjutUnsignedandTrapp ingjfjfzjfnjfpFloatingandRoundingjftjftz jftnjftpFloatingandTrappingRelationsrel! ==flagj!=flagj>flagj<flagj>=flagj<=flagSwitchbranchswt!sconst1,:::s constn:blockn 1jdefault :blockFigure 2: Statements CommentsComments start with/*and end with*/. They cannot be NamesNames are made up of letters, digits, underscore and dots. A name cannot begin with a numbercharacter or with a dot followed by a number character . Upperand lower case are distinct. Importednames should also follow these are identifiers for registers or memory addresses (Section ).The following are examples of legalC-- are two illegalC--names:. Name scopeProcedure and label names are always global inside aC--compilation unit (or program).

6 Local vari-able names and local control labels are only in scope of the procedure body where they are is no nested scoping of names inside a procedure. Procedure and label names may be usedbefore they are TheimportandexportdeclarationsNames that are to be used outside of theC--program must be exported with , names that theC--program uses and does not declare must be imported with theimportdeclaration. Only procedure and (pointer) label names may be names should follow the syntatic restriction mentioned in Section example where a few C external names are imported and a fewC--names are exported:import printf, sqrt; /* C procedures used in this C-- program*/export foo, bar; /* To be used outside this C-- program */Names that are explicitly exported and imported are guaranteed to be unchanged by the compiler. Allother names might be anexportdeclaration may appear anywhere in the program where adatalayoutdirective or a procedure definition ConstantsConstants can be (signed) integers, (signed) floating pointnumbers, characters, strings and C s syntax for denoting integer, floating point, character , and string Integer and floating point numbersInteger constants have of typeword.

7 Floating point constants have typefloat. Their size Characters and stringsCharacter and string constants are treated as integers and as pointer labels respectively. Characterconstants are ASCII characters surrounded by single quotes. String constants are a sequence of ASCII characters surrounded by double character constant is treated as an integer whose value is the character s 8-bit ASCII code. There-fore, character constants have C s escape sequences to denote special charac-ters, such as\nfor the new line and\tfor the example, character constant H is aword1with value constants are like labels that point to the firstword1of an array ofword1s stored in staticmemory. Therefore, they have typewordnwherenis the particular architecture s natural constants are not automatically example, the string"Hello World"is viewed as a label that points to the first byte of the arrayof bytes with values 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, stored in static is possible to have UTF-8 integers for single characters and for string syntax to specify an UTF-8 constant is:unicode(constant)whereconstantis a character constant or a string constant.

8 The type of UTF-8 characters isword2,for it requires two bytes two ASCII characters to code a Unicode character . UTF-8 strings arepointers to the firstword2of an array ofword2s stored in static memory, and therefore, they havetypewordn, wherenis the architecture s natural pointer Fundamental concepts MemoryMemory is an array of bytes from which different sizedtypes(Section ) can be read and size of the addressable memory is implementation dependent (Section ). All addresses and1 UTF-8 is an encoding of Unicode characters into 8-bit ASCII characters that does not use any of the ASCII control characters to perform the coding. Unicode is an abbreviation for Universal Multiple-Octet Coded Charac-ter Set (UCS), and it is defined in ISO/IEC 10646. It is an international standard for encoding computer char-acter sets that differs from historical ASCII. UTF-8 standsfor Universal Transformation Format, 8-Bit form.

9 More are specified in bytes. No guarantee about endianessis given, a portable program shouldeither not depend on a specific endianess or find it Data segmentThe data segment is the part of memory where the static, initialised or uninitialised, data is data segment is read/write, so the values stored can be changed at runtime. The size and initialcontent of the data segment is determined at compile time (Section 4).C--does not provide dy-namic memory allocation natively, nonetheless, it can be accomplished with foreign Language calls(Section and Section ). Code segmentThe code segment is the part of memory where the executable program code is stored (Section 5).The code segment consists of a series of procedure not currently provide a mechanism for creating code at TypesThere are only two kinds of types provided byC--, namelywordandfloat. These types can havedifferent sizes.

10 The size of awordcan be 1, 2, 4 or 8 bytes. The size of afloatcan be 4 or 8 type must be qualified with a size. Thusword1andword2are different is no pointer type. Thewordntype can be used for pointers (addresses), wherenis theparticular architecture snatural pointer size, :nis the number of bytes needed to hold a memoryaddress in the particular example, a four byte word is specified asword4, an eight byte float is specified asfloat8andso are used statements(Section ), to declare the type of local write statements and memory read expressions(Section and Section ,respectively) to indicate the type of the value layout directives(Section 4) to indicate the type of the allocated Local variables (or registers)Any number of local variable names may be declared inside procedure bodies. They are typed storagelocations that don t have an address. The term local variable name is interchangeable with the term register , since there is an unlimited supply of (virtual)registers: a local variable name will be8mapped to a machine register if there is one available, otherwise it is mapped to a memory location( the stack), but the mapping is transparent and local variables should be viewed as AddressesTo specify where in memory to read or write we need an expression that evaluates toawordncan be used as an address, wherenis the architecture snatural pointer size, :nis thenumber of bytes needed to hold a memory address in the particular addresses can be used but what they refer to is implementation dependent.


Related search queries