0

我想运行一个简单的 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$
4

1 回答 1

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功能之前警告您。
于 2013-11-11T08:16:18.203 回答