Class: Lrama::Grammar::Code
- Inherits:
-
Struct
- Object
- Struct
- Lrama::Grammar::Code
- Extended by:
- Forwardable
- Defined in:
- lib/lrama/grammar/code.rb
Instance Attribute Summary collapse
-
#token_code ⇒ Object
Returns the value of attribute token_code.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#translated_code ⇒ Object
$$, $n, @$, @n is translated to C code.
-
#translated_printer_code(tag) ⇒ Object
(also: #translated_error_token_code)
-
($1) error * ($$) *yyvaluep * (@1) error * (@$) *yylocationp.
-
Instance Attribute Details
#token_code ⇒ Object
Returns the value of attribute token_code
5 6 7 |
# File 'lib/lrama/grammar/code.rb', line 5 def token_code @token_code end |
#type ⇒ Object
Returns the value of attribute type
5 6 7 |
# File 'lib/lrama/grammar/code.rb', line 5 def type @type end |
Instance Method Details
#translated_code ⇒ Object
$$, $n, @$, @n is translated to C code
11 12 13 14 15 16 17 18 |
# File 'lib/lrama/grammar/code.rb', line 11 def translated_code case type when :user_code translated_user_code when :initial_action translated_initial_action_code end end |
#translated_printer_code(tag) ⇒ Object Also known as: translated_error_token_code
-
($1) error
-
($$) *yyvaluep
-
(@1) error
-
(@$) *yylocationp
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lrama/grammar/code.rb', line 24 def translated_printer_code(tag) t_code = s_value.dup references.reverse.each do |ref| first_column = ref.first_column last_column = ref.last_column case when ref.value == "$" && ref.type == :dollar # $$ # Omit "<>" member = tag.s_value[1..-2] str = "((*yyvaluep).#{member})" when ref.value == "$" && ref.type == :at # @$ str = "(*yylocationp)" when ref.type == :dollar # $n raise "$#{ref.value} can not be used in %printer." when ref.type == :at # @n raise "@#{ref.value} can not be used in %printer." else raise "Unexpected. #{self}, #{ref}" end t_code[first_column..last_column] = str end return t_code end |