Rascal:Repl 中的树表示

Rascal: Tree Representation in Repl

我了解 Rascal repl 中的默认树表示已更改。按照 EXP Combined example 的配方,我得到

rascal>import demo::lang::Exp::Combined::Manual::Parse;
ok
rascal>parseExp("2+3*4");
Exp: (Exp) `2+3*4`

而文档说

rascal>import demo::lang::Exp::Combined::Manual::Parse;
ok
rascal>parseExp("2+3");
Tree: `2+3`
Tree: appl(prod(sort("Exp"),[sort("Exp"),layouts("Whitespace"), ...

有没有办法回到这个 "raw" 树形表示(只有语言研究人员才想看到 ;-),可能还有布局(缩进等)?

您可以使用 IO 库中的 iprintln 获取基础树表示:

rascal>import demo::lang::Exp::Combined::Manual::Parse;
ok
rascal>import IO;
ok
rascal>iprintln(parseExp("2+3*4"))
appl(
  prod(
    sort("Exp"),
    [
      sort("Exp"),
      layouts("Whitespace"),
      lit("+"),
      layouts("Whitespace"),
      sort("Exp")
    ],
    {assoc(left())}),
  [appl(
      prod(
        sort("Exp"),
        [lex("IntegerLiteral")],
        {}),
      [appl(
          prod(
            lex("IntegerLiteral"),
            [iter(\char-class([range(48,57)]))],
            {}),
          [appl(
              regular(iter(\char-class([range(48,57)]))),
              [char(50)])[
              @loc=|unknown:///|(0,1,<1,0>,<1,1>)
            ]])[
          @loc=|unknown:///|(0,1,<1,0>,<1,1>)
        ]])[
      @loc=|unknown:///|(0,1,<1,0>,<1,1>)
    ],appl(
      prod(
        layouts("Whitespace"),
        [\iter-star(\char-class([
                range(9,10),
                range(13,13),
                range(32,32)
              ]))],
        {}),
      [appl(
          regular(\iter-star(\char-class([
                  range(9,10),
                  range(13,13),
                  range(32,32)
                ]))),
          [])[
          @loc=|unknown:///|(1,0,<1,1>,<1,1>)
        ]])[
      @loc=|unknown:///|(1,0,<1,1>,<1,1>)
    ],appl(
      prod(
        lit("+"),
        [\char-class([range(43,43)])],
        {}),
      [char(43)]),appl(
      prod(
        layouts("Whitespace"),
        [\iter-star(\char-class([
                range(9,10),
                range(13,13),
                range(32,32)
              ]))],
        {}),
      [appl(
          regular(\iter-star(\char-class([
                  range(9,10),
                  range(13,13),
                  range(32,32)
                ]))),
          [])[
          @loc=|unknown:///|(2,0,<1,2>,<1,2>)
        ]])[
      @loc=|unknown:///|(2,0,<1,2>,<1,2>)
    ],appl(
      prod(
        sort("Exp"),
        [
          sort("Exp"),
          layouts("Whitespace"),
          lit("*"),
          layouts("Whitespace"),
          sort("Exp")
        ],
        {assoc(left())}),
      [appl(
          prod(
            sort("Exp"),
            [lex("IntegerLiteral")],
            {}),
          [appl(
              prod(
                lex("IntegerLiteral"),
                [iter(\char-class([range(48,57)]))],
                {}),
              [appl(
                  regular(iter(\char-class([range(48,57)]))),
                  [char(51)])[
                  @loc=|unknown:///|(2,1,<1,2>,<1,3>)
                ]])[
              @loc=|unknown:///|(2,1,<1,2>,<1,3>)
            ]])[
          @loc=|unknown:///|(2,1,<1,2>,<1,3>)
        ],appl(
          prod(
            layouts("Whitespace"),
            [\iter-star(\char-class([
                    range(9,10),
                    range(13,13),
                    range(32,32)
                  ]))],
            {}),
          [appl(
              regular(\iter-star(\char-class([
                      range(9,10),
                      range(13,13),
                      range(32,32)
                    ]))),
              [])[
              @loc=|unknown:///|(3,0,<1,3>,<1,3>)
            ]])[
          @loc=|unknown:///|(3,0,<1,3>,<1,3>)
        ],appl(
          prod(
            lit("*"),
            [\char-class([range(42,42)])],
            {}),
          [char(42)]),appl(
          prod(
            layouts("Whitespace"),
            [\iter-star(\char-class([
                    range(9,10),
                    range(13,13),
                    range(32,32)
                  ]))],
            {}),
          [appl(
              regular(\iter-star(\char-class([
                      range(9,10),
                      range(13,13),
                      range(32,32)
                    ]))),
              [])[
              @loc=|unknown:///|(4,0,<1,4>,<1,4>)
            ]])[
          @loc=|unknown:///|(4,0,<1,4>,<1,4>)
        ],appl(
          prod(
            sort("Exp"),
            [lex("IntegerLiteral")],
            {}),
          [appl(
              prod(
                lex("IntegerLiteral"),
                [iter(\char-class([range(48,57)]))],
                {}),
              [appl(
                  regular(iter(\char-class([range(48,57)]))),
                  [char(52)])[
                  @loc=|unknown:///|(4,1,<1,4>,<1,5>)
                ]])[
              @loc=|unknown:///|(4,1,<1,4>,<1,5>)
            ]])[
          @loc=|unknown:///|(4,1,<1,4>,<1,5>)
        ]])[
      @loc=|unknown:///|(2,3,<1,2>,<1,5>)
    ]])[
  @loc=|unknown:///|(0,5,<1,0>,<1,5>)
]
ok