Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Lexical Elements Chapter 2 in ABC. 2 Tokens Token = word / symbol, does not contain white spaces. Tokens in C are either: –keywords –identifiers –constants.

Similar presentations


Presentation on theme: "1 Lexical Elements Chapter 2 in ABC. 2 Tokens Token = word / symbol, does not contain white spaces. Tokens in C are either: –keywords –identifiers –constants."— Presentation transcript:

1 1 Lexical Elements Chapter 2 in ABC

2 2 Tokens Token = word / symbol, does not contain white spaces. Tokens in C are either: –keywords –identifiers –constants –operators + - || =... –punctuation:, ;{ }

3 3 Comments Arbitrary strings placed between the delimiters /* and */. /* * A comment can be written in this fashion * to set it off from the surrounding code. */ The (pre-)compiler replaces each comment with a single blank character. int i1/*comment*/,i2 /*comment*/; int i/*comment*/3; In this course we do not use the c++ style!!! // This is not ANSI C!!! int i1,i2 ; int i 3; (gcc -E)

4 4 Keywords keyword = A reserved word with strict meaning. C does a lot with relatively few keywords. Some implementations on some systems may have additional keywords. autodogotosignedunsignedbreak doubleifsizeofvoidcaseelse intstaticvolatilecharenumlong structwhileconstexternregisterswitch continuefloatreturntypedefdefaultfor shortunion

5 5 Identifiers A token composed of a sequence of letters tax = price * tax_rate Alphanumeric characters + '_'. tax-rate tax - rate First character cannot be a digit!! 5a_cse is not legal Case sensitive CSE_5a is different from cse_5a Some identifiers are already taken: keywords. Choose names that are meaningful!! (cse_5a is not a good example...) expression

6 6 Numeric Constants 0 123456789000 123456789000u 123456789000L 0100 0x40 -49+13 123.0 3e2 'a' 'A' ' ' '\t' '\n' '\a' '\0' Suffixes: u or U : unsigned (integers only) l or L : long (ul - unsigned long) too long? cconstant integer (octal base) a constant expression floating constant integer constants  97  65  32 cconstant integer (hexadecimal base)

7 7 String Constants "a string of text" "" "a = b + c" "a string with double quotes \" within" "a string backslash \\ is in this string" 2 string constants separated by white spaces are concatenated "abc" "def" is equivalent to "abcdef" The NULL string (empty string) Nothing is executed


Download ppt "1 Lexical Elements Chapter 2 in ABC. 2 Tokens Token = word / symbol, does not contain white spaces. Tokens in C are either: –keywords –identifiers –constants."

Similar presentations


Ads by Google