ANTLR符号表中的这些值是什么意思?

问题描述 投票:0回答:1

我已将符号表转储到antlr中,但我有几个字段不清楚它们的含义。如果有对此的参考,请指出。该表具有标识符,然后是starttoken,endtoken,otherinfo。我已按组将其分解]

  • 1565614310是标识符-我有
  • startToken = [TokenInformation:L:1,charPosInL:8,s:8,e:11,i:1]
  • endToken = [TokenInformation:L:1,charPosInL:8,s:8,e:11,i:1]
  • otherinfo = [状态:737-类型:标识符]

方括号是我的。在startToken中,我看到它开始的行(L:1)和列(:8)以及endtoken的相应结尾。开始(s),结束(e)和索引(i)是什么意思?没有看到押韵或理由。

Otherinfo =什么是国家?它不符合我所看到的任何东西。

这里有几行,因此您可以感觉到输出。

1565614310 - [TokenInformation: L:1, charPosInL:8, s:8, e: 11, i: 1] - [TokenInformation: L:1, charPosInL:8, s:8, e: 11, i: 1] - State: 737 - Type: Identifier
783141366 - [TokenInformation: L:3, charPosInL:0, s:17, e: 22, i: 3] - [TokenInformation: L:29, charPosInL:0, s:832, e: 832, i: 3] - State: 777 - Type: PUBLIC
688113407 - [TokenInformation: L:3, charPosInL:0, s:17, e: 22, i: 3] - [TokenInformation: L:3, charPosInL:0, s:17, e: 22, i: 3] - State: 781 - Type: PUBLIC
1638864144 - [TokenInformation: L:3, charPosInL:22, s:39, e: 39, i: 6] - [TokenInformation: L:29, charPosInL:0, s:832, e: 832, i: 6] - State: 798 - Type: LBRACE

谢谢

compiler-construction antlr
1个回答
2
投票

我找不到打印此信息的代码,所以我只能给出有根据的猜测:

  • L显然是源代码行
  • s:可以是此符号的令牌的起始字符索引
  • e:可能是此符号的令牌的结束字符索引(注意:结束索引始终指向最后一个字符,而不是其后的位置,因此长度计算必须始终加1:[C0 ]。
  • i:然后是此符号的令牌索引
  • otherinfo:包含有关令牌的更多详细信息,例如令牌的状态号和类型。

对于状态号:记住,解析过程是由具有状态和转换的基础网络:ATN(增强的转换网络)控制的。

为了完整性:

  • Java(和原始)符号表版本为length = end - start + 1
  • 可以在symbtab中找到C ++端口。
  • Typescript端口是我的MySQL Workbench repository(antlr-c3)的一部分。

注意:当我说“端口”时,这是不正确的。非Java版本是使用Java变体中的基本原理的重新实现。有显着差异。

© www.soinside.com 2019 - 2024. All rights reserved.