编译-LL1语法 [英] Compilation - LL1 Grammar

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

问题描述

我正在研究编译器的魔力,但我不明白结果.

I am studying the magic of compilers and I don't understand a result.

这是语法:

S -> A #
A -> B G D E
B -> + | - | EPSILON
C -> c C | EPSILON
G -> c C
D -> . C | EPSILON
E -> e B G | EPSILON

当我尝试查找第一"和跟随"集时,得到的结果与使用在线预测变量得到的结果不同.

When I try to find the "first" and "follow" sets, I get different results than the one I get when I do it with an online predictor.

以下是给出的结果:

Non-terminal Symbol / Follow Set
     S                  $
     A                  #
     B                  c
     C               e, ., #
     G                 ., #
     D                 e, #
     E                   #

为什么不跟随G {e,.,#}?因为我了解的是,根据A规则,D跟随G,所以我们加.,但也可能是EPSILON,因此我们移到E并可能是ae,但也可能是EPSILON,因此,根据S规则,我们移至#.

Why isn't the follow set of G {e, ., #} ? Because what I understand is that according to the A rule, D follow the G, so we add ., but it could also have been EPSILON, so we move to the E and it can be a e, but it could also have been EPSILON, so we move to the #, in respect with the S rule.

我在这里想念什么?

我在 http://hackingoff.com/compilers/predict-第一跟进集

推荐答案

您对F的FOLLOW集的计算是正确的.

Your computation of the FOLLOW set of G is correct.

hackingoff工具有故障.这是一个较短的文法,它表现出相同的错误:

The hackingoff tool is buggy. Here is a shorter grammar which exhibits the same error:

S -> a B C a
B -> b
C -> EPSILON

很明显, a 位于为 B 设置的FOLLOW中,但是该工具报告该设置为空.

It's obvious that a is in the FOLLOW set for B but the tool reports that set as empty.

这篇关于编译-LL1语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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