-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
424 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Lrama | ||
class Grammar | ||
class Destructor < Struct.new(:ident_or_tags, :token_code, :lineno, keyword_init: true) | ||
def translated_code(tag) | ||
Code::DestructorCode.new(type: :destructor, token_code: token_code, tag: tag).translated_code | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ class Lexer | |
%define | ||
%require | ||
%printer | ||
%destructor | ||
%lex-param | ||
%parse-param | ||
%initial-action | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.