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

📄 c.grm

📁 OXCC is a multipass, interpreting C compiler with several language extensions. It generates an Archi
💻 GRM
📖 第 1 页 / 共 2 页
字号:
	-> String		;

GccIOspec
	-> CO [GccOutputList] CO [GccInputList] [ClobbersList]	$$;

GccOutputList
	-> GccOutput \','...	$$;

GccInputList
	-> GccInput \','...		$$;

ClobbersList
	-> CO Clobbers \','...	$$;

GccOutput
	-> String GccfixExp ;

GccInput
	-> String GccfixExp ;
	
Clobbers
	-> String			;

GccfixExp
	-> PostfixExp ;

MscAsmStmt
	-> _asm [AsmElem]...			;
	-> _asm '{' [AsmAll]... '}'		;
	-> _asm '(' AsmEmit... ')'		;
	
AsmAll
	-> AsmElem		$$;
	-> AsmUnixOp	$$;

AsmElem
	-> AsmOp		$$;
	-> AsmId		$$;
	-> Constant		$$;
	-> Type			$$;
	-> AsmEmit		$$;

AsmOp
	->	'+'		;
	->	'-'		;
	->	'*'		;
	->	'/'		;
	->	'.'		;
	->	'['		;
	->	']'		;
	->	','		;
	->	':'		;

AsmUnixOp
	->	'%'		;
	->	'$'		;
	->	'('		;
	->	')'		;

AsmId
	-> <identifier>		;
	-> {meta-name}		;

AsmEmit
	->	_emit Constant					;
	-> _emit '(' Constant \','... ')'	;

CO
	-> ':'	;

AnfBlock
	-> __anf__ '{' [AnfStmt]... '}'	;

AnfStmt
	->	AnfOp [AnfTarget] ';'	;
	->	Label ':' [AnfStmt]		;

AnfTarget
	->	AssignExp \','...		$$;

AnfOp
	->	DeclID		;

/* Expressions */

Exp
	-> AssignExp		;
	-> Exp ',' CommaExp	;

CommaExp
	-> AssignExp	;	/* needed for regen source */

ConstExp
	->BinopC		;

AssignExp
	-> BinopC					$$;
	-> AssignLHS '+='  AssignExp ;		/* 1 */
	-> AssignLHS '-='  AssignExp ;		/* 2 */
	-> AssignLHS '*='  AssignExp ;		/* 3 */
	-> AssignLHS '/='  AssignExp ;		/* 4 */
	-> AssignLHS '<<=' AssignExp ;		/* 5 */
	-> AssignLHS '>>=' AssignExp ;		/* 6 */
	-> AssignLHS '%='  AssignExp ;		/* 7 */
	-> AssignLHS '|='  AssignExp ;		/* 8 */
	-> AssignLHS '^='  AssignExp ;		/* 9 */
	-> AssignLHS '&='  AssignExp ;		/* 10 */
	-> AssignLHS '='   AssignExp ;		/* 11 */

AssignLHS
	-> CastExp ;

BinopC
	-> BaseOrCast			$$;
	-> BinopC '+'  BinopC	;	/* 1 */
	-> BinopC '-'  BinopC	;	/* 2 */
	-> BinopC '*'  BinopC	;	/* 3 */
	-> BinopC '/'  BinopC	;	/* 4 */
	-> BinopC '<<' BinopC	;	/* 5 */
	-> BinopC '>>' BinopC	;	/* 6 */
	-> BinopC '%'  BinopC	;	/* 7 */
	-> BinopC '|'  BinopC	;	/* 8 */
	-> BinopC '^'  BinopC	;	/* 9 */
	-> BinopC '&'  BinopC	;	/* 10 */
	-> BinopC '==' BinopC	;	/* 11 */
	-> BinopC '!=' BinopC	;	/* 12 */
	-> BinopC '<'  BinopC	;	/* 13 */
	-> BinopC '>'  BinopC	;	/* 14 */
	-> BinopC '<=' BinopC	;	/* 15 */
	-> BinopC '>=' BinopC	;	/* 16 */
	-> BinopC '||' BinopC	;	/* 17 */
	-> BinopC '&&' BinopC	;	/* 18 */
	-> BinopC '?'  BinopC ':' BinopC ;	/* 19 */
	-> BinopC '?'  ':' BinopC ;	/* 20 */

BaseOrCast
	->	BasedPtr	$$;
	->	CastExp		$$;

BasedPtr
	-> PostfixExp ':>' PostfixExp	;

CastExp
	-> UnaryExp				;
	-> '(' Cast ')' CastExp	;

Cast
	-> SpecQual... [NoNameDeclarator]	;

UnaryExp
	-> PostfixExp		$$;
	-> PreIncrement		$$;
	-> UnOpC  CastExp	$$;
	-> SizeOf			$$;
	-> AlignOf			$$;
	-> SegName			$$;

UnOpC
	-> '&'	;
	-> '*'	;
	-> '-'	;
	-> '~'	;
	-> '!'	;

PreIncrement
	-> '++' UnaryExp	;
	-> '--' UnaryExp	;

PostIncrement
	-> PostfixExp '++' ;
	-> PostfixExp '--' ;

SizeOf
	-> sizeof UnaryExp		;
	-> sizeof '(' Cast ')'	;

AlignOf
	-> __alignof__ UnaryExp		;
	-> __alignof__ '(' Cast ')'	;

SegName
	-> _segname '(' String ')'	;
	-> __segname '(' String ')'	;

PostfixExp
	-> PrimaryExp			$$;
	-> ArrayElement			$$;
	-> StructureElement		$$;
	-> PointerElement		$$;
	-> FunctionCall			$$;
	-> PostIncrement		$$;
   
ArrayElement
	-> ElemNameExp '[' ElemExp ']' ;

ElemNameExp
	-> Identifier		;
	-> ArrayElement 	;
	-> '(' Exp ')'		;
	-> PointerElement 	;
	-> StructureElement ;
	-> FunctionCall 	;
	-> String			;

ElemExp
	->	Exp ;

StructureElement
	-> PostfixExp '.' ElementName ;

PointerElement
	-> PostfixExp '->' ElementName ;	 

ElementName
	-> <identifier>	;
	-> {meta-name}	;

FunctionCall
	-> PostfixExp ArgList ;
	
ArgList
	-> '(' [Args] ')' ;

Args
	-> Arg \','... $$;

Arg
	-> AssignExp		;
	-> ArgId AssignExp	;

ArgId
	-> ArgLabel ':'		$$;

ArgLabel
	-> <identifier>		;
	-> {meta-name}		;	

PrimaryExp
	-> Constant					$$;
	-> Identifier				$$;
	-> '(' Exp ')'				$$;
	-> CompoundExp				$$;
	-> String...				$$;

CompoundExp
	-> '(' BlockC CompoundExit	;

CompoundExit
	->	')' ;

Identifier
	-> <identifier>  ;

Constant
	-> <int> ;			/*0*/
	-> <long> ;			/*1*/
	-> <ll>	;			/*2*/
	-> <uint> ;			/*3*/
	-> <ulong> ;		/*4*/
	-> <ull> ;			/*5*/

	-> <hex> ;			/*6*/
	-> <lhex> ;			/*7*/
	-> <llhex> ;		/*8*/
	-> <uhex> ;			/*9*/
	-> <ulhex> ;		/*10*/
	-> <ullhex> ;		/*11*/

	-> <octal> ;		/*12*/
	-> <loctal> ;		/*13*/
	-> <lloctal> ;		/*14*/
	-> <uoctal> ;		/*15*/
	-> <uloctal> ;		/*16*/
	-> <ulloctal> ;		/*17*/

	-> <float> ;		/*18*/
	-> <double> ;		/*19*/
	-> <ldouble> ;		/*20*/

	-> <literal> ;		/*21*/
	-> <wliteral> ;		/*22*/

String
	-> <string> ;
	-> <wstring> ;

LB	-> '{' $$;
RB	-> '}' $$;

Directive
	-> <notline> ;
	-> <linenum> ; /* this will never happen, linenum is expunged by doline */

/* Lexical grammar for c and c++ */

IGNORE 			:= spaces ;
				:= comment ;
				:= comment2 ;

"eof"			:= (0 | 26 | 255) ;


"linenum"		:= line restofline => doline ;
line			:= '#line' ;

"notline"		:= notline restofline ;
notline			:= '#' ;

"identifier"	:= ident => dyntoken ;
ident			:= letter ;
				:= ident letter ;
				:= ident digit ;

"int"			:= digits ;

"long"			:= digits 'l' ;
				:= digits 'L' ;

"uint"			:= digits 'U' ;
				:= digits 'u' ;

"ulong"			:= digits 'LU' ;
				:= digits 'UL' ;
				:= digits 'ul' ;
				:= digits 'lu' ;
				:= digits 'lU' ;
				:= digits 'Lu' ;
				:= digits 'uL' ;
				:= digits 'Ul' ;

"ll"			:= digits 'LL' ;
				:= digits 'll' ;

"ull"			:= digits 'ull' ;
				:= digits 'llu' ;
				:= digits 'ULL' ;
				:= digits 'LLU' ;
				
digits			:= digit ;
				:= digits digit ;

"hex"			:= hexx ;

"lhex"			:= hexx 'l' ;
				:= hexx 'L' ;

"uhex"			:= hexx 'U' ;
				:= hexx 'u' ;

"ulhex"			:= hexx 'LU' ;
				:= hexx 'UL' ;
				:= hexx 'ul' ;
				:= hexx 'lu' ;
				:= hexx 'lU' ;
				:= hexx 'Lu' ;
				:= hexx 'uL' ;
				:= hexx 'Ul' ;

"llhex"			:= hexx 'LL' ;
				:= hexx 'll' ;

"ullhex"		:= hexx 'ull' ;
				:= hexx 'llu' ;
				:= hexx 'ULL' ;
				:= hexx 'LLU' ;


hexx			:= '0x' hexdigit ;
				:= '0X' hexdigit ;
				:= hexx hexdigit ;

hexdigit		:= '0'/'9' ;
				:= a/f ;
				:= A/F ;

"octal"			:= oct ;

"loctal"		:= oct 'l' ;
				:= oct 'L' ;

"uoctal"		:= oct 'U' ;
				:= oct 'u' ;

"uloctal"		:= oct 'LU' ;
				:= oct 'UL' ;
				:= oct 'ul' ;
				:= oct 'lu' ;
				:= oct 'lU' ;
				:= oct 'Lu' ;
				:= oct 'uL' ;
				:= oct 'Ul' ;

"lloctal"		:= oct 'LL' ;
				:= oct 'll' ;

"ulloctal"		:= oct 'ull' ;
				:= oct 'llu' ;
				:= oct 'ULL' ;
				:= oct 'LLU' ;
				
oct				:= '0' octdigit ;
				:= oct octdigit ;
octdigit		:= '0'/'7' ;

"double"		:= flt ;
"float"			:= flt 'f' ;
				:= flt 'F' ;
"ldouble"		:= flt 'l' ;
				:= flt 'L' ;

flt				:= rational ;
				:= digits exp ;
				:= rational exp ;

rational		:= digits '.' ;
				:= '.' digits ;
				:= digits '.' digits ;
exp				:= 'e' digits  ;
				:= 'E' digits ;
				:= 'e-' digits ;
				:= 'E-' digits ;
				:= 'e+' digits ;
				:= 'E+' digits ;

"literal"		:= lit ;
"wliteral"		:= 'L' lit ;
lit				:= qt lchar... qt ;
lchar			:= ch ;
				:= qt qt ;
				:= '"' ;
				:= '*' ;
				:= '/' ;
				:= escapes ; 

"string"		:= str ;
"wstring"		:= 'L' str ;

str				:= '"' [schar...] '"' ;
schar			:= ch ;
				:= qt ;
				:= '*' ;
				:= '/' ;
				:= escapes ;

escapes			:= bs qt ;
				:= bs ch ;
				:= bs '"' ;
				:= bs '*' ;
				:= bs '/' ;
				:= bs bs ;
				:= bs lf ;

spaces    		:= space... ;
space     		:= ( 9 | 10 | 12 | 32 ) ;

comment   		:= '/*' end '/' ;
end       		:= endinstar ;
          		:= end noslash endinstar	;
endinstar 		:= stars ;
          		:= notstar stars ;
stars     		:= '*'... ;
notstar   		:= nostar	;
          		:= notstar nostar	;
noslash   		:= (ch | notsl) ;
notsl			:= (10 | 12 | 39 | '"' | '*' | 92) ;
nostar    		:= (ch | notst)	;
notst			:= (10 | 12 | 39 | '"' | '/' | 92) ;


comment2		:= '//' restofline ;

restofline		:= [(ch | noteol)]... ;
noteol			:= (39 | '"' | '/' | '*' | 92) ;

ch				:= 1/254 ^(10 12 26 39 '"' '/' '*' 92) ;

letter			:= a/z ;
				:= A/Z ;
				:= '_' ;

digit			:= '0'/'9' ;

bs			:= 92 ;
qt			:= 39 ;
lf			:= 10 ;
/*--- End. ---*/

⌨️ 快捷键说明

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