プログラムに書き込む各字句(トークン)の概略です。[C99, 6.4]
コンパイラが翻訳作業上予め意味をもつ言葉。
auto | break | case | char | const | continue |
default | do | double | else | enum | extern |
float | for | goto | if | inline | int |
long | register | restrict | return | short | signed |
sizeof | static | struct | switch | typedef | union |
unsigned | void | volatile | while | _Bool | _Complex |
_Imaginary | |||||
英数字 a-zA-Z0-9 とアンダースコア _ からなる文字列。大文字小文字を区別。変数名や関数名などのこと。
数字や文字などで決まった値として認識するもの。「文字定数」「整数定数」「浮動小数点定数」「列挙定数」がある。
ダブル・クォーテーションで挟まれた文字列。
上とは独立な意味をもつ文字。/ # < > ( ) { } [ ] , . -> + - * ; など。
次を一つのソースファイルに書き込み,そのソースファイルのみから構成されるプログラムを考えましょう。ソースファイル名は任意ですが,拡張子 .c を必ず付します。
/* Example 2.1 */
#include <stdio.h>
int main(void)
{
const int a = 0;
register int m = 12;
int n = 65;
printf("a is %d; m is %d; n is %d.\n", a, m, n);
return 0;
}
このプログラムでの各字句です。
| ・キーワード | int void const register return |
| ・識別子 | main a m n printf |
| ・文字列リテラル | "a is %d; m is %d; n is %d.\n" |
| ・定数 | 0 12 65 文字列リテラル内の各文字 |
| ・区切り子 | / * # <> () {} = ; , |
しかしながら,文法自体は,これらの組合せでできています。