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

📄 gcodeanylys.c

📁 G代码分析 这个文件主要进行语法分析
💻 C
📖 第 1 页 / 共 2 页
字号:
   Function   :Handle_Coordinate
   
   Description: 把地址字符串转换成浮点数,其中输入带有地址符的字符串,
                判断浮点数有超出数控系统指定的最大范围。
   
   Input      : char *str字符串从Lex得到的
   
   Output     : double   返回转换的双精度浮点数
  
  
  ***************************************************************************/

double Handle_Coordinate(char *str)
{
    double coordinate;
                                                                                                               
    str++;
    coordinate = atof(str);
    if(coordinate > 99999.0)
    {
        printf("Line[%d]n%d Data override error.\n", currlinenum, curr[currlinenum - 1]);
    }
    
    return (coordinate);
}


/***************************************************************************
  
   Function   :Yacc_Run_Analyser
   
   Description: 判断程序段是否有指定两次运动指令,有则报错
                没有则把G指令值存储到语法分析临时变量中
   
   Input      : int value 运动G指令的数据值
   
   Output     : 0(没有实际意义)
     
  ***************************************************************************/

int Yacc_Run_Analyser(int value)
{
    switch(value)
    {
        case 0:
		case 1:
		case 2:
		case 3:
		case 33:
        {	
            if(Yacc_Function[0] & 0x02)
            {
                printf("Line[%d] n%d Run G multx.\n", currlinenum, curr[currlinenum-1]);
            }
            else
            {
                Yacc_Function[0] |= 0x02;
                Yacc_Intcode[1] = value;
            }
            break;
        }
		default:
			break;                                                                                 
    }
    return 0;
}

/***************************************************************************
  
   Function   :Yacc_Run_Handle
   
   Description: 运动G指令语句合法性检查入口
   
   Input      : null
   
   Output     : 0
  
  
  ***************************************************************************/

void Yacc_Run_Handle(void)
{
	switch(Yacc_Intcode[1])
	{
	case 0:
		Yacc_Quick_Speed_Handle();
		break;
	case 1:
		Yacc_Line_Handle();
		break;
	case 2:
	case 3:
		Yacc_Circle_Handle(yylval);
		break;
	default:
		break;
	}
}	


/***************************************************************************
  
   Function   :Yacc_Quick_Speed_Handle
   
   Description: G0语句语法分析,并把数据存储到NC程序段的数据结构中,
                其中G0语句合法性为:
                (G00 G0){(<X><U>)(<Y><V>)(<Z><W>)}
   
   Input      : null
   
   Output     : 0(暂时没有定义) 
  
  
  ***************************************************************************/
int Yacc_Quick_Speed_Handle(void)
{
    if(Yacc_Format[2]&0x80)
    {
        printf("Line[%d]n%d  Fcode error.\n",currlinenum, curr[currlinenum -1]);
    }
    else
	{
		YaccLineMultiDefine();
		Yacc_Floatcode[15] = FMAX;
		Yacc_Save_Coordinate();
	}
	return 0;
}

/***************************************************************************
  
   Function   :YaccLineMultiDefine
   
   Description: G0/G1 语句合法性中坐标代码分析
                {(<X><U>)(<Y><V>)(<Z><W>)}
   
   Input      : null
   
   Output     : 0
  
  
  ***************************************************************************/
  
void YaccLineMultiDefine(void)
{
	if((Yacc_Format[0]&0x01)&&(Yacc_Format[0]&0x08))
	{
	     printf("Line[%d]n%d  X U multi define error.\n",currlinenum, curr[currlinenum -1]);		            
	}
	else if((Yacc_Format[0]&0x02)&&(Yacc_Format[0]&0x10))
    {
         printf("Line[%d]n%d  Y V multi define error.\n",currlinenum, curr[currlinenum -1]);                                                                                                          
    }
    else if((Yacc_Format[0]&0x04)&&(Yacc_Format[0]&0x20))
    {
         printf("Line[%d]n%d  Z W multi define error.\n",currlinenum, curr[currlinenum -1]);                                                                                                         
    }
}


/***************************************************************************
  
   Function   :Yacc_Quick_Speed_Handle
   
   Description: G1语句语法分析,并把数据存储到NC程序段的数据结构中,
                其中G0语句合法性为:
                (G01 G1){(<X><U>)(<Y><V>)(<Z><W>)}[<F>]
                G1如果没有指定速度则系统按照默认速度执行
                
   Input      : null
   
   Output     : 0(暂时没有定义) 
  
  
  ***************************************************************************/

int Yacc_Line_Handle(void)
{
	YaccLineMultiDefine();
	if(!(Yacc_Format[2]&0x80))
	{
		Yacc_Floatcode[15] = FMAX;
	}
	Yacc_Save_Coordinate();                                                                                                              
}

/***************************************************************************
  
   Function   :YaccSpeedF
   
   Description: 数控加工代码中有指定F指令中速度的处理
                首先判断F指令是否重复指定,如果没有则存储指令
   
   Input      : char *str
   
   Output     : 0
  
  
  ***************************************************************************/

int YaccSpeedF(char *str)
{
	if(Yacc_Format[2]&0x80)
	{
	          printf("Line[%d]n%d  F speed multi define.\n",currlinenum, curr[currlinenum -1]);
	}
	else
	{
		Yacc_Format[2] |= 0x80;
		Yacc_Floatcode[15] = Handle_Coordinate(str);
	}
	return 1;
}


 
 
 /***************************************************************************
  
   Function   :Yacc_Circle_Handle
   
   Description: 圆弧插补G02/G03语句合法分析,合法语句格式为:
   
				(G02 G2)(G03 G3))[<X><Y>]({<I><J>}<R>)[<F>]
				(G02 G2)(G03 G3))[<Z><X>]({<K><I>}<R>)[<F>]
				(G02 G2)(G03 G3))[<Y><Z>]({<J><K>}<R>)[<F>]
				
                G17((G02 G2)(G03 G3))[<X><Y>]({<I><J>}<R>)[<F>]
                G18((G02 G2)(G03 G3))[<Z><X>]({<K><I>}<R>)[<F>]
                G19((G02 G2)(G03 G3))[<Y><Z>]({<J><K>}<R>)[<F>]
                其中合法性语句文字说明参照编译需求分析详细文档
   
   Input      : 坐标平面标志
   
   Output     : 返回整型数 1:数据存储在NC结构里,0:报警,数据没有存储
  
  
  ***************************************************************************/

int Yacc_Circle_Handle(int value)
{
    
    // G02、G03数据保存标志,程序段不合法则不保存
    int saveflag = 0; .
    
    switch(Yacc_Coordinate_Plane)
    {
        case 0:// not define plane.
        {
		    if((Yacc_Format[0]&0x01)&&(Yacc_Format[0]&0x02)&&(Yacc_Format[0]&0x04))
		    {
	            printf("Line[%d]n%d xyz Error.\n",currlinenum, curr[currlinenum - 1]);
			    saveflag = 1;
		    }
		    else if((Yacc_Format[1]&0x01)&&(Yacc_Format[1]&0x02)&&(Yacc_Format[1]&0x04))
		    { 
                printf("Line[%d]n%d IJK Error.\n",currlinenum, curr[currlinenum - 1]);
                saveflag = 1;
            }
		    break;
		}
        case 1:// g17
        {
            if((Yacc_Format[0]&0x04)||(Yacc_Format[1]&0x04))
            {
                printf("Line[%d]n%d 'xy'plane'z' Error.\n",currlinenum, curr[currlinenum - 1]);
                saveflag = 1;
            }
		    break;
		}
	    case 2:// g18
		{
            if((Yacc_Format[0]&0x02)||(Yacc_Format[1]&0x02))
            {
                printf("Line[%d]n%d 'zx'plane'y' Error.\n",currlinenum, curr[currlinenum - 1]);
                saveflag = 1;
            }                                                                                           
            break;
		}
        case 3:// g19
		{
            if((Yacc_Format[0]&0x01)||(Yacc_Format[1]&0x01))
            {
                printf("Line[%d]n%d 'yz'plane'x' Error.\n",currlinenum, curr[currlinenum - 1]);
                saveflag = 1;
            }
		    break;
		}
    }
    
	if(!saveflag)
	{
		Yacc_Save_Coordinate();
		return 1;
	}
	else
	{
		return 0;
	}
}


/***************************************************************************
  
   Function   :YaccModeG
   
   Description: 保存模态G指令,存储其标志及参数
   
   Input      : null
   
   Output     : 0
  
  
  ***************************************************************************/

void YaccModeG(void)
{
	if(Yacc_Prec_Function[0]&0x02)
	{
		Yacc_Function[0] |= 0x02;
		Yacc_Intcode[1] = Yacc_Prec_Intcode[1];
	}
}



/***************************************************************************
  
   Function   :Yacc_Reset_Array
   
   Description: 清空分析程序段中标识及数组变量,用来下条程序段的存储变量做好
                准备。
   
   Input      : null
   
   Output     : 0
  
  
  ***************************************************************************/
  
void Yacc_Reset_Array(void)
{
    int i;
                                                                                                               
    for(i=0; i<3; i++)
    {
        Yacc_Format[i] = 0;
        Yacc_Function[i] = 0;
    }
    
    for(i=0; i<20; i++)
    {
        Yacc_Floatcode[i] = 0;
        Yacc_Prec_Intcode[i] = Yacc_Intcode[i];
        Yacc_Intcode[i]= 0;
    }
    Yacc_Coordinate_Plane = 0;
}
                                                                             
                                                                             

⌨️ 快捷键说明

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