'c' parse rule tree (not heavily tested)

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

'c' parse rule tree (not heavily tested)

r.crowther
Aye,

So I'm on the way with a Parboiled/Scala rule tree,

https://github.com/rcrowther/cparser

Unimaginatively named, I guess. Don't know if anyone has done this
before. Still, if anyone is interested, here it is, crawling from the
blocks.

Preprocessing directives included (groan),
Rob

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

Re: 'c' parse rule tree (not heavily tested)

mathias
Administrator
Rob,

quite interesting, thanks for the pointer!
Have you seen parboiled 2 yet?

If you are working in Scala then pb2 should be interesting.
Mainly because its parsing perf is about 5-10 times higher and it parser generation runs at compile time rather than at runtime.

Also, have you seen this PEG grammar for C: http://www.romanredz.se/freesoft.htm#C ?

Cheers,
Mathias

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

On 25.4.2015, at 10:55, r.crowther [via parboiled users] <[hidden email]> wrote:

> Aye,
>
> So I'm on the way with a Parboiled/Scala rule tree,
>
> https://github.com/rcrowther/cparser
>
> Unimaginatively named, I guess. Don't know if anyone has done this
> before. Still, if anyone is interested, here it is, crawling from the
> blocks.
>
> Preprocessing directives included (groan),
> Rob
>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/c-parse-rule-tree-not-heavily-tested-tp4024397.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML

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

Re: 'c' parse rule tree (not heavily tested)

r.crowther@npost.co.uk
Mathias,

Once or twice I wondered about the references to "mouse". Thanks for the link! May have saved me some regexing, had I known. When I get a chance, I'll cross reference the mouse version against mine.

I'm using Parboiled 2, but not in any significant way beyond understanding it as a "recent version of Parboiled". My target was practical parsing of 'c' files. Hence the extensive documentation. And my willingness to try limited parsing of pre-processing directives (macro expansion makes from-raw-text parsing near impossible, but I may yet try something with the stack... or skip lines with a generic rule).

If you have the time, a snippet about how to use the Terminal helper (as with the Parboiled Java parser) would help DRY the tree. The parser compiled, but wouldn't parse, when I used those methods. I didn't dig in though, to look at types.

Rob
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 'c' parse rule tree (not heavily tested)

r.crowther@npost.co.uk
I appeal to myself, "Please be precise!"

Use of the helpers caused the parser to parse incorrectly, not recognising the terminal rules. The parser did complete runs. I can give more data if you like.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 'c' parse rule tree (not heavily tested)

mathias
Administrator
In reply to this post by r.crowther@npost.co.uk
> If you have the time, a snippet about how to use the Terminal helper (as with the Parboiled Java parser) would help DRY the tree. The parser compiled, but wouldn't parse, when I used those methods. I didn't dig in though, to look at types.

What was the problem you experienced with the `Terminal` helper?

I assume you mean this one from the pb1 Java parser example:

    Rule Terminal(String string) {
      return Sequence(string, Spacing()).label('\'' + string + '\'');
    }

Was it the labelling?
Apart from that it should be no problem to define pretty much the identical rule in pb2.

Cheers,
Mathias

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

On 27.4.2015, at 12:18, [hidden email] [via parboiled users] <[hidden email]> wrote:

> Mathias,
>
> Once or twice I wondered about the references to "mouse". Thanks for the link! May have saved me some regexing, had I known. When I get a chance, I'll cross reference the mouse version against mine.
>
> I'm using Parboiled 2, but not in any significant way beyond understanding it as a "recent version of Parboiled". My target was practical parsing of 'c' files. Hence the extensive documentation. And my willingness to try limited parsing of pre-processing directives (macro expansion makes from-raw-text parsing near impossible, but I may yet try something with the stack... or skip lines with a generic rule).
>
> If you have the time, a snippet about how to use the Terminal helper (as with the Parboiled Java parser) would help DRY the tree. The parser compiled, but wouldn't parse, when I used those methods. I didn't dig in though, to look at types.
>
> Rob
>  
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/c-parse-rule-tree-not-heavily-tested-tp4024397p4024399.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML

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

Re: 'c' parse rule tree (not heavily tested)

r.crowther@npost.co.uk
The problem with having neat rules DRYing out every terminal node is that if something is wrong in the grammar, traces suggest it's the helper code, when it's not.

I'm also suspecting some Scala inference is not working as I intended, because I've now had this happen twice.

Ah well. No real problem, once you know.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 'c' parse rule tree (not heavily tested)

r.crowther@npost.co.uk
In reply to this post by mathias
I've been unable to code for a week. This puts me way off-schedule. Which I regret.

Current state of play is that there is now a C parser based on the Mouse grammar. The original Mouse conversion checked typedefs, and was demanding (likely accurate). The published version has a workround to make it more forgiving. The original BISON conversion is still available.

Rob
Loading...