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

📄 nescobjecttreebuilder.g

📁 plugin for eclipse
💻 G
📖 第 1 页 / 共 5 页
字号:
														}															
		: #( d:NDeclarator								{	declObj = new Declarator();
															declObj.setDefNode(d);
														}
			 ( pgObj = pointerGroup						{	declObj.setPointerGroup(pgObj); }
			 )?
			 
			 ( 
				( id1:ID										
				  ( DOT
				    id2:ID										
				   )?												
														{	declObj.setNameNodes(ctx, id1, id2); }
				)												
				| 
				( lp:LPAREN 								
				  childDeclObj = nestedd:declarator		{	declObj.setNestedDecl(childDeclObj); }
				  rp:RPAREN
				)
			 )

			 (
			 	#( ip:NInterfaceParameterList			
				   ptlObj = parameterTypeList			{	declObj.setInterfaceParameterTypeList(ptlObj); }
				   rbr:RBRACKET		
				 )
			 )?

		     (
				#( n:NParameterTypeList    				
				   (
						ptlObj = parameterTypeList		{	declObj.addParameterTypeList(ptlObj); }
						| (idList)?						{	// add an empty one so we can figure out it's a function decl
															declObj.addParameterTypeList(new ParameterTypeList());
														}
				   )
				   r:RPAREN                    
				 )
				 | lb:LBRACKET							{	acObj = new ArrayConstructor();
				 											acObj.setDefNode(lb);
				 											declObj.addArrayConstructor(acObj);
				 										}
				   ( expr )?
				   rb:RBRACKET 

			 )*													
		   )
		;

interfaceMemberFunctionDeclarator returns [Declarator declObj]
														{	declObj = null;
															PointerGroup pgObj = null; 
															Declarator childDeclObj = null;
															ParameterTypeList ptlObj = null;
															ArrayConstructor acObj = null;
														}															
		: #( d:NDeclarator								{	declObj = new Declarator();
															declObj.setDefNode(d);
														}
			( pgObj = pointerGroup						{	declObj.setPointerGroup(pgObj); }
			)?
			 
			id1:ID										{	declObj.setNameNode(id1); }	
			 

			#( n:NParameterTypeList
				
				(
				ptlObj = parameterTypeList				{	declObj.addParameterTypeList(ptlObj); }
				| (idList)?								{	// add an empty one so we can figure out it's a function decl
															declObj.addParameterTypeList(new ParameterTypeList());
														}
				)
				r:RPAREN                    
			)
		  )
		;


parameterTypeList returns [ParameterTypeList ptlObj] 
														{	ptlObj = new ParameterTypeList();
															ParameterDeclaration pdObj = null;
														}
		: ( pdObj = parameterDeclaration				{	ptlObj.addParameterDeclaration(pdObj); }
			( COMMA | SEMI )?
		  )+
		  
		  ( VARARGS										{	ptlObj.addVarArgs(); }
		  )?
        ;

parameterDeclaration returns [ParameterDeclaration pdObj]
															{	StorageClassSpecifier scsObj = null;
																TypeQualifier tqObj = null;
																TypeSpecifier tsObj = null;
																Declarator declObj = null;
																AbstractDeclarator adeclObj = null;																
																TypeBuilder builderObj = new TypeBuilder();
																pdObj = new ParameterDeclaration();
															}

 :#( dn:NParameterDeclaration								{   pdObj.setDefNode(dn); }

						( scsObj = storageClassSpecifier	{	pdObj.addStorageClassSpecifier(scsObj); }
		                 | tqObj = tq:typeQualifier			{   builderObj.addTypeQualifier(tqObj); }
		                 | tsObj = ts:typeSpecifier			{	//try {
																	builderObj.addTypeSpecifier(tsObj);
																//} catch (TypeResolutionException ex) {
																//	ctx.addError(new Error(ex, ex.getMessage(), new CodeLocation(tsObj.getDefNode())));
																//}
															}
		                )+

                (
                  declObj = declarator 						{
                  												try {
	                  												builderObj.addDeclarator(declObj);
																} catch (TypeResolutionException ex) {
																	ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(declObj.getDefNode()), ex));
																}
	                  												
                												if(builderObj.getDeclarator() instanceof Declarator) {
                													Declarator namedDeclObj = (Declarator)builderObj.getDeclarator();
                													pdObj.setNameNode(namedDeclObj.getNameNode());
                												}
                  	
                  											}
                | adeclObj = nonemptyAbstractDeclarator
                											{	try {
                													builderObj.addDeclarator(adeclObj);
																} catch (TypeResolutionException ex) {
																	ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(adeclObj.getDefNode()), ex));
																}              													
                											}
                )?											{	pdObj.setType(builderObj.getType()); }
    )														
        ;

functionDef returns [FunctionDefinition fcnDefObj = null]													
															{	Declarator declObj = null;
																StorageClassSpecifier scsObj = null;
																TypeQualifier tqObj = null;	
																TypeSpecifier tsObj = null;
																CompoundStatement csObj = null;
																TypeBuilder builderObj = null;
																Scope scope = null;
																Attribute attrObj = null;
															}
		 :#( fdn:NFunctionDef								{	fcnDefObj = new FunctionDefinition(); 
		 														fcnDefObj.setDefNode(fdn);		 														
		 														builderObj = new TypeBuilder();
		 													}
		 
					( scsObj = functionStorageClassSpecifier{	fcnDefObj.addStorageClassSpecifier(scsObj); }
	                 | tqObj = tq:typeQualifier				{	builderObj.addTypeQualifier(tqObj); }
	                 | tsObj = ts:typeSpecifier				{	// try {
																	builderObj.addTypeSpecifier(tsObj);
																// } catch (TypeResolutionException ex) {
																// 	ctx.addError(new Error(ex, ex.getMessage(), new CodeLocation(tsObj.getDefNode())));
																// }
															}
	                )+

                declObj = dr:declarator                		{	try {
                													builderObj.addDeclarator(declObj);
                												} catch (TypeResolutionException ex) {
																	ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(declObj.getDefNode()), ex));
																}
                												
                												if(builderObj.getDeclarator() instanceof Declarator) {
                													Declarator namedDeclObj = (Declarator)builderObj.getDeclarator();
                													fcnDefObj.setNameNode(namedDeclObj.getNameNode());
                													fcnDefObj.setInterfacePort(namedDeclObj.getInterfacePort());
                													fcnDefObj.setFunctionPort(namedDeclObj.getFunctionPort());
                												}
                											}
                (declaration 								{	// FIXME: old style not supported
                											}	
                | VARARGS)*					
                						
                ( attrObj = attributeDecl					{	fcnDefObj.addAttribute(attrObj); }
                )*                                            
                											{   fcnDefObj.setType(builderObj.getType());
																fcnDefObj.addToScope(ctx);
                												
                												scope = new Scope("function " + declObj.getName(), ctx.getCurrentScope());
                												ctx.pushScope(scope);
                												fcnDefObj.addParametersToScope(ctx);
                											}
                csObj = compoundStatement[declObj.getName(), scope]
                											{	fcnDefObj.setBody(csObj);
                												ctx.popScope();
                											}
            )
        ;

functionDeclSpecifiers :( functionStorageClassSpecifier
                | typeQualifier
                | typeSpecifier
                )+
        ;

declarationList returns [List declnListObj = new ArrayList()]
														{	List listObj = null; }
		 :(   //ANTLR doesn't know that declarationList properly eats all the declarations
                    //so it warns about the ambiguity
                    options {
                        warnWhenFollowAmbig = false;
                    } :
                localLabelDecl							// FIXME: process label declaration
                | listObj = declaration				{	declnListObj.addAll(listObj); }
                )+
        ;

localLabelDecl :#("__label__" (ID)+ )
        ;

compoundStatement[String declName, Scope scope] returns [CompoundStatement csObj = null]
														{	String[] declNames = null;
															List declnListObj = null;
															List statementListObj = null;
															boolean isScopeGiven = (scope != null);
														}
:
		#( cs:NCompoundStatement						{	csObj = new CompoundStatement();
															csObj.setDefNode(cs);
															if(!isScopeGiven) {
																scope = new Scope(ctx.getAScopeName(), ctx.getCurrentScope());
																ctx.pushScope(scope);
															}
															csObj.setScope(scope);
														}
                ( declnListObj = declarationList		{	csObj.addDeclarations(declnListObj); }
                | functionDef							// TODO: I guess it's not allowed
                )*
                ( statementListObj = statementList		{	csObj.addStatements(statementListObj); }
                )?
                RCURLY									
                )										{	if(!isScopeGiven) {
                												ctx.popScope();
                											}
                										}
        ;

statementList returns [List statementListObj = new ArrayList()]
														{	Statement stObj = null; }
		:( 
			stObj = statement							{	statementListObj.add(stObj); }
		)+
        ;

statement returns [Statement stObj = null]
		:
		( 
			("atomic") => a:"atomic" stObj = statementBody
														{	stObj.setAtomicNode(a); }
			| stObj = statementBody							
		)	
        ;

statementBody returns [Statement stObj = null]
														{
															Expression expr1Obj = null;
															Expression expr2Obj = null;
															Expression expr3Obj = null;
															Statement st1Obj = null;
															Statement st2Obj = null;																						
														}
		:
		s:SEMI 											// Empty statements
														{	stObj = new Statement();
															stObj.setDefNode(s);
														}

        |       stObj = compoundStatement[null,null]	// Group of statements

        |       #(esn:NStatementExpr expr1Obj=expr		// Expressions
        												{	ExpressionStatement estObj = new ExpressionStatement(); 
        													estObj.setDefNode(esn);
        													estObj.setExpression(expr1Obj);
        													stObj = estObj;
        												}
        		)

// Iteration statements:

        |       #( wsn:"while" expr1Obj = expr st1Obj = statement
        												{
        													WhileStatement wstObj = new WhileStatement();
        													wstObj.setDefNode(wsn);
        													wstObj.setCondition(expr1Obj);
        													wstObj.setLoopStatement(st1Obj);
        													stObj = wstObj;
        												}
        		)
        |       #( dsn:"do" st1Obj = statement expr1Obj = expr
        												{
        													DoStatement dstObj = new DoStatement();
        													dstObj.setDefNode(dsn);
        													dstObj.setCondition(expr1Obj);
        													dstObj.setLoopStatement(st1Obj);
        													stObj = dstObj;
        												}
        		)
        |       #( fsn:"for"		
                expr1Obj = expr							
                expr2Obj = expr							
                expr3Obj = expr							
                st1Obj = statement						
        												{	ForStatement fstObj = new ForStatement();
        													fstObj.setDefNode(fsn);
															fstObj.setInitExpression(expr1Obj);
															fstObj.setCondition(expr2Obj);
															fstObj.setUpdateExpression(expr3Obj);
															fstObj.setLoopStatement(st1Obj);
                											stObj = fstObj;
                										}
                )


// Jump statements:

        |       #( gsn:"goto" expr1Obj= expr			{	GotoStatement gstObj = new GotoStatement();
        													gstObj.setDefNode(gsn);
        													gstObj.setLabelExpression(expr1Obj);
        													stObj = gstObj;
        												}
        		)
        |       csn:"continue" 							{	ContinueStatement cstObj = new ContinueStatement();
        													cstObj.setDefNode(csn);        													
        													stObj = cstObj;
        												}
        |       bsn:"break" 							{	BreakStatement bstObj = new BreakStatement();
        													bstObj.setDefNode(bsn);        													
        													stObj = bstObj;

⌨️ 快捷键说明

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