【问题标题】:Meaning of insert() semantic function in attribute grammar属性语法中insert()语义函数的含义
【发布时间】:2021-03-05 09:49:34
【问题描述】:

我目前正在尝试为这个属性语法绘制属性流。

decl → ID decl tail
 decl.t := decl tail.t  
 decl tail.in tab := insert (decl.in tab, ID.n, decl tail.t)  
 decl.out tab := decl tail.out tab  

decl tail → , decl
 decl tail.t := decl.t  
 decl.in tab := decl tail.in tab  
 decl tail.out tab := decl.out tab  

decl tail → : ID ;
 decl tail.t := ID.n  
 decl tail.out tab := decl tail.in tab  

但我不明白insert (decl.in tab, ID.n, decl tail.t) 是什么意思。
我的第一个假设是它类似于 Python 中的 insert() 函数。
但是据我所知,Python 的insert() 带两个参数,但是在这个属性语法中它带三个参数decl.in tab, ID.n, decl tail.t 所以我原来的假设在这里显然是错误的。
我对编译器设计很陌生,我很难弄清楚一些我以前从未见过的语义函数的含义。 (例如ReduceTo()

insert (decl.in tab, ID.n, decl tail.t) 是什么意思?
有没有我需要知道或记住的语义函数列表?

【问题讨论】:

    标签: parsing compiler-construction grammar semantics parse-tree


    【解决方案1】:

    猜测的目的是将具有指定类型的声明变量添加到符号表(“tab”)中。

    然而,为了分析属性流,你并不需要知道insert 做了什么。您只需要知道它需要某些值(它的参数),因此这些属性必须可用才能计算从函数的返回值分配的属性。

    属性语法没有预定义的语义函数,因此您无需担心记住它们的列表。特定属性语法应用程序中使用的特定语义函数将由该应用程序本身指定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      • 2018-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 2013-02-08
      相关资源
      最近更新 更多