Class: Faust2Ruby::Parser
- Inherits:
-
Object
- Object
- Faust2Ruby::Parser
- Defined in:
- lib/faust2ruby/parser.rb
Overview
Recursive descent parser for Faust DSP programs. Grammar based on Faust’s official grammar with simplified precedence.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- PRECEDENCE =
Operator precedence (lowest to highest) In Faust: SEQ < PAR < SPLIT/MERGE < REC < arithmetic
{ PAR: 1, # , (parallel - lowest, used as arg separator) SEQ: 2, # : (sequential) SPLIT: 3, # <: MERGE: 3, # :> REC: 4, # ~ OR: 5, # | AND: 6, # & LT: 7, GT: 7, LE: 7, GE: 7, EQ: 7, NEQ: 7, # comparison ADD: 8, SUB: 8, # + - MUL: 9, DIV: 9, MOD: 9, # * / % POW: 10, # ^ DELAY: 11, # @ }.freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(source) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(source) ⇒ Parser
Returns a new instance of Parser.
37 38 39 40 41 42 |
# File 'lib/faust2ruby/parser.rb', line 37 def initialize(source) @lexer = Lexer.new(source) @tokens = @lexer.tokenize @pos = 0 @errors = @lexer.errors.dup end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
53 54 55 |
# File 'lib/faust2ruby/parser.rb', line 53 def errors @errors end |
Instance Method Details
#parse ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/faust2ruby/parser.rb', line 44 def parse statements = [] until current_type == :EOF stmt = parse_statement statements << stmt if stmt end AST::Program.new(statements) end |