Lexical Elements - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Lexical Elements

Description:

A comment can be written in this fashion * to set it off from the surrounding code. ... course we do not use the c style!!! // This is not ANSI C!!! int i1 , ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 8
Provided by: Ala774
Category:

less

Transcript and Presenter's Notes

Title: Lexical Elements


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
  • operators - ...
  • punctuation ,

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
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.

auto do goto signed unsigned break
double if sizeof void case else
int static volatile char enum long
struct while const extern register switch
continue float return typedef default for
short union
5
Identifiers
  • A token composed of a sequence of letters
  • tax price tax_rate
  • Alphanumeric characters '_'. tax-rate
    ltgt 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
Numeric Constants
too long?
  • 0
  • 123456789000 123456789000u 123456789000L
  • 0100 0x40
  • -4913
  • 123.0 3e2
  • 'a' 'A' ' ' '\t' '\n' '\a' '\0'
  • Suffixes
  • u or U unsigned (integers only)
  • l or L long (ul - unsigned long)

cconstant integer (octal base)
cconstant integer (hexadecimal base)
a constant expression
floating constant
integer constants
?97
?65
?32
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
Write a Comment
User Comments (0)
About PowerShow.com