Thursday 16 May 2013

Lexical IN C++


Introduces the fundamental elements of a C++ program as they are meaningful to the compiler are used to construct statements, definitions, declarations, and so on, which are used to construct complete programs.
The fundamental elements of a C++ program are called “lexical elements” or “tokens” to construct statements, definitions, declarations, and so on, which are used to construct complete programs. The following lexical elements are discussed here:
1.    Tokens
A token is the smallest element of a C++ program that is meaningful to the compiler. The C++ parser recognizes these kinds of tokens: Identifiers, Keywords, Literals, Operators, Punctuators, and Other Separators. A stream of these tokens makes up a translation unit.
2.    Comments
A comment is text that the compiler ignores but that is useful for programmers. Comments are normally used to annotate code for future reference.
A C++ comment is written in one of the following ways:

The /* (slash, asterisk) characters, followed by any sequence of characters (including new lines), followed by the */ characters.

The // (two slashes) characters, followed by any sequence of characters. A new line not immediately preceded by a backslash terminates this form of comment. Therefore, it is commonly called a “single-line comment.”
/*This is an example of
  comments in a program */
FileName = String( "hello.dat" );   // Initialize file string 

3.    Identifiers
An identifier is a sequence of characters used to denote one of the following:
   
Object or variable name
   
Class, structure, or union name
   
Enumerated type name

 Member of a class, structure, union, or enumeration

 Function or class-member function
   typedef name
   Label name
The first character of an identifier must be an alphabetic character, either uppercase or lowercase, or an underscore ( _ ). Because C++ identifiers are case sensitive, fileName is different from FileName.

4.    C++ keywords
Keywords are predefined reserved identifiers that have special meanings. They cannot be used as identifiers in your program. The following keywords are reserved for C++:
asm
auto
bad_cast
bad_typeid
bool
break
case
catch
char
class
const
const_cast
continue
default
delete
do
double
dynamic_cast
else
enum
except
explicit
extern
false
finally
float
for
friend
goto
if
inline
int
long
mutable
namespace
new
operator
private
protected
public
register
reinterpret_cast
return
short
signed
sizeof
static
static_cast
struct
switch
template
this
throw
true
try
type_info
typedef
typeid
typename
union
unsigned
using
virtual
void
Volatile
while



5.    Punctuators
Punctuators in C++ have syntactic and semantic meaning to the compiler but do not, of themselves, specify an operation that yields a value. Some punctuators, either alone or in combination, can also be C++ operators or be significant to the preprocessor.  The punctuators are
! % ^ & * ( ) + = { } | ~
[ ] \ ; ' : " < > ? , . / #
The punctuators [ ], ( ), and { } must appear in pairs

6.    Operators

No comments:

Post a Comment