Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Improvements #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Improvements #29

wants to merge 2 commits into from

Conversation

adams85
Copy link

@adams85 adams85 commented Sep 29, 2017

Hi!

I was looking for a parser generator and your project matched my requirements. However, I needed to make some improvements so i decided to fork it (to be precise, the 1.1-alpha version).

I've completely rewritten the ParserBase class as it had some problems.

  • You throw and catch exceptions to propagate them. Throwing exceptions in C# is expensive because of stack trace creation, etc. They are for exceptional cases, failure of a parse rule is not such a case.
  • You use a deep stack of function calls for parsing. Call stack is limited (see https://stackoverflow.com/questions/29832311/call-stack-limitation-in-c-sharp), so I changed this to emulating call stack using the Stack class. So the entire memory of the computer is available for the parser.

I revised the Parsable class (renamed to Scanner) and C# code emitter and made some performance optimalization:
perf_old

perf_new

I measured 10,000 iterations of parsing the pascal assignment grammar. There is some boost.

I made the generated code more readable, as well (https://github.com/adams85/human-parser-generator/blob/improvements/netcore/parser.cs), and included generation of the visitor pattern. (For demonstration, I rewrote AST generation using the visitor. It emits now formatted JSON.)

What do you think? Do you have any intention to merge this into the original project? I used C# 7 features heavily, but as far as I know mono supports it already. (But you may consider NET Core 2.0. I think, that's the future of cross-platform development.)

I gladly help you with developing the project if you choose so because it can become a neat tool. As a matter of fact, it is like that already. It needs some code cleanup/organization and there are some glitches in the model/code generation that should be fixed.

parsable -> scanner: cleanup, performance optimization
parserbase fixes
unix style line breaks
@masonwheeler
Copy link

17x speedup. Very nice!

@christophevg
Copy link
Owner

Hi Adam,

you have been busy :-) Great, it's always a nice surprise when people appreciate some thing you have been working on and take it for a (big) spin.

Regarding the pull request - after a very quick browse: those are two very big commits and they will need some love to get them into the master tree. Do give me some time and I'll dig into it to see how we can make this work.

To be continued!
Christophe

@adams85
Copy link
Author

adams85 commented Oct 2, 2017

Okay, I hope you'll find it useful! Just let me know if you have some questions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants