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

发布于 2024-12-10 00:09:26 字数 1118 浏览 4 评论 0原文

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

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())

What are the meanings of these keywords:

shift, reduce, error, accept, conflict?

Please give a full description of each.

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;

In the above code, what are the meanings of

lookahead()

and

reduce(production(), productionSize())

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性不性感 2024-12-17 00:09:26

在评论中回答。

@KLibby 写道:

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

(Answered in the comments.)

@KLibby wrote:

Have you tried reading the Yacc documentation ? This contains a clear explanation of the above, and a lot of other information to get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文