如何在c ++中使用lex或yacc中的shift,reduce,error,accept和conflict关键字?

时间:2011-10-17 10:21:43

标签: c++ yacc lex

这些关键字的含义是什么:

shiftreduceerroracceptconflict

请详细说明每一项。

switch ( oAction)
{
   case SSYaccAction::shift:
      oElement = shift( lookahead());
      if ( !oElement) return SSTrue;
      oElement->oLexeme = lookahead();
      oElement->oulState = state();
      push();
      if ( getLexeme()) return SSTrue;
      oulError++;
      break;
   case SSYaccAction::reduce:
     oElement = reduce( production(), productionSize());
      if ( !oElement) return SSTrue;
      pop( productionSize());
      if ( goTo( leftside())) return SSTrue;
      break;
   case SSYaccAction::error:
      oError = SSTrue;
      if ( error( state(), lookahead()))
         return SSTrue;
      oulError = 0;
      break;
   case SSYaccAction::accept:
      return accept();
   default:
      throwException( SSExceptionYaccParse, SSYaccMsgParse);
      return SSTrue;

在上面的代码中,

的含义是什么
lookahead()

reduce(production(), productionSize())

1 个答案:

答案 0 :(得分:0)

Answered in the comments.

@KLibby写道:

  

您是否尝试过阅读Yacc documentation?这包含对上述内容的清晰解释,以及许多其他信息可帮助您入门。