Flex and Bison tools [closed] - c++

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want know which is best whether compiler design using either tools like Flex & Bison or C/C++.
Because I've heard that developing with tools is not worthy at all. I'm a beginner to compiler design so I need clarification about this. And other thing that I want to ask you is which of those two ways as I said above expected by a company in compiler design. Please help me!!!

This depends on complexity of your syntax you want to parse. It is not hard to implement simple grammar by hand but without experience it is hard for complex grammars.
If you don't have any experience with lexers and parsers, it would be better to start with other tools not using LR (LALR) parser but LL because they are much more intuitive for starters.
I have very good experience with ANTLR. It generates Java code but it has also C++ backend and nice grammar development tools (ANTLRWorks).
So my advice is none of those two you have chosen but start with ANTLR.

If you are not constrained by C/C++, I would recommend Eclipse Xtext. It is simple to learn, has great documentation, and has the added benefit of automatically generating an Eclipse-based IDE that supports your language, with syntax-highlighting, content assist, and other powerful features.
Xtext has its own programming language (Xtend) which is a more powerful version of Java (in a way, it is similar to Scala). Xtext uses ANTLR internally.

Related

Can OOP be used in Embedded C? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm very new to software development and really loving it.
Currently, my work involves C++ programming in an OOP implementation (basically, the guys who started the framework for the software used OOP approach in everything). I jumped in and inherited what's already there.
Hobby-wise, I would like to develop a framework also for an embedded application.
Basically programming Embedded C on a microcontroller.
Is it wise to do the framework in OOP approach also?
I was thinking it is more organized.
Thanks in advance for the answers!
I would say that it depends on your microcontroller specifications (and how many resources you have).
In my experience (as Olaf says it's a subjective opinion):
OOP approach is usually clearer, avoids some mistakes for common variables and allows other person to use the framework without a painful learning process.
However... it usually require more resources as you need to encapsulate everything and that leads into more functions.
So... it depends...
It depends on your Embedded applicaton.
In some scenarios some c++ features costlier.
for e.g. run time polymorphism. .
Hope this link helps.!
http://www.embedded.com/design/programming-languages-and-tools/4424383/A-guide-to-C--for-C-programmers

Is the Go programming language replacing C++? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have read on some blogs that Go is a better system programming language and is going to replace C/C++. I am currently learning C++. So, I was wondering whether I should continue learning C++ or move to Go?
Go is designed for reliable, fast online services. It's the recommended language of Google App Engine. It does have general feature parity with C, plus additional scalability features. Perhaps, one day, it will be adopted for embedded programming and client-side applications, but that has yet to happen.
C is used in many, many application domains. No other language approaches its breadth of use. As a first language, though, it won't help you develop good habits.
C++ is a multi-paradigm language. It supports deep, generic metaprogramming. Many users of C++ are really using "embedded domain-specific languages" (EDSLs) where a library provides functionality defined within the C++ grammar. Go does not attempt to provide this depth, which is a Pandora's box of complexity.

I want to include a scripting language in C++ project. Lua vs Bison/Yacc [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to implement a scripting language in my app. Just for controlling some behavior, defining rules etc.
I haven't found a reason to use Lua over bison/yacc or vice-versa. What are advantages and disadvantages of these tools?
From implementation point Lua seems to be much easier to implement while yacc/bison requires to learn to write parser markup but then I have a standalone parser. Other than that what are the differences?
They're completely different things, and not really comparable. Lua is an (embeddable) scripting language, Bison/yacc something you could write a lexer and parser for a language with.
With Bison/Yacc, you would still have to implement the actual execution engine (VM, whatever) for your scripting language.
So if you want a scripting language embedded in your app, lua gives you one "out of the box". Bison/yacc give you (some of ) the tools for implementing one.
If you do want a parser for some reason, you can use bison/yacc, or you might want to look at lpeg in Lua, depending on your use-case.

C++ parser generator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I'm writing my own scripting language and I need a software tool which generates C++ code for parsing my language. I need a lexical analyzer and a parser generator which generates C++ code. It would be nice for me to be able also to generate a Visual C++ 2010 project. Suggestions?
http://en.wikipedia.org/wiki/Comparison_of_parser_generators
for C/C++: http://epaperpress.com/lexandyacc/
Or look at: Boost.Spirit:
"Spirit is a set of C++ libraries for parsing and output generation
implemented as Domain Specific Embedded Languages (DSEL) using
Expression templates and Template Meta-Programming."
Dou you really need new language? maybe it would be better to use some well known like Lua, Python?
Try with Flex and Bison. They are good lexical analizers and parser generator usefull to define new languages.
http://en.wikipedia.org/wiki/Flex_lexical_analyser
It's an old question but still might be relevant: since I was unhappy with the existing options, I recently wrote a template c++ parser generator which doesn't need any external tools (you include a header and define the grammar directly in the c++ source). It uses readable PEG grammars so there is no need for a separate lexing step. You can check it out on Github.
You have two choices: whether you create your own parser by creating an AST (abstract syntax tree), then it will be a good exercise for you but it's very long and hard to implement. Or you can use an open source solution such the ANTLR parser generator which has a grammar for C/C++ as well as the preprocessor. I've never used it so I can't say how complete its parsing of C++ is going to be. Then If you are in hurry and you want to create a good parser, you'd better use the second solution

BNF grammar test case generation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Does anyone have any experience with a tool that generates test strings from a BNF grammar that could then be fed into a unit test?
I don't have an answer to the tool question, but I will say it is fairly easy in any text processing language (perl/python/etc) to randomly generate sentences from a BNF grammar, and slightly more verbose in a bigger language (Java/C/etc), but it shouldn't be too hard to roll your own.
The problem with this, of course, is that it can only generate strings in the grammar, and unless your grammar is very simple, the test space is infinitely large.
I've done exactly as hazzen commented (using an embedded DSL in a scripting language). It was a mildly interesting exercise, but except for the most basic tests of e.g. parsing, it wasn't terribly useful. Most of my most interesting tests have to do with more sophisticated relationships than one can easily express in BNF (or any other context-free grammar).
If, say, you're developing a compiler, then you likely have an abstract syntax tree datatype. If so, then you could write a function to generate an random AST -- with that, you can print it to a string and feed that to your unit test. It's guaranteed to be a valid program this way, since you started with your AST.
If I were writing a compiler in Haskell or ML, this is what I would do, using QuickCheck.
Gramtest is one such tool that can generate strings from arbitrary user defined BNF grammars. You can read more details about the algorithm behind Gramtest here and some practical tips on the tool are available here.