Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 596885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:13:13+00:00 2026-05-13T16:13:13+00:00

Most things that look like operators are methods in Ruby; 1 + 2 is

  • 0

Most things that look like operators are methods in Ruby; 1 + 2 is syntactic sugar for 1.+(2).

Even though + and * are methods that a program can redefine, Ruby has special magic to evaluate 1 + 2 * 3 as 1.+(2.*(3)) instead of 1.+(2).*(3).

I wonder where this special magic lives in Ruby–if it is hard-wired into the interpreter.

Ari.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:13:14+00:00Added an answer on May 13, 2026 at 4:13 pm

    In all Ruby Implementations, Operator Precedence is handled by the parser. Since pretty much all existing Ruby Implementations use the same parser, or a parser generated from the same YACC grammar, parse.y in YARV is the file you want to look at. (In JRuby, for example, that file is essentially the same: src/org/jruby/parser/Ruby19Parser.y. Same for IronRuby: Merlin/Main/Languages/Ruby/Ruby/Compiler/Parser/Parser.y.)

    The only four Ruby Implementations that do not either use the YARV parser directly or use a YACC clone generated parser from YARV’s parse.y, are Cardinal, tinyrb, RubyGoLightly and XRuby.

    Cardinal is a Ruby implementation for the Parrot virtual machine, and since Parrot includes the Parrot Grammar Engine, Cardinal naturally uses that. The interesting file is src/parser/grammar.pg. PGE is a hybrid recursive-descent parser/operator precedence parser, which means that operator precedence shows up pretty nicely in the grammar file.

    Tinyrb uses a PEG parser utilizing Ian Piumarta’s leg library. As is typical for PEG parsers, there is no operator precedence table, rather the precedence is implicit in the hierarchical structure of the grammar. See vm/grammar.leg for details. RubyGoLightly is derived from tinyrb, except it uses Go instead of C as the implementation language, but it uses the same PEG grammar.

    XRuby uses ANTLR for its parser. Here, the interesting file is src/com/xruby/compiler/parser/ruby.g.

    Rubinius uses the Melbourne parser, which is essentially YARV’s parser packaged as a C extension. MagLev uses ruby_parser (see below).

    Apart from the Ruby Implementations, there are also other Ruby parsers available.

    Ryan Davis’s ruby_parser is derived from the YARV YACC grammar. It uses racc as the parser generator. See lib/ruby_parser.y.

    Caleb Clausen’s RedParse uses Caleb’s own hand-written compiler-interpreter. The interesting file is lib/redparse/babyparser.rb.

    That’s all the parsers I know, that actually handle operator precedence. There is another parser built into RDoc, and there used to be one in YARD (it now uses RedParse), but those only handle just enough of Ruby’s syntax to find modules, classes and methods, comments and extract method parameter lists. They don’t deal with operator precedence.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not a bug. triggerHandler() doesn't bubble the event, and live()… May 14, 2026 at 8:34 pm
  • Editorial Team
    Editorial Team added an answer I dont think it's possible to switch to another activity… May 14, 2026 at 8:34 pm
  • Editorial Team
    Editorial Team added an answer $values = array(); $q = "SELECT * FROM table"; $resu… May 14, 2026 at 8:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.