class Solver::Parser
Constants
- RULE_METHODS
- TOKENS_FOLLOWING_DIV_IN_mult_238
- TOKENS_FOLLOWING_EXP_IN_exp_307
- TOKENS_FOLLOWING_FLOAT_IN_atom_356
- TOKENS_FOLLOWING_INT_IN_atom_341
- TOKENS_FOLLOWING_LPAREN_IN_atom_367
- TOKENS_FOLLOWING_MINUS_IN_expression_182
- TOKENS_FOLLOWING_MODVAR_IN_atom_386
- TOKENS_FOLLOWING_MULT_IN_mult_224
- TOKENS_FOLLOWING_PLUS_IN_expression_168
- TOKENS_FOLLOWING_RPAREN_IN_atom_375
- TOKENS_FOLLOWING_T__19_IN_log_268
- TOKENS_FOLLOWING_UNMODVAR_IN_atom_400
- TOKENS_FOLLOWING_atom_IN_exp_303
- TOKENS_FOLLOWING_atom_IN_exp_311
- TOKENS_FOLLOWING_exp_IN_log_272
- TOKENS_FOLLOWING_exp_IN_log_282
- TOKENS_FOLLOWING_expression_IN_atom_371
- TOKENS_FOLLOWING_expression_IN_evaluate_139
- TOKENS_FOLLOWING_log_IN_mult_216
- TOKENS_FOLLOWING_log_IN_mult_228
- TOKENS_FOLLOWING_log_IN_mult_242
- TOKENS_FOLLOWING_mult_IN_expression_160
- TOKENS_FOLLOWING_mult_IN_expression_172
- TOKENS_FOLLOWING_mult_IN_expression_186
Attributes
expressionCache[RW]
objectCache[RW]
Public Class Methods
new( input, options = {} )
click to toggle source
Calls superclass method
# File lib/plympton/SolverParser.rb, line 109 def initialize( input, options = {} ) super( input, options ) end
Public Instance Methods
atom()
click to toggle source
parser rule atom
(in solver.g) 82:1: atom returns [result] : (a= INT | a= FLOAT | LPAREN r= expression RPAREN | a= MODVAR | a= UNMODVAR ) ;
# File lib/plympton/SolverParser.rb, line 431 def atom # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 6 ) result = nil a = nil r = nil begin # at line 83:7: (a= INT | a= FLOAT | LPAREN r= expression RPAREN | a= MODVAR | a= UNMODVAR ) # at line 83:7: (a= INT | a= FLOAT | LPAREN r= expression RPAREN | a= MODVAR | a= UNMODVAR ) alt_5 = 5 case look_5 = @input.peek( 1 ) when INT then alt_5 = 1 when FLOAT then alt_5 = 2 when LPAREN then alt_5 = 3 when MODVAR then alt_5 = 4 when UNMODVAR then alt_5 = 5 else raise NoViableAlternative( "", 5, 0 ) end case alt_5 when 1 # at line 83:8: a= INT a = match( INT, TOKENS_FOLLOWING_INT_IN_atom_341 ) # --> action result = BigDecimal(a.text) # <-- action when 2 # at line 84:8: a= FLOAT a = match( FLOAT, TOKENS_FOLLOWING_FLOAT_IN_atom_356 ) # --> action result = BigDecimal(a.text) # <-- action when 3 # at line 85:8: LPAREN r= expression RPAREN match( LPAREN, TOKENS_FOLLOWING_LPAREN_IN_atom_367 ) @state.following.push( TOKENS_FOLLOWING_expression_IN_atom_371 ) r = expression @state.following.pop # --> action result = r # <-- action match( RPAREN, TOKENS_FOLLOWING_RPAREN_IN_atom_375 ) when 4 # at line 86:8: a= MODVAR a = match( MODVAR, TOKENS_FOLLOWING_MODVAR_IN_atom_386 ) # --> action result = @objectCache.send(a.text) # <-- action when 5 # at line 89:8: a= UNMODVAR a = match( UNMODVAR, TOKENS_FOLLOWING_UNMODVAR_IN_atom_400 ) # --> action case a.text when 'R' result = @objectCache.runtime when 'U' result = @objectCache.send(a.text) when 'V' result = @objectCache.send(a.text) else result = BigDecimal("0") end # <-- action end rescue ANTLR3::Error::RecognitionError => re report_error(re) recover(re) ensure # -> uncomment the next line to manually enable rule tracing # trace_out( __method__, 6 ) end return result end
evaluate()
click to toggle source
parser rule evaluate
(in solver.g) 57:1: evaluate returns [result] : r= expression ;
# File lib/plympton/SolverParser.rb, line 138 def evaluate # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 1 ) result = nil r = nil begin # at line 58:6: r= expression @state.following.push( TOKENS_FOLLOWING_expression_IN_evaluate_139 ) r = expression @state.following.pop # --> action result = r # <-- action rescue ANTLR3::Error::RecognitionError => re report_error(re) recover(re) ensure # -> uncomment the next line to manually enable rule tracing # trace_out( __method__, 1 ) end return result end
exp()
click to toggle source
parser rule exp
(in solver.g) 78:1: exp returns [result] : r= atom ( ‘^’ r2= atom )? ;
# File lib/plympton/SolverParser.rb, line 376 def exp # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 5 ) result = nil r = nil r2 = nil begin # at line 79:5: r= atom ( '^' r2= atom )? @state.following.push( TOKENS_FOLLOWING_atom_IN_exp_303 ) r = atom @state.following.pop # at line 79:12: ( '^' r2= atom )? alt_4 = 2 look_4_0 = @input.peek( 1 ) if ( look_4_0 == EXP ) alt_4 = 1 end case alt_4 when 1 # at line 79:14: '^' r2= atom match( EXP, TOKENS_FOLLOWING_EXP_IN_exp_307 ) @state.following.push( TOKENS_FOLLOWING_atom_IN_exp_311 ) r2 = atom @state.following.pop # --> action r **= r2.to_i() # <-- action end # --> action result = r # <-- action rescue ANTLR3::Error::RecognitionError => re report_error(re) recover(re) ensure # -> uncomment the next line to manually enable rule tracing # trace_out( __method__, 5 ) end return result end
expression()
click to toggle source
parser rule expression
(in solver.g) 60:1: expression returns [result] : r= mult ( ‘+’ r2= mult | ‘-’ r2= mult )* ;
# File lib/plympton/SolverParser.rb, line 173 def expression # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 2 ) result = nil r = nil r2 = nil begin # at line 61:5: r= mult ( '+' r2= mult | '-' r2= mult )* @state.following.push( TOKENS_FOLLOWING_mult_IN_expression_160 ) r = mult @state.following.pop # at line 62:5: ( '+' r2= mult | '-' r2= mult )* while true # decision 1 alt_1 = 3 look_1_0 = @input.peek( 1 ) if ( look_1_0 == PLUS ) alt_1 = 1 elsif ( look_1_0 == MINUS ) alt_1 = 2 end case alt_1 when 1 # at line 62:7: '+' r2= mult match( PLUS, TOKENS_FOLLOWING_PLUS_IN_expression_168 ) @state.following.push( TOKENS_FOLLOWING_mult_IN_expression_172 ) r2 = mult @state.following.pop # --> action r += r2 # <-- action when 2 # at line 63:7: '-' r2= mult match( MINUS, TOKENS_FOLLOWING_MINUS_IN_expression_182 ) @state.following.push( TOKENS_FOLLOWING_mult_IN_expression_186 ) r2 = mult @state.following.pop # --> action r -= r2 # <-- action else break # out of loop for decision 1 end end # loop for decision 1 # --> action result = r # <-- action rescue ANTLR3::Error::RecognitionError => re report_error(re) recover(re) ensure # -> uncomment the next line to manually enable rule tracing # trace_out( __method__, 2 ) end return result end
log()
click to toggle source
parser rule log
(in solver.g) 73:1: log returns [result] : ( ‘ln’ r= exp | r= exp );
# File lib/plympton/SolverParser.rb, line 317 def log # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 4 ) result = nil r = nil begin # at line 74:3: ( 'ln' r= exp | r= exp ) alt_3 = 2 look_3_0 = @input.peek( 1 ) if ( look_3_0 == T__19 ) alt_3 = 1 elsif ( look_3_0 == LPAREN || look_3_0.between?( INT, UNMODVAR ) ) alt_3 = 2 else raise NoViableAlternative( "", 3, 0 ) end case alt_3 when 1 # at line 74:5: 'ln' r= exp match( T__19, TOKENS_FOLLOWING_T__19_IN_log_268 ) @state.following.push( TOKENS_FOLLOWING_exp_IN_log_272 ) r = exp @state.following.pop # --> action result = BigMath.log(r, 2) # <-- action when 2 # at line 75:5: r= exp @state.following.push( TOKENS_FOLLOWING_exp_IN_log_282 ) r = exp @state.following.pop # --> action result = r # <-- action end rescue ANTLR3::Error::RecognitionError => re report_error(re) recover(re) ensure # -> uncomment the next line to manually enable rule tracing # trace_out( __method__, 4 ) end return result end
mult()
click to toggle source
parser rule mult
(in solver.g) 67:1: mult returns [result] : r= log ( ‘*’ r2= log | ‘/’ r2= log )* ;
# File lib/plympton/SolverParser.rb, line 245 def mult # -> uncomment the next line to manually enable rule tracing # trace_in( __method__, 3 ) result = nil r = nil r2 = nil begin # at line 68:5: r= log ( '*' r2= log | '/' r2= log )* @state.following.push( TOKENS_FOLLOWING_log_IN_mult_216 ) r = log @state.following.pop # at line 69:5: ( '*' r2= log | '/' r2= log )* while true # decision 2 alt_2 = 3 look_2_0 = @input.peek( 1 ) if ( look_2_0 == MULT ) alt_2 = 1 elsif ( look_2_0 == DIV ) alt_2 = 2 end case alt_2 when 1 # at line 69:7: '*' r2= log match( MULT, TOKENS_FOLLOWING_MULT_IN_mult_224 ) @state.following.push( TOKENS_FOLLOWING_log_IN_mult_228 ) r2 = log @state.following.pop # --> action r *= r2 # <-- action when 2 # at line 70:7: '/' r2= log match( DIV, TOKENS_FOLLOWING_DIV_IN_mult_238 ) @state.following.push( TOKENS_FOLLOWING_log_IN_mult_242 ) r2 = log @state.following.pop # --> action r /= r2 # <-- action else break # out of loop for decision 2 end end # loop for decision 2 # --> action result = r # <-- action rescue ANTLR3::Error::RecognitionError => re report_error(re) recover(re) ensure # -> uncomment the next line to manually enable rule tracing # trace_out( __method__, 3 ) end return result end
recover( error = $! )
click to toggle source
Recovery function handling errors
# File lib/plympton/SolverParser.rb, line 119 def recover( error = $! ) puts "Parser Recovering: #{error}" exit(1) end
report_error( error = $! )
click to toggle source
Reporting function handling errors
# File lib/plympton/SolverParser.rb, line 125 def report_error( error = $! ) puts "Parser Reporting: #{error}" exit(1) end