From WikiChip
Editing c/phases of translation

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
{{c title|Phases of Translation}}
+
A [[C]] program can consist of one or more files; the text of the program is kept in units called ''[[source file]]s''. The '''phases of translation''' are a series of steps a translator, or compiler, must go through to convert a source file into an executable program. During these phases, the source file gets converted into a [[preprocessing translation unit - C|preprocessing translation unit]], then into a [[translation unit - C|translation unit]], and finally into an [[executable program]]. It is also possible to translate individual units separately and then later link them to produce an executable program.<ref>ISO/IEC 9899:2011 §5.1.1.1 p1</ref>
A [[C]] program can consist of one or more files; the text of the program is kept in units called ''[[source file]]s''. The '''phases of translation''' are a series of steps a translator, or compiler, must go through to convert a source file into an executable program. During these phases, the source file gets converted into a {{C|preprocessing translation unit}}, then into a {{C|translation unit}}, and finally into an [[executable program]]. It is also possible to translate individual units separately and then later link them to produce an executable program.<ref>ISO/IEC 9899:2011 §5.1.1.1 p1</ref>
 
  
 
== Translation phases ==
 
== Translation phases ==
Line 17: Line 16:
 
During the first phase of translation, the physical source  is mapped to the source character set in an implementation-defined manner. For example, the compiler may choose to interpret the source as UTF-8 or simply as ASCII and convert it to the implementation's internal source representation if necessary.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.1</ref>
 
During the first phase of translation, the physical source  is mapped to the source character set in an implementation-defined manner. For example, the compiler may choose to interpret the source as UTF-8 or simply as ASCII and convert it to the implementation's internal source representation if necessary.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.1</ref>
  
In addition to the character mapping; {{C|trigraphs|trigraph sequences}} are replaced by corresponding single-character internal representations. For example:
+
In addition to the character mapping; [[trigraphs - C|trigraph sequences]] are replaced by corresponding single-character internal representations. For example:
  
 
<source lang="C">
 
<source lang="C">
Line 63: Line 62:
 
   
 
   
 
== Tokenization ==
 
== Tokenization ==
In the third phase of translation, the {{C|preprocessor}} tokenizes the source file into preprocessing [[token]]s and sequences of whitespace characters. Comments are placed by a single [[whitespace]] character and [[new-line]] characters are retained.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.3</ref>
+
In the third phase of translation, the [[C preprocessor|preprocessor]] tokenizes the source file into preprocessing [[token]]s and sequences of whitespace characters. Comments are placed by a single [[whitespace]] character and [[new-line]] characters are retained.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.3</ref>
  
 
== Preprocessing ==
 
== Preprocessing ==
During this stage all processing directives are executed, macro invocations are expanded, and the {{C|_Pragma}} operator expressions are executed. Any included file is processed from phase 1 through phase 4, recursively. By the conclusion of this phase, all preprocessing directives are deleted.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.4</ref>
+
During this stage all processing directives are executed, macro invocations are expanded, and the [[pragma operator - C|_Pragma]] operator expressions are executed. Any included file is processed from phase 1 through phase 4, recursively. By the conclusion of this phase, all preprocessing directives are deleted.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.4</ref>
  
 
== Character-set mapping ==
 
== Character-set mapping ==
In the fifth phase of translation, each source character set member and {{C|escape sequence}} in character constants and string literals are converted to their corresponding execution character set member. Whenever that's not possible, the character is convert in an implementation-defined manner to some character other than null.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.5</ref>
+
In the fifth phase of translation, each source character set member and [[escape sequence - C|escape sequence]] in character constants and string literals are converted to their corresponding execution character set member. Whenever that's not possible, the character is convert in an implementation-defined manner to some character other than null.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.5</ref>
  
 
== String concatenation ==
 
== String concatenation ==
In this phase, all adjacent {{C|string literal}} tokens are [[concatenation|concatenated]]. For example: <code>"A" "B" C"</code> becomes <code>"ABC"</code> and <code>"A" u"B" "C"</code> becomes <code>u"ABC"</code><ref>ISO/IEC 9899:2011 §5.1.1.2 p1.6</ref>
+
In this phase, all adjacent [[string literals - C|string literal]] tokens are [[concatenation|concatenated]]. For example: <code>"A" "B" C"</code> becomes <code>"ABC"</code> and <code>"A" u"B" "C"</code> becomes <code>u"ABC"</code><ref>ISO/IEC 9899:2011 §5.1.1.2 p1.6</ref>
  
 
== Translation ==
 
== Translation ==
In the seventh phase, all [[whitespace]] characters separating tokens becomes insignificant. Every {{C|preprocessing token}} is converted into a token. Tokens are syntactically and semantically analyzed and translated as a translation unit.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.7</ref>
+
In the seventh phase, all [[whitespace]] characters separating tokens becomes insignificant. Every [[preprocessing token - C|preprocessing token]] is converted into a token. Tokens are syntactically and semantically analyzed and translated as a translation unit.<ref>ISO/IEC 9899:2011 §5.1.1.2 p1.7</ref>
  
 
== Linkage ==
 
== Linkage ==

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)