⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-grammer.doc

📁 使用yacc和lex编写的cmm语言的词法分析和语法分析程序.
💻 DOC
📖 第 1 页 / 共 2 页
字号:
%start program
%token IDENTIFIER
%token TYPENAME
%token SCSPEC			
%token STATIC			
%token TYPESPEC
%token TYPE_QUAL
%token OBJC_TYPE_QUAL
%token CONSTANT
%token STRING
%token ELLIPSIS
%token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
%token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
%token ATTRIBUTE EXTENSION LABEL
%token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P
%token FUNC_NAME OFFSETOF
%nonassoc IF
%nonassoc ELSE
%right <code> ASSIGN '='
%right <code> '?' '
%left <code> OROR
%left <code> ANDAND
%left <code> '|'
%left <code> '^'
%left <code> '&'
%left <code> EQCOMPARE
%left <code> ARITHCOMPARE
%left <code> LSHIFT RSHIFT
%left <code> '+' '-'
%left <code> '*' '/' '%'
%right <code> UNARY PLUSPLUS MINUSMINUS
%left HYPERUNARY
%left <code> POINTSAT '.' '(' '['
%token AT_INTERFACE AT_IMPLEMENTATION AT_END AT_SELECTOR AT_DEFS AT_ENCODE
%token CLASSNAME AT_PUBLIC AT_PRIVATE AT_PROTECTED AT_PROTOCOL
%token AT_CLASS AT_ALIAS
%token AT_THROW AT_TRY AT_CATCH AT_FINALLY AT_SYNCHRONIZED
%token OBJC_STRING
%type <code> unop
%type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
%type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
%type <ttype> identifier IDENTIFIER TYPENAME CONSTANT STRING FUNC_NAME
%type <ttype> nonnull_exprlist exprlist
%type <exprtype> expr expr_no_commas cast_expr unary_expr primary
%type <dsptype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea
%type <dsptype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea
%type <dsptype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea
%type <dsptype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea
%type <dsptype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea
%type <dsptype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea
%type <dsptype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea
%type <dsptype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea
%type <dsptype> declspecs_ts declspecs_nots
%type <dsptype> declspecs_ts_nosa declspecs_nots_nosa
%type <dsptype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs
%type <dsptype> maybe_type_quals_attrs
%type <tstype> typespec_nonattr typespec_attr
%type <tstype> typespec_reserved_nonattr typespec_reserved_attr
%type <tstype> typespec_nonreserved_nonattr
%type <ttype> offsetof_member_designator
%type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile
%type <ttype> initdecls notype_initdecls initdcl notype_initdcl
%type <exprtype> init
%type <ttype> simple_asm_expr maybeasm asm_stmt asm_argument asm_string
%type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
%type <ttype> maybe_attribute attributes attribute attribute_list attrib
%type <ttype> any_word
%type <ttype> compstmt compstmt_start compstmt_primary_start
%type <ttype> stmt label stmt_nocomp start_break start_continue
%type <ttype> c99_block_start c99_block_lineno_labeled_stmt
%type <ttype> if_statement_1 if_statement_2
%type <dtrtype> declarator
%type <dtrtype> notype_declarator after_type_declarator
%type <dtrtype> parm_declarator
%type <dtrtype> parm_declarator_starttypename parm_declarator_nostarttypename
%type <dtrtype> array_declarator
%type <tstype> structsp_attr structsp_nonattr
%type <ttype> component_decl_list component_decl_list2
%type <ttype> component_decl components components_notype component_declarator
%type <ttype> component_notype_declarator
%type <ttype> enumlist enumerator
%type <ttype> struct_head union_head enum_head
%type <typenametype> typename
%type <dtrtype> absdcl absdcl1 absdcl1_ea absdcl1_noea direct_absdcl1
%type <parmtype> absdcl_maybe_attribute
%type <ttype> condition xexpr for_cond_expr for_incr_expr
%type <parmtype> parm firstparm
%type <ttype> identifiers
%type <arginfotype> parms parmlist parmlist_1 parmlist_2
%type <arginfotype> parmlist_or_identifiers parmlist_or_identifiers_1
%type <ttype> identifiers_or_typenames
%type <itype> setspecs setspecs_fp extension
%type <location> save_location
%type <otype> save_obstack_position
%%
program
	:| extdefs
extdefs
	: save_obstack_position 			
	| extdefs save_obstack_position
extdef
	: fndef
	| datadef
	| asmdef
	| extension extdef
save_obstack_position
	: ;
datadef
	: setspecs notype_initdecls ';'
	| declspecs_nots setspecs notype_initdecls ';'
	| declspecs_ts setspecs initdecls ';'
	| declspecs ';'
	| error ';'
	| error '}'
	| ';'
fndef
	: declspecs_ts setspecs declarator
	old_style_parm_decls save_location
	compstmt_or_error
	| declspecs_ts setspecs declarator error
	| declspecs_nots setspecs notype_declarator
	old_style_parm_decls save_location
	compstmt_or_error
	| declspecs_nots setspecs notype_declarator error
	| setspecs notype_declarator
	old_style_parm_decls save_location
	compstmt_or_error
	| setspecs notype_declarator error
identifier
	: IDENTIFIER
	| TYPENAME
unop
	: | '-'
	| '+'
	| PLUSPLUS
	| MINUSMINUS
	| '~'
	| '!'
expr
	: | expr ',' expr_no_commas
exprlist
	: | nonnull_exprlist
nonnull_exprlist
	: expr_no_commas
	| nonnull_exprlist ',' expr_no_commas
unary_expr
	: primary
	| '*' cast_expr   %prec UNARY
	| extension cast_expr	  %prec UNARY
	| unop cast_expr  %prec UNARY
	| ANDAND identifier
	| sizeof unary_expr  %prec UNARY
	| sizeof '(' typename ')'  %prec HYPERUNARY
	| alignof unary_expr  %prec UNARY
	| alignof '(' typename ')'  %prec HYPERUNARY
	| REALPART cast_expr %prec UNARY
	| IMAGPART cast_expr %prec UNARY
sizeof
	: SIZEOF 	;
alignof
	: ALIGNOF 	;
typeof
	: TYPEOF 	;
cast_expr
	: unary_expr
	| '(' typename ')' cast_expr  %prec UNARY
expr_no_commas
	: cast_expr
	| expr_no_commas '+' expr_no_commas
	| expr_no_commas '-' expr_no_commas
	| expr_no_commas '*' expr_no_commas
	| expr_no_commas '/' expr_no_commas
	| expr_no_commas '%' expr_no_commas
	| expr_no_commas LSHIFT expr_no_commas
	| expr_no_commas RSHIFT expr_no_commas
	| expr_no_commas ARITHCOMPARE expr_no_commas
	| expr_no_commas EQCOMPARE expr_no_commas
	| expr_no_commas '&' expr_no_commas
	| expr_no_commas '|' expr_no_commas
	| expr_no_commas '^' expr_no_commas
	| expr_no_commas ANDAND
	expr_no_commas
	| expr_no_commas OROR
	expr_no_commas
	| expr_no_commas '?'
	expr ':'
	expr_no_commas
	| expr_no_commas '?'
	':' expr_no_commas
	| expr_no_commas '=' expr_no_commas
	| expr_no_commas ASSIGN expr_no_commas
primary
	: IDENTIFIER
	| CONSTANT
	| STRING
	| FUNC_NAME
	| '(' typename ')' '{'
	  initlist_maybe_comma '}'  %prec UNARY
	| '(' expr ')'
	| '(' error ')'
	| compstmt_primary_start compstmt_nostart ')'
	| compstmt_primary_start error ')'
	| primary '(' exprlist ')'   %prec '.'
	| VA_ARG '(' expr_no_commas ',' typename ')'
	| OFFSETOF '(' typename ','
	  offsetof_member_designator ')'
	| OFFSETOF '(' error ')'
	| CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ','
			  expr_no_commas ')'
	| CHOOSE_EXPR '(' error ')'
	| TYPES_COMPATIBLE_P '(' typename ',' typename ')'
	| TYPES_COMPATIBLE_P '(' error ')'
	| primary '[' expr ']'   %prec '.'
	| primary '.' identifier
	| primary POINTSAT identifier
	| primary PLUSPLUS
	| primary MINUSMINUS
offsetof_member_designator
	: identifier
	| offsetof_member_designator '.' identifier
	| offsetof_member_designator '[' expr ']'
old_style_parm_decls
	: | datadecls
lineno_datadecl
	: save_location datadecl
datadecls
	: lineno_datadecl
	| errstmt
	| datadecls lineno_datadecl
	| lineno_datadecl errstmt
datadecl
	: declspecs_ts_nosa setspecs initdecls ';'
	| declspecs_nots_nosa setspecs notype_initdecls ';'
	| declspecs_ts_nosa ';'
	| declspecs_nots_nosa ';'
lineno_decl
	: save_location decl
setspecs
	:
maybe_resetattrs
	: maybe_attribute
decl
	: declspecs_ts setspecs initdecls ';'
	| declspecs_nots setspecs notype_initdecls ';'
	| declspecs_ts setspecs nested_function
	| declspecs_nots setspecs notype_nested_function
	| declspecs ';'
	| extension decl
declspecs_nosc_nots_nosa_noea
	: TYPE_QUAL
	| declspecs_nosc_nots_nosa_noea TYPE_QUAL
	| declspecs_nosc_nots_nosa_ea TYPE_QUAL
declspecs_nosc_nots_nosa_ea
	: declspecs_nosc_nots_nosa_noea attributes
declspecs_nosc_nots_sa_noea
	: declspecs_nosc_nots_sa_noea TYPE_QUAL
	| declspecs_nosc_nots_sa_ea TYPE_QUAL
declspecs_nosc_nots_sa_ea
	: attributes
	| declspecs_nosc_nots_sa_noea attributes
declspecs_nosc_ts_nosa_noea
	: typespec_nonattr
	| declspecs_nosc_ts_nosa_noea TYPE_QUAL
	| declspecs_nosc_ts_nosa_ea TYPE_QUAL
	| declspecs_nosc_ts_nosa_noea typespec_reserved_nonattr
	| declspecs_nosc_ts_nosa_ea typespec_reserved_nonattr
	| declspecs_nosc_nots_nosa_noea typespec_nonattr
	| declspecs_nosc_nots_nosa_ea typespec_nonattr
declspecs_nosc_ts_nosa_ea
	: typespec_attr
	| declspecs_nosc_ts_nosa_noea attributes
	| declspecs_nosc_ts_nosa_noea typespec_reserved_attr
	| declspecs_nosc_ts_nosa_ea typespec_reserved_attr
	| declspecs_nosc_nots_nosa_noea typespec_attr
	| declspecs_nosc_nots_nosa_ea typespec_attr
declspecs_nosc_ts_sa_noea
	: declspecs_nosc_ts_sa_noea TYPE_QUAL
	| declspecs_nosc_ts_sa_ea TYPE_QUAL
	| declspecs_nosc_ts_sa_noea typespec_reserved_nonattr
	| declspecs_nosc_ts_sa_ea typespec_reserved_nonattr
	| declspecs_nosc_nots_sa_noea typespec_nonattr
	| declspecs_nosc_nots_sa_ea typespec_nonattr
declspecs_nosc_ts_sa_ea
	: declspecs_nosc_ts_sa_noea attributes
	| declspecs_nosc_ts_sa_noea typespec_reserved_attr
	| declspecs_nosc_ts_sa_ea typespec_reserved_attr
	| declspecs_nosc_nots_sa_noea typespec_attr
	| declspecs_nosc_nots_sa_ea typespec_attr
declspecs_sc_nots_nosa_noea
	: scspec
	| declspecs_sc_nots_nosa_noea TYPE_QUAL
	| declspecs_sc_nots_nosa_ea TYPE_QUAL
	| declspecs_nosc_nots_nosa_noea scspec
	| declspecs_nosc_nots_nosa_ea scspec
	| declspecs_sc_nots_nosa_noea scspec
	| declspecs_sc_nots_nosa_ea scspec
declspecs_sc_nots_nosa_ea
	: declspecs_sc_nots_nosa_noea attributes
declspecs_sc_nots_sa_noea
	: declspecs_sc_nots_sa_noea TYPE_QUAL
	| declspecs_sc_nots_sa_ea TYPE_QUAL
	| declspecs_nosc_nots_sa_noea scspec
	| declspecs_nosc_nots_sa_ea scspec
	| declspecs_sc_nots_sa_noea scspec
	| declspecs_sc_nots_sa_ea scspec
declspecs_sc_nots_sa_ea
	: declspecs_sc_nots_sa_noea attributes
declspecs_sc_ts_nosa_noea
	: declspecs_sc_ts_nosa_noea TYPE_QUAL
	| declspecs_sc_ts_nosa_ea TYPE_QUAL
	| declspecs_sc_ts_nosa_noea typespec_reserved_nonattr
	| declspecs_sc_ts_nosa_ea typespec_reserved_nonattr
	| declspecs_sc_nots_nosa_noea typespec_nonattr
	| declspecs_sc_nots_nosa_ea typespec_nonattr
	| declspecs_nosc_ts_nosa_noea scspec
	| declspecs_nosc_ts_nosa_ea scspec
	| declspecs_sc_ts_nosa_noea scspec
	| declspecs_sc_ts_nosa_ea scspec
declspecs_sc_ts_nosa_ea
	: declspecs_sc_ts_nosa_noea attributes
	| declspecs_sc_ts_nosa_noea typespec_reserved_attr
	| declspecs_sc_ts_nosa_ea typespec_reserved_attr
	| declspecs_sc_nots_nosa_noea typespec_attr
	| declspecs_sc_nots_nosa_ea typespec_attr
declspecs_sc_ts_sa_noea
	: declspecs_sc_ts_sa_noea TYPE_QUAL
	| declspecs_sc_ts_sa_ea TYPE_QUAL
	| declspecs_sc_ts_sa_noea typespec_reserved_nonattr
	| declspecs_sc_ts_sa_ea typespec_reserved_nonattr
	| declspecs_sc_nots_sa_noea typespec_nonattr
	| declspecs_sc_nots_sa_ea typespec_nonattr
	| declspecs_nosc_ts_sa_noea scspec
	| declspecs_nosc_ts_sa_ea scspec
	| declspecs_sc_ts_sa_noea scspec
	| declspecs_sc_ts_sa_ea scspec
declspecs_sc_ts_sa_ea
	: declspecs_sc_ts_sa_noea attributes
	| declspecs_sc_ts_sa_noea typespec_reserved_attr
	| declspecs_sc_ts_sa_ea typespec_reserved_attr
	| declspecs_sc_nots_sa_noea typespec_attr
	| declspecs_sc_nots_sa_ea typespec_attr
declspecs_ts
	: declspecs_nosc_ts_nosa_noea
	| declspecs_nosc_ts_nosa_ea
	| declspecs_nosc_ts_sa_noea
	| declspecs_nosc_ts_sa_ea
	| declspecs_sc_ts_nosa_noea
	| declspecs_sc_ts_nosa_ea
	| declspecs_sc_ts_sa_noea
	| declspecs_sc_ts_sa_ea
declspecs_nots
	: declspecs_nosc_nots_nosa_noea
	| declspecs_nosc_nots_nosa_ea
	| declspecs_nosc_nots_sa_noea
	| declspecs_nosc_nots_sa_ea
	| declspecs_sc_nots_nosa_noea
	| declspecs_sc_nots_nosa_ea
	| declspecs_sc_nots_sa_noea
	| declspecs_sc_nots_sa_ea
declspecs_ts_nosa
	: declspecs_nosc_ts_nosa_noea
	| declspecs_nosc_ts_nosa_ea
	| declspecs_sc_ts_nosa_noea
	| declspecs_sc_ts_nosa_ea
declspecs_nots_nosa
	: declspecs_nosc_nots_nosa_noea
	| declspecs_nosc_nots_nosa_ea
	| declspecs_sc_nots_nosa_noea
	| declspecs_sc_nots_nosa_ea
declspecs_nosc_ts
	: declspecs_nosc_ts_nosa_noea
	| declspecs_nosc_ts_nosa_ea
	| declspecs_nosc_ts_sa_noea
	| declspecs_nosc_ts_sa_ea
declspecs_nosc_nots
	: declspecs_nosc_nots_nosa_noea
	| declspecs_nosc_nots_nosa_ea
	| declspecs_nosc_nots_sa_noea
	| declspecs_nosc_nots_sa_ea
declspecs_nosc
	: declspecs_nosc_ts_nosa_noea
	| declspecs_nosc_ts_nosa_ea
	| declspecs_nosc_ts_sa_noea
	| declspecs_nosc_ts_sa_ea
	| declspecs_nosc_nots_nosa_noea
	| declspecs_nosc_nots_nosa_ea
	| declspecs_nosc_nots_sa_noea
	| declspecs_nosc_nots_sa_ea
declspecs
	: declspecs_nosc_nots_nosa_noea
	| declspecs_nosc_nots_nosa_ea
	| declspecs_nosc_nots_sa_noea
	| declspecs_nosc_nots_sa_ea
	| declspecs_nosc_ts_nosa_noea
	| declspecs_nosc_ts_nosa_ea
	| declspecs_nosc_ts_sa_noea
	| declspecs_nosc_ts_sa_ea
	| declspecs_sc_nots_nosa_noea
	| declspecs_sc_nots_nosa_ea
	| declspecs_sc_nots_sa_noea
	| declspecs_sc_nots_sa_ea
	| declspecs_sc_ts_nosa_noea
	| declspecs_sc_ts_nosa_ea
	| declspecs_sc_ts_sa_noea
	| declspecs_sc_ts_sa_ea
maybe_type_quals_attrs
	: | declspecs_nosc_nots
typespec_nonattr
	: typespec_reserved_nonattr
	| typespec_nonreserved_nonattr
typespec_attr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -