Are all Parsers made with yacc or bison (and lex/flex)? [closed]
Asked Answered
A

3

5

I think Bison and Yacc are very often used for parsing grammars of programming languages. (and lex/flex for tokenizing...)

My Question is: Are all compilers made with this tools or are there people who write their parsers from scratch? (I do it mostly without "compiler compilers", but I know them)

Is it "luctrative" to build parsers without these tools?

Are there alternatives for yacc/bison and lex/flex that are more "open" and not so strict. Are libraries for C existing to do that for me (the parsing)? Is there another option to build parsers without yacc but also not to write it from scratch?

Best regards Lukas

Arachnoid answered 27/12, 2015 at 0:13 Comment(4)
There are lots of parser generators out there. All of them have been used for something and probably most of them continue to be used.. Sometimes for a very simple syntax it is just easier to parse a domain specific language (often a configuration file of sorts) by hand written code.Wylen
Nope. Consider JavaCC and ANTLR. Some people roll their own parser generators.Riband
There are lots of parser generators out there. Here's a partial list: en.wikipedia.org/wiki/Comparison_of_parser_generators.Crissy
SO closers: I don't think this question asked for resource or a recommendation. He is asking about what is the state of the practice. I think your close request inappropriate. (Vote to re-open).Crissy
S
3

Are all Parsers made with yacc or bison (and lex/flex)?

No. For example, GCC don't use them.

c - Are GCC and Clang parsers really handwritten? - Stack Overflow

Sruti answered 27/12, 2015 at 0:17 Comment(0)
E
3

Many high performance parsers for big ticket products, like C++ compilers are handwritten, or at least pre generated by a tool. and then modified by hand.

Unfortunately, this significantly increases maintenance effort and introduces a much larger possibility for bugs.

A well written grammar and a well chosen parser generator tool can yield performance almost as good, or in many cases, as good as a handwritten parser.

For this reason, a parser generator is preferable if you don't have the development and testing resources that a larger organization might.

There are many parsing and lexing tools available, both general and specialized depending on platform, parser type (LLk, LALR(1), etc), and output language.

There are also general parsing engines like Programmar that take an input grammar and interpret it at runtime in order to allow an app to analyze inputs that conform to that grammar.

Gold Parser is a free and easy to use LALR(1) parser generator that runs on Windows operating systems.

The Spirit Framework ships with the C++ Boost library and uses a combination of preprocessing macros and clever generics to allow the developer to produce a grammar in a C++ file that is compiled by the C++ compiler itself despite looking quite a bit like a standard EBNF grammar file. Naturally, its output targets C++

Elk is a toolkit for creating C++ based GLR parsers. GLR is a particularly efficient and flexible type of parser often used for complex grammars, like C++ itself.

There are many other tools out there, including ANTLR and ACCENT, each of which have their own strengths and weaknesses.

Electromotor answered 27/12, 2015 at 0:55 Comment(1)
See #6319586 for a discussion about using grammars effectively for complex languages such as C++.Crissy
E
3

In grad school I wrote a C compiler using an LRR parser that was built from the ground up -- first generated the table and then wrote an engine to use it.

This was not hard to do and is quite well explained in the literature. I suggest you read the dragon book if you want to learn more.

https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools

Exotic answered 27/12, 2015 at 1:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.