Compiler construction 解析器在此过程中使用什么产品来解析给定的字符串?

Compiler construction 解析器在此过程中使用什么产品来解析给定的字符串?,compiler-construction,Compiler Construction,用于悬挂if-else语句。给出的语法是stmt->matched_stmt | unmatched_stmt 匹配的\u stmt->if expre then matched \u stmt else matched \u stmt | other 不匹配\u stm->if expre then stmt | if expre then matched \u stmt else unmatched \u stmt 如何解析这个python if-else语句 x=int(input("E

用于悬挂if-else语句。给出的语法是stmt->matched_stmt | unmatched_stmt

匹配的\u stmt->if expre then matched \u stmt else matched \u stmt | other

不匹配\u stm->if expre then stmt | if expre then matched \u stmt else unmatched \u stmt

如何解析这个python if-else语句

x=int(input("Enter the value of x "))
if x<=10:
    print("in 10")
    if x<=5:
        print("in 5")
else:
    print("greater than 10")
x=int(输入(“输入x的值”))

if xPython的语法没有表现出悬空的else歧义,因为if语句的主体和可选else子句的存在是由缩进精确分隔的。另一种避免问题的方法是坚持使用关键字(
fi
)终止
if
语句


在任何情况下,龙书语法都不适用于Python。

如果在Python中空格很重要,那么语法是错误的,如果不是,那么缩进是错误的,这可能是造成混淆的唯一原因。缩进是正确的。我认为语法是错误的。但是语法来自ullman aho sethi编译器设计书。龙之书是在Python发明之前几十年编写的。如果缩进正确表达了您的意图,即
else
与第一个
If
关联,则您的语法不会对其进行描述。