Quantcast

Precedence climbing

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Precedence climbing

chrisl
Does anyone have an example of a precedence climbing implementation in Parboiled?

Cheers,
Chris
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Precedence climbing

mathias
Administrator
Chris,

the calculator examples implement precedence climbing for the basic mathematical operators:
https://github.com/sirthias/parboiled/wiki/Calculators

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 09.04.2013, at 18:40, "chrisl [via parboiled users]" <[hidden email]> wrote:

>
>
> Does anyone have an example of a  precedence climbing
> <http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing>  
> implementation in Parboiled?
>
> Cheers,
> Chris
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Precedence-climbing-tp4024168.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Precedence climbing

chrisl
I don't believe those are examples of precedence climbing, at least not in the way I imagine it.

In all the calculator examples, the operators are explicitly declared and grouped into Expressions, Terms and Factors - which imply their precedence within these grammar rules. That seems to be a "classic solution" (Recursive Decent Recognition).

I believe a precedence climbing solution would have a simpler grammar that matches any OperatorChars (anyOf('+-*/')) in an infix position, and use a separate table of precedence levels to decide how to group them.

Is there a reason that belief is incorrect?

Cheers,
Chris

PS. I'm interested in this, as I'm trying to parse a grammar that would allow runtime definition of infix operators/functions with varying precedence levels. Thus it's imposible to know at coding time whether the infix operator belongs in Expressions, Terms or Factors, or indeed what the operator even is.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Precedence climbing

mathias
Administrator
Chris,

ok, sorry for not getting the point earlier.
From your description the "precedence climbing" you are talking about doesn't happen on the grammar level but rather in the logic layer on-top (e.g. the parser rules).
What support from parboiled would you like to see for it?

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 10.04.2013, at 10:10, "chrisl [via parboiled users]" <[hidden email]> wrote:

>
>
> I don't believe those are examples of precedence climbing, at least not in
> the way I imagine it.
>
> In all the calculator examples, the operators are explicitly declared and
> grouped into Expressions, Terms and Factors - which imply their precedence
> within these grammar rules. That seems to be a  "classic solution"
> (Recursive Decent Recognition)
> <http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#classic>  .
>
> I believe a precedence climbing solution would have a simpler grammar that
> matches any OperatorChars (anyOf('+-*/')) in an infix position, and use a
> separate table of precedence levels to decide how to group them.
>
> Is there a reason that belief is incorrect?
>
> Cheers,
> Chris
>
> PS. I'm interested in this, as I'm trying to parse a grammar that would
> allow runtime definition of infix operators/functions with varying
> precedence levels. Thus it's imposible to know at coding time whether the
> infix operator belongs in Expressions, Terms or Factors, or indeed what the
> operator even is.
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Precedence-climbing-tp4024168p4024170.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Precedence climbing

chrisl
Hey Mahtias,

I don't know if anything is needed in parboiled yet to achieve this. I was just curious if anyone already had an example of this being done.

Cheers,
Chris
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Precedence climbing

mathias
Administrator
Chris,

no, sorry, I don't know of any…

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 10.04.2013, at 16:13, chrisl [via parboiled users] <[hidden email]> wrote:

>
>
> Hey Mahtias,
>
> I don't know if anything is needed in parboiled yet to achieve this. I was
> just curious if anyone already had an example of this being done.
>
> Cheers,
> Chris
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Precedence-climbing-tp4024168p4024172.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Loading...