语法歧义

问题描述 投票:0回答:1

我正在学习语法歧义,我需要一点帮助才能更好地理解。这是语法:

<S> ::= if <S> then <S>
<S> ::= if <S> then <S> else <S>
<S> ::= a

使用解析树或最左派生,如何显示此语法不明确?

racket ambiguous ambiguous-grammar
1个回答
0
投票

请考虑以下内容:

if a then if a then a else a

您可以考虑通过以下两种方式将其分组:

(if a then (if a then a else a))

(if a then (if a then a) else a)

您提供的语法都是可能的,所以模棱两可。

© www.soinside.com 2019 - 2024. All rights reserved.