Class: Postsvg::Source::AstBuilder
- Inherits:
-
Object
- Object
- Postsvg::Source::AstBuilder
- Defined in:
- lib/postsvg/source/ast_builder.rb
Overview
Walks a token stream from the Lexer and produces a typed Model::Program. Procedures, arrays, and dictionaries are kept as Model literal nodes; operators are constructed via the Model::Operators registry.
Constant Summary collapse
- MAX_PROC_DEPTH =
64
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#dict_stack ⇒ Object
readonly
Returns the value of attribute dict_stack.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#recursion_depth ⇒ Object
readonly
Returns the value of attribute recursion_depth.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(tokens) ⇒ AstBuilder
constructor
A new instance of AstBuilder.
Constructor Details
#initialize(tokens) ⇒ AstBuilder
Returns a new instance of AstBuilder.
14 15 16 17 18 19 20 21 |
# File 'lib/postsvg/source/ast_builder.rb', line 14 def initialize(tokens) @tokens = tokens @stack = OperandStack.new @body = [] @dict_stack = [{}] # global dictionary @header = Model::Program::Header.new @recursion_depth = 0 end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/postsvg/source/ast_builder.rb', line 10 def body @body end |
#dict_stack ⇒ Object (readonly)
Returns the value of attribute dict_stack.
10 11 12 |
# File 'lib/postsvg/source/ast_builder.rb', line 10 def dict_stack @dict_stack end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
10 11 12 |
# File 'lib/postsvg/source/ast_builder.rb', line 10 def header @header end |
#recursion_depth ⇒ Object (readonly)
Returns the value of attribute recursion_depth.
10 11 12 |
# File 'lib/postsvg/source/ast_builder.rb', line 10 def recursion_depth @recursion_depth end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
10 11 12 |
# File 'lib/postsvg/source/ast_builder.rb', line 10 def stack @stack end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
10 11 12 |
# File 'lib/postsvg/source/ast_builder.rb', line 10 def tokens @tokens end |
Class Method Details
.build(tokens) ⇒ Object
23 24 25 |
# File 'lib/postsvg/source/ast_builder.rb', line 23 def self.build(tokens) new(tokens).build end |