我想定义 char(即 'a AND 'a'),但在检查错误时遇到问题。这里我如何编写规则并检查:
char " ' " {letter}
代码
{char} {
int x =input() ;
//printf("%d",'a');
if(x == 10)
{
return(tCharunterm);
}
else if(x == '\'')
{
return(tChar);
}
else
{
yyerror("char overflow");
}
最后检查一下:
'a
token = tCharunterm, value = "(null)"
'a'
token = tChar, value = "(null)"
'as
char overflow
'asddd
char overflow
token = tIdentifier, value = "ddd"
^Z