【问题标题】:Basic parse failure in Rascal MPL Basic Entity ModellingRascal MPL 基本实体建模中的基本解析失败
【发布时间】:2013-11-10 23:59:55
【问题描述】:

我想运行一个简单的 Rascal MPL 解析示例,并尝试遵循 2011 年 5 月 3 日的 Rascal Language Workbench (18531D.pdf) 中的清单 1。我已经下载了当前的 Rascal MPL 版本 0.5。 1,并注意一些模块路径已更改。下面显示了我的Entity.rsc的内容:

module tut1::Entities                                                   

extend lang::std::Layout;                                                       
extend lang::std::Id;                                                           
extend Type;

start syntax Entities                                                           
  = entities: Entity* entities;                                                 
syntax Entity                                                                   
  = @Foldable entity: "entity" Id name "{" Field* "}";                          
syntax Field                                                                    
  = field: Symbol Id name;

我在这里假设 NameIdent 现在是 IdType 现在是 Symbol。然后我继续如下:

rascal>import tut1::Entities;
ok
rascal>import ParseTree;
ok

但是,当我尝试执行关键的 parse 函数时,我收到下面列出的错误。我哪里错了? (尽管有消息我注意到我可以在 Rascal 提示符下声明一个 Symbol 变量。)

rascal>parse(#Entities, "entity Person { string name integer age }");
Extending again?? ParseTree
Extending again?? Type
expanding parameterized symbols
generating stubs for regular
generating literals
establishing production set
generating item allocations
computing priority and associativity filter
printing the source code of the parser class
|prompt:///|(22,43,<1,22>,<1,65>): Java("Undeclared non-terminal: Symbol, in class: class org.rascalmpl.java.parser.object.$shell$")

    org.rascalmpl.parser.gtd.SGTDBF.invokeExpects(SGTDBF.java:139)
    org.rascalmpl.parser.gtd.SGTDBF.expandStack(SGTDBF.java:864)
    org.rascalmpl.parser.gtd.SGTDBF.expand(SGTDBF.java:971)
    org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1032)
    org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1089)
    org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1082)
    org.rascalmpl.interpreter.Evaluator.parseObject(Evaluator.java:493)
    org.rascalmpl.interpreter.Evaluator.parseObject(Evaluator.java:544)
    org.rascalmpl.library.Prelude.parse(Prelude.java:1644)
    org.rascalmpl.library.Prelude.parse(Prelude.java:1637)
    sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
    somewhere in: $shell$

【问题讨论】:

  • 当心,那是相当老的流氓版本! Eclipse 版本得到了更好的支持,但如果您愿意,我们可以提供一个新的命令行版本

标签: parsing context-free-grammar rascal


【解决方案1】:

示例已过时。这样的事情会更好:

module tut1::Entities

extend lang::std::Layout; // for spaces and such                                                      
extend lang::std::Id;     // for the Id non-terminal                                                       

start syntax Entities                                                           
  = entities: Entity* entities;                                                 
syntax Entity                                                                   
  = @Foldable entity: "entity" Id name "{" Field* "}";                          
syntax Field                                                                    
  = field: Id symbol Id name; // now Id is used instead of Symbol and "symbol" is just the name of a slot in the rule

一些解释:

  • 导入/扩展已消失,它们是不必要的,可能会造成混淆
  • 缺少Symbol 非终端的定义。我不知道它应该做什么,但它应该被定义为syntax Symbol = ...,但这对我来说没有意义,而是我重用了Id 来定义一个字段的类型。
  • 类型检查器(正在开发中)会在使用 parse 函数之前警告您。

【讨论】:

    猜你喜欢
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    相关资源
    最近更新 更多