help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is handwritten faster?


From: Chris verBurg
Subject: Re: Is handwritten faster?
Date: Fri, 2 Oct 2015 12:25:04 -0700

Hey Adam,

My two cents is to paraphrase John Levine's Flex & Bison book (ha! I almost
said Adam Levine!):
- yes, after tweaking, your manual parser will probably be faster.
- but that assumes you put all the necessary time into tweaking
- and you put in all the necessary time to get it functionally correct in
the first place
- but re-implementing Bison's nifty error unrolling is considered Extremely
Nontrivial.

So my vote would be, if this is a production with a deadline, use two Bison
parsers; otherwise if it's a pet (or research) project and you think it'd
be fun, write your own.

-Chris



On Fri, Oct 2, 2015 at 9:05 AM, Adam Smalin <address@hidden> wrote:

> I have a fairly complicated grammar. It's > 1000 lines not including
> comments with 6 shift-reduce conflicts and 4 reduce-reduce conflicts. I'm
> using %glr-parser because a few states are unreachable unless I use a GLR
> although only one is valid by the end of the line.
>
> I'm thinking about writing a parser by hand. My two questions are 1) Is it
> easy to write a (correct) parser that isn't efficient/fast? 2) Will I hate
> myself because my grammar is very complicated? I could create two bison
> parsers as another option but IDK how efficient it is versus a hand written
> parser. For example if you look at the code below I'd do one pass for the
> variables/functions then another for each function.
>
> I'm trying to avoid trees. With bison I know I'll execute the if body
> before the if but I could just create a char* and printf it later. If I
> were to write my own I don't know how complicated the line "c =
> a+b*3+atol(e)" will be.
>
> Bison definitely helped me but if I'm trying to be crazy efficient do I
> want to write a handmade parser (I kind of do) or do I want to write two
> bison parsers? Many rules will be shared in both like declaring a function
> can be inside and outside of a function (but an if cannot be outside)
>
> int a, b, c;
> void d() {
>   a=2
>   b=3
>   if(rand()> 0.5) {
>     c = a+b*3+atol(e)
>   } else c=9
>   printf("C: %d\n", c);
> }
> string e="5"
> _______________________________________________
> address@hidden https://lists.gnu.org/mailman/listinfo/help-bison
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]