【问题标题】:Making an if statement in antlr4 not working在 antlr4 中做一个 if 语句不起作用
【发布时间】:2022-11-20 04:41:57
【问题描述】:

我一直在尝试用我的编程语言在 antlr4 中创建一个 if 语句

我失败的语法是:

if_stmt: IF conditional_block stmt_block (ELSE IF conditional_block stmt_block)* (ELSE conditional_block stmt_block)?;

但它给出了错误:

line 3:2 extraneous input 'else' expecting {<EOF>, '!', BOOLEAN, 'null', 'func', 'if', 'while', 'for', ID, INTEGER, FLOAT, STRING}
line 4:27 extraneous input ')' expecting {<EOF>, '!', BOOLEAN, 'null', 'func', 'if', 'while', 'for', ID, INTEGER, FLOAT, STRING}

它期待“其他” 我进入程序的代码是:

if false {
    println("Hello World!")
} else {
    println("This is true")
}

【问题讨论】:

    标签: python antlr4


    【解决方案1】:

    这看起来很可疑:

    (ELSE conditional_block stmt_block)?
    

    这可能应该是:

    (ELSE stmt_block)?
    

    不确定这是否能解决您的问题。如果没有,您需要编辑您的问题并添加足够的语法,以便其他人能够重现您提到的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2012-07-16
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 2016-04-25
      相关资源
      最近更新 更多