删除左递归 [英] Removing left recursion

查看:113
本文介绍了删除左递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下语法已退出递交

E= E+T|T
T= T*F|F
F= a|b|c

有没有一般的程序?

推荐答案

是的,有一个一般的程序, 维基百科

Yes, there is a general procedure, see e.g. wikipedia.

E = TE'
E'= (e) | +TE'
T = FT'
T'= (e) | *FT'
F = a | b | c

应该提到这会改变 + * 从左到右。也就是说, a + b + c 之前分析为(a + b)+ c 解析为 a +(b + c)

It should be mentioned that this alters the associativity of + and * from left to right. That is, where before a + b + c was parsed as (a + b) + c, it is now parsed as a + (b + c).

这不是加法和乘法的问题,

This is not a problem for addition and multiplication, but it would be a problem for subtraction and division, for example.

维基百科文章有更详细的左递归移除程序及其复杂性。

Wikipedia article has more detail on the left-recursion removal procedure and its intricacies.

这篇关于删除左递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆