diff options
author | yui-knk <spiketeika@gmail.com> | 2023-11-18 17:46:38 +0900 |
---|---|---|
committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2023-11-18 19:38:55 +0900 |
commit | c56dd94db0001b900a2dab3ee350a182d6bb42af (patch) | |
tree | 7a4f5236452ae721f67fe6602f3dcbc68a085ac1 /tool/lrama/lib/lrama/grammar/code/printer_code.rb | |
parent | f479e629ab497f325091096819fa5bf60c0d03b2 (diff) | |
download | ruby-c56dd94db0001b900a2dab3ee350a182d6bb42af.tar.gz |
Lrama v0.5.10
Diffstat (limited to 'tool/lrama/lib/lrama/grammar/code/printer_code.rb')
-rw-r--r-- | tool/lrama/lib/lrama/grammar/code/printer_code.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tool/lrama/lib/lrama/grammar/code/printer_code.rb b/tool/lrama/lib/lrama/grammar/code/printer_code.rb new file mode 100644 index 0000000000..a19646adda --- /dev/null +++ b/tool/lrama/lib/lrama/grammar/code/printer_code.rb @@ -0,0 +1,34 @@ +module Lrama + class Grammar + class Code + class PrinterCode < Code + def initialize(type: nil, token_code: nil, tag: nil) + super(type: type, token_code: token_code) + @tag = tag + end + + private + + # * ($$) *yyvaluep + # * (@$) *yylocationp + # * ($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 == :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}." + else + raise "Unexpected. #{self}, #{ref}" + end + end + end + end + end +end |