summaryrefslogtreecommitdiff
path: root/tool/lrama/lib/lrama/grammar/code/destructor_code.rb
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2024-03-22 08:17:51 +0900
committerYuichiro Kaneko <spiketeika@gmail.com>2024-03-22 11:53:15 +0900
commitc5045830b7ed3bf664633871ca21fcfe03a42aa7 (patch)
treec592834d65fe6c4e76459771d4ced00589540efe /tool/lrama/lib/lrama/grammar/code/destructor_code.rb
parentb4d73e9f80aa5fe72c39f42a88727fed0abb261b (diff)
Lrama v0.6.4
Diffstat (limited to 'tool/lrama/lib/lrama/grammar/code/destructor_code.rb')
-rw-r--r--tool/lrama/lib/lrama/grammar/code/destructor_code.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/tool/lrama/lib/lrama/grammar/code/destructor_code.rb b/tool/lrama/lib/lrama/grammar/code/destructor_code.rb
new file mode 100644
index 0000000000..70360eb90f
--- /dev/null
+++ b/tool/lrama/lib/lrama/grammar/code/destructor_code.rb
@@ -0,0 +1,40 @@
+module Lrama
+ class Grammar
+ class Code
+ class DestructorCode < Code
+ def initialize(type:, token_code:, tag:)
+ super(type: type, token_code: token_code)
+ @tag = tag
+ end
+
+ private
+
+ # * ($$) *yyvaluep
+ # * (@$) *yylocationp
+ # * ($:$) error
+ # * ($1) error
+ # * (@1) error
+ # * ($:1) error
+ def reference_to_c(ref)
+ case
+ when ref.type == :dollar && ref.name == "$" # $$
+ member = @tag.member
+ "((*yyvaluep).#{member})"
+ when ref.type == :at && ref.name == "$" # @$
+ "(*yylocationp)"
+ when ref.type == :index && ref.name == "$" # $:$
+ raise "$:#{ref.value} can not be used in #{type}."
+ when ref.type == :dollar # $n
+ raise "$#{ref.value} can not be used in #{type}."
+ when ref.type == :at # @n
+ raise "@#{ref.value} can not be used in #{type}."
+ when ref.type == :index # $:n
+ raise "$:#{ref.value} can not be used in #{type}."
+ else
+ raise "Unexpected. #{self}, #{ref}"
+ end
+ end
+ end
+ end
+ end
+end