標準C語言Flex及Bison文件,請結合WinFlex&Bison編譯調試

目錄

 

1、前言

2、ANSI C 詞法文件

3、ANSI C 語法文件

4、ISO C 標準語法文件(未整理,請參考前兩個即可整理)


1、前言

鑑於這段時間美國總統特朗普先生對以華爲爲代表的中國企業圍堵的全面升級,本人將平時收集整理的標準C語言的Flex和Bison元文件發出來,供大家參考。算是爲反圍堵儘自己的一份綿薄之力。請注意文件只是標識了標準的詞法和語法,並沒有語法分析和語義分析部分,我一直沒有來得及補寫,現在放出來是給大家一個參考。

2、ANSI C 詞法文件

%option noyywrap nodefault yylineno 
%{
#include <stdio.h>
#include "ANSI_C.tab.h"

void yyerror(char *text);
void count(void);
void comment(void);
 int check_type(void);
%}
D			[0-9]
L			[a-zA-Z_]
H			[a-fA-F0-9]
E			([Ee][+-]?{D}+)
P           ([Pp][+-]?{D}+)
FS			(f|F|l|L)
IS          ((u|U)|(u|U)?(l|L|ll|LL)|(l|L|ll|LL)(u|U))

%%
"/*"			{ comment(); }
"//"[^\n]*      { /* consume //-comment */ }

"auto"			{ count(); return(AUTO); }
"_Bool"			{ count(); return(BOOL); }
"break"			{ count(); return(BREAK); }
"case"			{ count(); return(CASE); }
"char"			{ count(); return(CHAR); }
"_Complex"		{ count(); return(COMPLEX); }
"const"			{ count(); return(CONST); }
"continue"		{ count(); return(CONTINUE); }
"default"		{ count(); return(DEFAULT); }
"do"			{ count(); return(DO); }
"double"		{ count(); return(DOUBLE); }
"else"			{ count(); return(ELSE); }
"enum"			{ count(); return(ENUM); }
"extern"		{ count(); return(EXTERN); }
"float"			{ count(); return(FLOAT); }
"for"			{ count(); return(FOR); }
"goto"			{ count(); return(GOTO); }
"if"			{ count(); return(IF); }
"_Imaginary"	{ count(); return(IMAGINARY); }
"inline"		{ count(); return(INLINE); }
"int"			{ count(); return(INT); }
"long"			{ count(); return(LONG); }
"register"		{ count(); return(REGISTER); }
"restrict"		{ count(); return(RESTRICT); }
"return"		{ count(); return(RETURN); }
"short"			{ count(); return(SHORT); }
"signed"		{ count(); return(SIGNED); }
"sizeof"		{ count(); return(SIZEOF); }
"static"		{ count(); return(STATIC); }
"struct"		{ count(); return(STRUCT); }
"switch"		{ count(); return(SWITCH); }
"typedef"		{ count(); return(TYPEDEF); }
"union"			{ count(); return(UNION); }
"unsigned"		{ count(); return(UNSIGNED); }
"void"			{ count(); return(VOID); }
"volatile"		{ count(); return(VOLATILE); }
"while"			{ count(); return(WHILE); }

{L}({L}|{D})*		{ count(); return(check_type()); }

0[xX]{H}+{IS}?				{ count(); return(CONSTANT); }
0[0-7]*{IS}?				{ count(); return(CONSTANT); }
[1-9]{D}*{IS}?				{ count(); return(CONSTANT); }
L?'(\\.|[^\\'\n])+'			{ count(); return(CONSTANT); }
{D}+{E}{FS}?				{ count(); return(CONSTANT); }
{D}*"."{D}+{E}?{FS}?		{ count(); return(CONSTANT); }
{D}+"."{D}*{E}?{FS}?		{ count(); return(CONSTANT); }
0[xX]{H}+{P}{FS}?			{ count(); return(CONSTANT); }
0[xX]{H}*"."{H}+{P}?{FS}?   { count(); return(CONSTANT); }
0[xX]{H}+"."{H}*{P}?{FS}?   { count(); return(CONSTANT); }

L?\"(\\.|[^\\"\n])*\"		{ count(); return(STRING_LITERAL); }

"..."			{ count(); return(ELLIPSIS); }
">>="			{ count(); return(RIGHT_ASSIGN); }
"<<="			{ count(); return(LEFT_ASSIGN); }
"+="			{ count(); return(ADD_ASSIGN); }
"-="			{ count(); return(SUB_ASSIGN); }
"*="			{ count(); return(MUL_ASSIGN); }
"/="			{ count(); return(DIV_ASSIGN); }
"%="			{ count(); return(MOD_ASSIGN); }
"&="			{ count(); return(AND_ASSIGN); }
"^="			{ count(); return(XOR_ASSIGN); }
"|="			{ count(); return(OR_ASSIGN); }
">>"			{ count(); return(RIGHT_OP); }
"<<"			{ count(); return(LEFT_OP); }
"++"			{ count(); return(INC_OP); }
"--"			{ count(); return(DEC_OP); }
"->"			{ count(); return(PTR_OP); }
"&&"			{ count(); return(AND_OP); }
"||"			{ count(); return(OR_OP); }
"<="			{ count(); return(LE_OP); }
">="			{ count(); return(GE_OP); }
"=="			{ count(); return(EQ_OP); }
"!="			{ count(); return(NE_OP); }
";"				{ count(); return(SEMICOLON); }
("{"|"<%")		{ count(); return(LEFTBRACES); }
("}"|"%>")		{ count(); return(RIGHTBRACES); }
","				{ count(); return(COMMA); }
":"				{ count(); return(COLON); }
"="				{ count(); return(SIGN); }
"("				{ count(); return(LPAREN); }
")"				{ count(); return(RPAREN); }
("["|"<:")		{ count(); return(LBRACKET); }
("]"|":>")		{ count(); return(RBRACKET); }
"."				{ count(); return(DOT); }
"&"				{ count(); return(AMPERSAND); }
"!"				{ count(); return(MARK); }
"~"				{ count(); return(TILDE); }
"-"				{ count(); return(MINUS); }
"+"				{ count(); return(PLUS); }
"*"				{ count(); return(TIMES); }
"/"				{ count(); return(OVER); }
"%"				{ count(); return(MOD); }
"<"				{ count(); return(LT_OP); }
">"				{ count(); return(GT_OP); }
"^"				{ count(); return(BITXOR_OP); }
"|"				{ count(); return(BITOR_OP); }
"?"				{ count(); return(ASK); }

[ \t\v\n\f]		{ count(); }
.			{ /* Add code to complain about unmatched characters */ }

%%
void comment(void)
{
	char c, prev = 0;
  
	while ((c = yyinput()) != 0)      /* (EOF maps to 0) */
	{
		if (c == '/' && prev == '*')
			return;
		prev = c;
	}
	yyerror("unterminated comment");
}


int column = 0;

void count(void)
{
	int i;

	for (i = 0; yytext[i] != '\0'; i++)
		if (yytext[i] == '\n')
			column = 0;
		else if (yytext[i] == '\t')
			column += 8 - (column % 8);
		else
			column++;

	ECHO;
}


int check_type(void)
{
/*
* pseudo code --- this is what it should check
*
*	if (yytext == type_name)
*		return TYPE_NAME;
*
*	return IDENTIFIER;
*/

/*
*	it actually will only return IDENTIFIER
*/

	return IDENTIFIER;
}

3、ANSI C 語法文件

%{
#include "stdio.h"

#ifndef YYSTYPE
#define YYSTYPE int
#endif

extern char yytext[];
extern int column;

void yyerror(char *text);
int yylex(void);
%}

%token PTR_OP		"->"
%token INC_OP		"++"
%token DEC_OP		"--"
%token LEFT_OP		"<<" 
%token RIGHT_OP		">>" 
%token LE_OP		"<=" 
%token GE_OP		">=" 
%token EQ_OP		"==" 
%token NE_OP		"!="
%token AND_OP		"&&" 
%token OR_OP		"||"
%token MUL_ASSIGN	"*=" 
%token DIV_ASSIGN	"/=" 
%token MOD_ASSIGN	"%="
%token ADD_ASSIGN	"+="
%token SUB_ASSIGN	"-="
%token LEFT_ASSIGN  "<<="	
%token RIGHT_ASSIGN ">>="
%token AND_ASSIGN	"&="
%token XOR_ASSIGN	"^="
%token OR_ASSIGN	"|=" 
%token ELLIPSIS		"..."

%token SEMICOLON 	";"	
%token LEFTBRACES	"{"
%token RIGHTBRACES	"}"
%token COMMA		","
%token COLON		":"	
%token SIGN			"="
%token LPAREN		"("
%token RPAREN		")"
%token LBRACKET		"["
%token RBRACKET		"]"
%token DOT			"."
%token AMPERSAND	"&"
%token MARK			"!"
%token TILDE		"~"
%token MINUS		"-"
%token PLUS			"+"
%token TIMES		"*"
%token OVER			"/"
%token MOD			"%"
%token LT_OP		"<"
%token GT_OP		">"
%token BITXOR_OP	"^"
%token BITOR_OP		"|"
%token ASK			"?"

%token TYPE_NAME
%token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
%token TYPEDEF EXTERN STATIC AUTO REGISTER
%token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID 
%token BOOL COMPLEX IMAGINARY INLINE RESTRICT
%token STRUCT UNION ENUM 
%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN

%start translation_unit

%%

primary_expression
	: IDENTIFIER
	| CONSTANT
	| STRING_LITERAL
	| "(" expression ")"
	;

postfix_expression
	: primary_expression
	| postfix_expression "[" expression "]"
	| postfix_expression "(" ")"
	| postfix_expression "(" argument_expression_list ")"
	| postfix_expression "." IDENTIFIER
	| postfix_expression "->" IDENTIFIER
	| postfix_expression "++"
	| postfix_expression "--"
	;

argument_expression_list
	: assignment_expression
	| argument_expression_list "," assignment_expression
	;

unary_expression
	: postfix_expression
	| "++" unary_expression
	| "--" unary_expression
	| unary_operator cast_expression
	| SIZEOF unary_expression
	| SIZEOF "(" type_name ")"
	;

unary_operator
	: "&"
	| "*"
	| "+"
	| "-"
	| "~"
	| "!"
	;

cast_expression
	: unary_expression
	| "(" type_name ")" cast_expression
	;

multiplicative_expression
	: cast_expression
	| multiplicative_expression "*" cast_expression
	| multiplicative_expression "/" cast_expression
	| multiplicative_expression "%" cast_expression
	;

additive_expression
	: multiplicative_expression
	| additive_expression "+" multiplicative_expression
	| additive_expression "-" multiplicative_expression
	;

shift_expression
	: additive_expression
	| shift_expression "<<" additive_expression
	| shift_expression ">>" additive_expression
	;

relational_expression
	: shift_expression
	| relational_expression "<" shift_expression
	| relational_expression ">" shift_expression
	| relational_expression "<=" shift_expression
	| relational_expression ">=" shift_expression
	;

equality_expression
	: relational_expression
	| equality_expression "==" relational_expression
	| equality_expression "!=" relational_expression
	;

and_expression
	: equality_expression
	| and_expression "&" equality_expression
	;

exclusive_or_expression
	: and_expression
	| exclusive_or_expression "^" and_expression
	;

inclusive_or_expression
	: exclusive_or_expression
	| inclusive_or_expression "|" exclusive_or_expression
	;

logical_and_expression
	: inclusive_or_expression
	| logical_and_expression "&&" inclusive_or_expression
	;

logical_or_expression
	: logical_and_expression
	| logical_or_expression "||" logical_and_expression
	;

conditional_expression
	: logical_or_expression
	| logical_or_expression "?" expression ":" conditional_expression
	;

assignment_expression
	: conditional_expression
	| unary_expression assignment_operator assignment_expression
	;

assignment_operator
	: "="
	| "*="
	| "/="
	| "%="
	| "+="
	| "-="
	| "<<="
	| ">>="
	| "&="
	| "^="
	| "|="
	;

expression
	: assignment_expression
	| expression "," assignment_expression
	;

constant_expression
	: conditional_expression
	;

declaration
	: declaration_specifiers ";"
	| declaration_specifiers init_declarator_list ";"
	;

declaration_specifiers
	: storage_class_specifier
	| storage_class_specifier declaration_specifiers
	| type_specifier
	| type_specifier declaration_specifiers
	| type_qualifier
	| type_qualifier declaration_specifiers
	;

init_declarator_list
	: init_declarator
	| init_declarator_list "," init_declarator
	;

init_declarator
	: declarator
	| declarator "=" initializer
	;

storage_class_specifier
	: TYPEDEF
	| EXTERN
	| STATIC
	| AUTO
	| REGISTER
	;

type_specifier
	: VOID
	| CHAR
	| SHORT
	| INT
	| LONG
	| FLOAT
	| DOUBLE
	| SIGNED
	| UNSIGNED
	| struct_or_union_specifier
	| enum_specifier
	| TYPE_NAME
	;

struct_or_union_specifier
	: struct_or_union IDENTIFIER "{" struct_declaration_list "}"
	| struct_or_union "{" struct_declaration_list "}"
	| struct_or_union IDENTIFIER
	;

struct_or_union
	: STRUCT
	| UNION
	;

struct_declaration_list
	: struct_declaration
	| struct_declaration_list struct_declaration
	;

struct_declaration
	: specifier_qualifier_list struct_declarator_list ";"
	;

specifier_qualifier_list
	: type_specifier specifier_qualifier_list
	| type_specifier
	| type_qualifier specifier_qualifier_list
	| type_qualifier
	;

struct_declarator_list
	: struct_declarator
	| struct_declarator_list "," struct_declarator
	;

struct_declarator
	: declarator
	| ":" constant_expression
	| declarator ":" constant_expression
	;

enum_specifier
	: ENUM "{" enumerator_list "}"
	| ENUM IDENTIFIER "{" enumerator_list "}"
	| ENUM IDENTIFIER
	;

enumerator_list
	: enumerator
	| enumerator_list "," enumerator
	;

enumerator
	: IDENTIFIER
	| IDENTIFIER "=" constant_expression
	;

type_qualifier
	: CONST
	| VOLATILE
	;

declarator
	: pointer direct_declarator
	| direct_declarator
	;

direct_declarator
	: IDENTIFIER
	| "(" declarator ")"
	| direct_declarator "[" constant_expression "]"
	| direct_declarator "[" "]"
	| direct_declarator "(" parameter_type_list ")"
	| direct_declarator "(" identifier_list ")"
	| direct_declarator "(" ")"
	;

pointer
	: "*"
	| "*" type_qualifier_list
	| "*" pointer
	| "*" type_qualifier_list pointer
	;

type_qualifier_list
	: type_qualifier
	| type_qualifier_list type_qualifier
	;


parameter_type_list
	: parameter_list
	| parameter_list "," "..."
	;

parameter_list
	: parameter_declaration
	| parameter_list "," parameter_declaration
	;

parameter_declaration
	: declaration_specifiers declarator
	| declaration_specifiers abstract_declarator
	| declaration_specifiers
	;

identifier_list
	: IDENTIFIER
	| identifier_list "," IDENTIFIER
	;

type_name
	: specifier_qualifier_list
	| specifier_qualifier_list abstract_declarator
	;

abstract_declarator
	: pointer
	| direct_abstract_declarator
	| pointer direct_abstract_declarator
	;

direct_abstract_declarator
	: "(" abstract_declarator ")"
	| "[" "]"
	| "[" constant_expression "]"
	| direct_abstract_declarator "[" "]"
	| direct_abstract_declarator "[" constant_expression "]"
	| "(" ")"
	| "(" parameter_type_list ")"
	| direct_abstract_declarator "(" ")"
	| direct_abstract_declarator "(" parameter_type_list ")"
	;

initializer
	: assignment_expression
	| "{" initializer_list "}"
	| "{" initializer_list "," "}"
	;

initializer_list
	: initializer
	| initializer_list "," initializer
	;

statement
	: labeled_statement
	| compound_statement
	| expression_statement
	| selection_statement
	| iteration_statement
	| jump_statement
	;

labeled_statement
	: IDENTIFIER ":" statement
	| CASE constant_expression ":" statement
	| DEFAULT ":" statement
	;

compound_statement
	: "{" "}"
	| "{" statement_list "}"
	| "{" declaration_list "}"
	| "{" declaration_list statement_list "}"
	;

declaration_list
	: declaration
	| declaration_list declaration
	;

statement_list
	: statement
	| statement_list statement
	;

expression_statement
	: ";"
	| expression ";"
	;

selection_statement
	: IF "(" expression ")" statement
	| IF "(" expression ")" statement ELSE statement
	| SWITCH "(" expression ")" statement
	;

iteration_statement
	: WHILE "(" expression ")" statement
	| DO statement WHILE "(" expression ")" ";"
	| FOR "(" expression_statement expression_statement ")" statement
	| FOR "(" expression_statement expression_statement expression ")" statement
	;

jump_statement
	: GOTO IDENTIFIER ";"
	| CONTINUE ";"
	| BREAK ";"
	| RETURN ";"
	| RETURN expression ";"
	;

translation_unit
	: external_declaration
	| translation_unit external_declaration
	;

external_declaration
	: function_definition
	| declaration
	;

function_definition
	: declaration_specifiers declarator declaration_list compound_statement
	| declaration_specifiers declarator compound_statement
	| declarator declaration_list compound_statement
	| declarator compound_statement
	;

%%

int main(void)
{
	yyparse();
	
	system("PAUSE");
	return 0;
}

void yyerror(char*s)
{
	fflush(stdout);
	printf("\n%*s\n%*s\n", column, "^", column, s);
}

4、ISO C 標準語法文件(未整理,請參考前兩個即可整理)

# FILE:         c.cfg
# PURPOSE:      The Grammar for Standard C with _opt factored out,
#               and the oversight for enumeration-constant corrected.
#
# LANGUAGE:     C
# TARGET:       C++
# Note: default the TITLE:  to Cfg
#
# NOTE:		This grammar is closely related to rc.cfg
#		which used as input to awk
#
# TRANSCRIBED:  McKeeman @ WangInst     1986
# MODIFIED:     {0} McKeeman -- 89.08.15 -- original
# 		{1} Aurenz   -- 89.09.07 -- rc parser complete
# 		{2} Aki      -- 92.01.06 -- support awk processing
# 		{3} McKeeman -- 92.02.25 -- restore ANSI details
# 		{4} McKeeman -- 93.01.08 -- removed : after lhs
#
#Input format for c.cfg:
#
#  1) comments must have a '#' in column 1, 
#     or be an entirely empty line
#
#  2) The format of a rule is:
#       lhs
#           rhs1
#           rhs2
#           ...
#           rhsN
#
#     The left hand side must start with a non-blank in column 1.
#
#     The right hand side(s) must start with a blank in column 1.
#     The r.h.s. must be on one line.
#     Blanks must be used to separate tokens in the r.h.s.
#
#  3) An empty rhs is specified with the predefined keyword:
#        _E_M_P_T_Y_R_U_L_E_
#     as the only token on the line.
#
#[begin example]
#
# ,---- column 1
# |
# v
#
# # rule xxx
# xxx
#     yyy + yyy
#     zzz xxx
#
# # rule yyy (1st alternative is empty)
# yyy
#     _E_M_P_T_Y_R_U_L_E_
#     yyy - xxx
#
# # rule zzz (empty)
# zzz
#     _E_M_P_T_Y_R_U_L_E_
#
#[end example]
# 


# 
# C expression rules
# 

primary-expression
    identifier
    constant
    string-literal
    ( expression )

postfix-expression
    primary-expression
    postfix-expression [ expression ]
    postfix-expression ( )
    postfix-expression ( argument-expression-list )
    postfix-expression . identifier
    postfix-expression -> identifier
    postfix-expression ++
    postfix-expression --

argument-expression-list
    assignment-expression
    argument-expression-list , assignment-expression

unary-expression
    postfix-expression
    ++ unary-expression
    -- unary-expression
    unary-operator cast-expression
    sizeof unary-expression
    sizeof ( type-name )

unary-operator
    &
    *
    +
    -
    ~
    !

cast-expression
    unary-expression
    ( type-name ) cast-expression

multiplicative-expression
    cast-expression
    multiplicative-expression * cast-expression
    multiplicative-expression / cast-expression
    multiplicative-expression % cast-expression

additive-expression
    multiplicative-expression
    additive-expression + multiplicative-expression
    additive-expression - multiplicative-expression

shift-expression
    additive-expression
    shift-expression << additive-expression
    shift-expression >> additive-expression

relational-expression
    shift-expression
    relational-expression < shift-expression
    relational-expression > shift-expression
    relational-expression <= shift-expression
    relational-expression >= shift-expression

equality-expression
    relational-expression
    equality-expression == relational-expression
    equality-expression != relational-expression

AND-expression
    equality-expression
    AND-expression & equality-expression

exclusive-OR-expression
    AND-expression
    exclusive-OR-expression ^ AND-expression

inclusive-OR-expression
    exclusive-OR-expression
    inclusive-OR-expression | exclusive-OR-expression

logical-AND-expression
    inclusive-OR-expression
    logical-AND-expression && inclusive-OR-expression

logical-OR-expression
    logical-AND-expression
    logical-OR-expression || logical-AND-expression

conditional-expression
    logical-OR-expression
    logical-OR-expression ? expression : conditional-expression

assignment-expression
    conditional-expression
    unary-expression assignment-operator assignment-expression

assignment-operator
    =
    *=
    /=
    %=
    +=
    -=
    <<=
    >>=
    &=
    ^=
    |=

expression
    assignment-expression
    expression , assignment-expression

constant-expression
    conditional-expression

#
# C declaration rules
#

declaration
    declaration-specifiers ;
    declaration-specifiers init-declarator-list ;

declaration-specifiers
    storage-class-specifier
    type-specifier
    type-qualifier
    storage-class-specifier declaration-specifiers
    type-specifier          declaration-specifiers
    type-qualifier          declaration-specifiers

init-declarator-list
    init-declarator
    init-declarator-list , init-declarator

init-declarator
    declarator
    declarator = initializer

storage-class-specifier
    typedef
    extern
    static
    auto
    register

type-specifier
    void
    char
    short
    int
    long
    float
    double
    signed
    unsigned
    struct-or-union-specifier
    enum-specifier
    typedef-name

struct-or-union-specifier
    struct-or-union { struct-declaration-list }
    struct-or-union identifier { struct-declaration-list }
    struct-or-union identifier

struct-or-union
    struct
    union

struct-declaration-list
    struct-declaration
    struct-declaration-list struct-declaration

struct-declaration
    specifier-qualifier-list struct-declarator-list ;

specifier-qualifier-list
    type-specifier
    type-qualifier
    type-specifier specifier-qualifier-list 
    type-qualifier specifier-qualifier-list 

struct-declarator-list
    struct-declarator
    struct-declarator-list , struct-declarator

struct-declarator
    declarator
     constant-expression
    declarator  constant-expression

enum-specifier
    enum { enumerator-list }
    enum identifier { enumerator-list }
    enum identifier

enumerator-list
    enumerator
    enumerator-list , enumerator

enumerator
    enumeration-constant
    enumeration-constant = constant-expression

enumeration-constant
    identifier

type-qualifier
    const
    volatile

declarator
    direct-declarator
    pointer direct-declarator

direct-declarator
    identifier
    ( declarator )
    direct-declarator [ ]
    direct-declarator [ constant-expression ]
    direct-declarator ( )
    direct-declarator ( parameter-type-list )
    direct-declarator ( identifier-list )

pointer
     *
     * pointer
     * type-qualifier-list
     * type-qualifier-list pointer

type-qualifier-list
    type-qualifier
    type-qualifier-list type-qualifier

parameter-type-list
    parameter-list
    parameter-list , ...

parameter-list
    parameter-declaration
    parameter-list , parameter-declaration

parameter-declaration
    declaration-specifiers declarator
    declaration-specifiers
    declaration-specifiers abstract-declarator

identifier-list
    identifier
    identifier-list , identifier

type-name
    specifier-qualifier-list
    specifier-qualifier-list abstract-declarator

abstract-declarator
    pointer
    direct-abstract-declarator
    pointer direct-abstract-declarator

direct-abstract-declarator
    ( abstract-declarator )
    [ ]
    [ constant-expression ]
    ( )
    ( parameter-type-list )
    direct-abstract-declarator [ ]
    direct-abstract-declarator [ constant-expression ]
    direct-abstract-declarator ( )
    direct-abstract-declarator ( parameter-type-list )

typedef-name
    identifier

initializer
    assignment-expression
    { initializer-list }
    { initializer-list , }

initializer-list
    initializer
    initializer-list , initializer

#
# C statement rules
#

statement
    labeled-statement
    compound-statement
    expression-statement
    selection-statement
    iteration-statement
    jump-statement

labeled-statement
    identifier : statement
    case constant-expression : statement
    default : statement

compound-statement
    { }
    { declaration-list }
    { statement-list }
    { declaration-list statement-list }

declaration-list
    declaration
    declaration-list declaration

statement-list
    statement
    statement-list statement

expression-statement
    ;
    expression ;

selection-statement
    if ( expression ) statement
    if ( expression ) statement else statement
    switch ( expression ) statement

iteration-statement
    while ( expression ) statement
    do statement while ( expression ) ;
    for (            ;            ;            ) statement
    for (            ;            ; expression ) statement
    for (            ; expression ;            ) statement
    for (            ; expression ; expression ) statement
    for ( expression ;            ;            ) statement
    for ( expression ;            ; expression ) statement
    for ( expression ; expression ;            ) statement
    for ( expression ; expression ; expression ) statement

jump-statement
    goto identifier ;
    continue ;
    break ;
    return ;
    return expression ;

translation-unit
    external-declaration
    translation-unit external-declaration

external-declaration
    function-definition
    declaration

function-definition
                           declarator                  compound-statement
    declaration-specifiers declarator                  compound-statement
                           declarator declaration-list compound-statement
    declaration-specifiers declarator declaration-list compound-statement

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章