Has anybody used Lex and Yacc to write compiler/interpreter of their own. Is there any popular language/script whose compiler source was generated using lex and yacc?
-
I am faced with a problem where I have to design a VM environment. Obviously I need constructs that will be valid in this VM environment. These constructs form my small language which will run on this VM environment. I was wondering if I should write my own compiler for my language and convert it into bytecodes and have then interpreter of my own. Or I should use Lex and Yacc to atleast create well structured source code generation for my compiler and then I can use headers to write my vm interpretor too. Is there any popular language compiler/interpretor sources of which have been generated by lex and yacc tool. If there is some other tool out there just for this kind of requirement, please let me know. Any suggestions will be welcome. Thanks -Deepak
-
Answer:
uses flex and bison (improved versions of lex and yacc): http://books.google.ca/books?id=eMHHfB7SLgsC&lpg=PA47&ots=u0oDZHAdHU&dq=mysql+lex+yacc&pg=PA47#v=onepage&q=mysql%20lex%20yacc&f=false I have also written examples of flex/bison based parsers; look at the .l and .y files in these projects: http://telegraphics.com.au/svn/exprparser/trunk/ (simple example of numeric expressions) http://telegraphics.com.au/svn/dpa/trunk/nova/ (DG Nova assembly language) http://telegraphics.com.au/svn/dpa/trunk/pdp8/ (DEC PDP-8 assembly language) http://telegraphics.com.au/svn/filterfoundry/trunk/ (Adobe Filter Factory expressions)
Toby Thain at Quora Visit the source
Other answers
Lots of tools/obscure compilers have been built with Lex and Yacc; that was the point. But your question is inappropriate. People use Lex and Yacc to support building a *parser*. One needs completely different tools to handle the rest of the compiler (semantic analysis, optimization, code generator) Such tools (attribute grammars, instruction-code generators such as Twig, transformations) are used pretty rarely; it seems that many compiler-builders don't know about, don't want, or can't build the infrastructure to support them, so the back end of compilers tends to be a lot more ad hoc/procedural. That's too bad, because the back end is more complex and typically a lot larger than the parser part. (See my essay http://www.semdesigns.com/products/DMS/LifeAfterParsing.html?Home=DMSToolkit for more detail; I've made this point often enough to not repeat it here).
Ira Baxter
I have used Lex & Yacc (actually flex and bison!) a few years ago to convert COBOL to C. This can be best termed as a 'translator', rather then a 'compiler' - but in essence, they are same. The lex file is 27kb and the yacc file is 82kb. Considering the fact that COBOL is a verbose language with many verbs & variations, IMHO using lex/yacc allowed completing the task comfortably.
Rajiv Bhagwat
PHP uses Lex and Yacc. See Zend/zend_language_scanner.l and Zend/zend_language_parser.y.
Seo Sanghyeon
I have used lex and yacc to make a parser and IMHO it is a pain in the ass for which you'd have to have a very good reason to get involved. If you want to write a parser quick in a hurry, I recommend LPEG: http://www.inf.puc-rio.br/~roberto/lpeg/
Michael Fox
Related Q & A:
- What is the simplest ajax upload plugin or script to be used with wordpress?Best solution by WordPress
- How to Implement Gateway Service something similar to Oracle API gateway Using Java and Java based Open Source frameworks only?Best solution by Quora
- How to write Windows registry script?Best solution by forums.codeguru.com
- how can I write this shell script in python?Best solution by Stack Overflow
- Has anybody ever used ultraviolet paint?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.