c语言 bnf,c语言的bnf

c语言 bnf,c语言的bnftokenint constchar constfloat constidstrin const translation unit external decl translation unitexternal decl external decl function definition decl function definition decl

%token int_const char_const float_const id string enumeration_const

%%

translation_unit: external_decl

| translation_unit external_decl

;

external_decl: function_definition

| decl

;

function_definition: decl_specs declarator decl_list compound_stat

|declarator decl_list compound_stat

| decl_specs declaratorcompound_stat

|declarator compound_stat

;

decl: decl_specs init_declarator_list ‘;’

| decl_specs’;’

;

decl_list: decl

| decl_list decl

;

decl_specs: storage_class_spec decl_specs

| storage_class_spec

| type_spec decl_specs

| type_spec

| type_qualifier decl_specs

| type_qualifier

;

storage_class_spec: ‘auto’ | ‘register’ | ‘static’ | ‘extern’ | ‘typedef’

;

type_spec: ‘void’ | ‘char’ | ‘short’ | ‘int’ | ‘long’ | ‘float’

| ‘double’ | ‘signed’ | ‘unsigned’

| struct_or_union_spec

| enum_spec

| typedef_name

;

type_qualifier: ‘const’ | ‘volatile’

;

struct_or_union_spec: struct_or_union id ‘{‘ struct_decl_list ‘}’

| struct_or_union'{‘ struct_decl_list ‘}’

| struct_or_union id

;

struct_or_union: ‘struct’ | ‘union’

;

struct_decl_list: struct_decl

| struct_decl_list struct_decl

;

init_declarator_list: init_declarator

| init_declarator_list ‘,’ init_declarator

;

init_declarator: declarator

| declarator ‘=’ initializer

;

struct_decl: spec_qualifier_list struct_declarator_list ‘;’

;

spec_qualifier_list: type_spec spec_qualifier_list

| type_spec

| type_qualifier spec_qualifier_list

| type_qualifier

;

struct_declarator_list: struct_declarator

| struct_declarator_list ‘,’ struct_declarator

;

struct_declarator: declarator

| declarator ‘:’ const_exp

|’:’ const_exp

;

enum_spec: ‘enum’ id ‘{‘ enumerator_list ‘}’

| ‘enum”{‘ enumerator_list ‘}’

| ‘enum’ id

;

enumerator_list: enumerator

| enumerator_list ‘,’ enumerator

;

enumerator: id

| id ‘=’ const_exp

;

declarator: pointer direct_declarator

|direct_declarator

;

direct_declarator: id

| ‘(‘ declarator ‘)’

| direct_declarator ‘[‘ const_exp ‘]’

| direct_declarator ‘[”]’

| direct_declarator ‘(‘ param_type_list ‘)’

| direct_declarator ‘(‘ id_list ‘)’

| direct_declarator ‘(”)’

;

pointer: ‘*’ type_qualifier_list

| ‘*’

| ‘*’ type_qualifier_list pointer

| ‘*’pointer

;

type_qualifier_list: type_qualifier

| type_qualifier_list type_qualifier

;

param_type_list: param_list

| param_list ‘,’ ‘…’

;

param_list: param_decl

| param_list ‘,’ param_decl

;

param_decl: decl_specs declarator

| decl_specs abstract_declarator

| decl_specs

;

id_list: id

| id_list ‘,’ id

;

initializer: assignment_exp

| ‘{‘ initializer_list ‘}’

| ‘{‘ initializer_list ‘,’ ‘}’

;

initializer_list: initializer

| initializer_list ‘,’ initializer

;

type_name: spec_qualifier_list abstract_declarator

| spec_qualifier_list

;

abstract_declarator: pointer

| pointer direct_abstract_declarator

|direct_abstract_declarator

;

direct_abstract_declarator: ‘(‘ abstract_declarator ‘)’

| direct_abstract_declarator ‘[‘ const_exp ‘]’

|'[‘ const_exp ‘]’

| direct_abstract_declarator ‘[”]’

|'[”]’

| direct_abstract_declarator ‘(‘ param_type_list ‘)’

|'(‘ param_type_list ‘)’

| direct_abstract_declarator ‘(”)’

|'(”)’

;

typedef_name: id

;

stat: labeled_stat

| exp_stat

| compound_stat

| selection_stat

| iteration_stat

| jump_stat

;

labeled_stat: id ‘:’ stat

| ‘case’ const_exp ‘:’ stat

| ‘default’ ‘:’ stat

;

exp_stat: exp ‘;’

|’;’

;

compound_stat: ‘{‘ decl_list stat_list ‘}’

| ‘{‘stat_list ‘}’

| ‘{‘ decl_list’}’

| ‘{”}’

;

stat_list: stat

| stat_list stat

;

selection_stat: ‘if’ ‘(‘ exp ‘)’ stat

| ‘if’ ‘(‘ exp ‘)’ stat ‘else’ stat

| ‘switch’ ‘(‘ exp ‘)’ stat

;

iteration_stat: ‘while’ ‘(‘ exp ‘)’ stat

| ‘do’ stat ‘while’ ‘(‘ exp ‘)’ ‘;’

| ‘for’ ‘(‘ exp ‘;’ exp ‘;’ exp ‘)’ stat

| ‘for’ ‘(‘ exp ‘;’ exp ‘;”)’ stat

| ‘for’ ‘(‘ exp ‘;”;’ exp ‘)’ stat

| ‘for’ ‘(‘ exp ‘;”;”)’ stat

| ‘for’ ‘(”;’ exp ‘;’ exp ‘)’ stat

| ‘for’ ‘(”;’ exp ‘;”)’ stat

| ‘for’ ‘(”;”;’ exp ‘)’ stat

| ‘for’ ‘(”;”;”)’ stat

;

jump_stat: ‘goto’ id ‘;’

| ‘continue’ ‘;’

| ‘break’ ‘;’

| ‘return’ exp ‘;’

| ‘return”;’

;

exp: assignment_exp

| exp ‘,’ assignment_exp

;

assignment_exp: conditional_exp

| unary_exp assignment_operator assignment_exp

;

assignment_operator: ‘=’ | ‘*=’ | ‘/=’ | ‘%=’ | ‘+=’ | ‘-=’ | ‘<<=’

| ‘>>=’ | ‘&=’ | ‘^=’ | ‘|=’

;

conditional_exp: logical_or_exp

| logical_or_exp ‘?’ exp ‘:’ conditional_exp

;

const_exp: conditional_exp

;

logical_or_exp: logical_and_exp

| logical_or_exp ‘||’ logical_and_exp

;

logical_and_exp: inclusive_or_exp

| logical_and_exp ‘&&’ inclusive_or_exp

;

inclusive_or_exp: exclusive_or_exp

| inclusive_or_exp ‘|’ exclusive_or_exp

;

exclusive_or_exp: and_exp

| exclusive_or_exp ‘^’ and_exp

;

and_exp: equality_exp

| and_exp ‘&’ equality_exp

;

equality_exp: relational_exp

| equality_exp ‘==’ relational_exp

| equality_exp ‘!=’ relational_exp

;

relational_exp: shift_expression

| relational_exp ‘| relational_exp ‘>’ shift_expression

| relational_exp ‘<=’ shift_expression

| relational_exp ‘>=’ shift_expression

;

shift_expression: additive_exp

| shift_expression ‘>’ additive_exp

;

additive_exp: mult_exp

| additive_exp ‘+’ mult_exp

| additive_exp ‘-‘ mult_exp

;

mult_exp: cast_exp

| mult_exp ‘*’ cast_exp

| mult_exp ‘/’ cast_exp

| mult_exp ‘%’ cast_exp

;

cast_exp: unary_exp

| ‘(‘ type_name ‘)’ cast_exp

;

unary_exp: postfix_exp

| ‘++’ unary_exp

| ‘–‘ unary_exp

| unary_operator cast_exp

| ‘sizeof’ unary_exp

| ‘sizeof’ ‘(‘ type_name ‘)’

;

unary_operator: ‘&’ | ‘*’ | ‘+’ | ‘-‘ | ‘~’ | ‘!’

;

postfix_exp: primary_exp

| postfix_exp ‘[‘ exp ‘]’

| postfix_exp ‘(‘ argument_exp_list ‘)’

| postfix_exp ‘(”)’

| postfix_exp ‘.’ id

| postfix_exp ‘->’ id

| postfix_exp ‘++’

| postfix_exp ‘–‘

;

primary_exp: id

| const

| string

| ‘(‘ exp ‘)’

;

argument_exp_list: assignment_exp

| argument_exp_list ‘,’ assignment_exp

;

const: int_const

| char_const

| float_const

| enumeration_const

;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231399.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • vue axios跨域问题的三种解决方案_vue如何实现跨域

    vue axios跨域问题的三种解决方案_vue如何实现跨域vue3项目,axios跨域处理,代理

    2025年9月6日
    6
  • windows关闭/开启休眠命令行

    windows关闭/开启休眠命令行C:\hiberfil.sys占用空间过大,可以考虑关闭休眠重新开启

    2022年8月1日
    5
  • Qt5 QMediaPlayer 音乐播放器

    Qt5 QMediaPlayer 音乐播放器   暑假用Qt写的音乐播放器,界面有点丑,然后功能也有点少,还有一些bug,然后现在趁着寒假的时间把之前的界面给改了一下,并添加了一些功能,修改了一些bug,实现功能包括基本的歌曲播放暂停,上一首,下一首,添加歌曲,添加为我喜欢,添加至我的收藏,最近播放,列表的右键菜单,主窗口的右键菜单,删除歌曲,多选,查看歌曲信息,改变播放模式(顺序播放,随机播放,单曲循环),歌曲定位,清除列表,换皮肤…

    2022年5月30日
    41
  • 基于WDM的专用USB设备的驱动程序开发[通俗易懂]

    基于WDM的专用USB设备的驱动程序开发[通俗易懂]1引言目前对于诸如USB鼠标、键盘等这样的计算机标准外设,Windows系统已经提供了标准的驱动程序,用户无需再进行任何开发工作。而开发专用USB设备,需要开发专用的驱动程序。Windows2000/XP操作系统不允许用户程序直接访问硬件设备。为了实现对硬件设备的访问和控制,必须通过操作系统所认可的驱动程序对硬件设备实现间接访问和控制。驱动程序通常被认为是操作系统的组成部分,所以,开发驱动程序有严

    2022年8月30日
    8
  • 使用jprobe建设镜面层叠的原则和见解

    使用jprobe建设镜面层叠的原则和见解

    2022年1月6日
    41
  • snmp trap报文格式_linux接收snmptrap

    snmp trap报文格式_linux接收snmptrap转载地址:https://blog.csdn.net/eric_sunah/article/details/19557683SNMP的报文格式SNMP代理和管理站通过SNMP协议中的标准消息进行通信,每个消息都是一个单独的数据报。SNMP使用UDP(用户数据报协议)作为第四层协议(传输协议),进行无连接操作。SNMP消息报文包含两个部分:SNMP报头和协议数据单元PDU。在实际网络传输环境下,S…

    2022年8月21日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号