Does lexer tool need be coded in the same language, as the source language?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Does lexer tool need be coded in the same language, as the source language?
What makes the need for Jflex, as a lexical analyzer building tool, for the Java language?
Why Flex is not enough for the same task?
Kindly explain with example of a Java language construct being unable to be tokenised using flex.
P.S.: Am a trainer, so please delve into details for the above, as there can be many questions asked for the above, to me.
It just states the lexer algorithm, in a table, for a given compiler; but never states the language in which the lexer is implemented; unless you search the individual compiler.
My question would even then (after searching, for the individual compilers' details) would remain unanswered; i.e.:
Do the lexer need be coded in the same language as the source language?
Flex produces C or C++, which isn't very helpful for a developer who knows Java, but not C or C++ languages.
However, as per its manual, JFlex is not a Java version of Flex, it's a faster version of JLex.
Quote:
Originally Posted by https://jflex.de/manual.html
JFlex was designed to read old JLex specifications unchanged and to generate a scanner which behaves exactly the same as the one generated by JLex with the only difference of being faster.
Both Flex and JLex were inspired by Lex (which used to be proprietary software).
The language a lexer is implemented in is mostly irrelevant (except if it requires a particular VM to run), but they will often be implemented in the same language as the output language because that's a language the authors are comfortable working/developing with.
The original question was: Does lexer tool need be coded in the same language, as the source language?
But, request examples, and theory justifying your answer.
Also, request in which cases, the constraint of the lexer being coded in the source language, is not applicable.
As far as I know, lex is written in C, its source language is lex/C mix, its target language is C; jlex is written in Java, its source language is jlex/Java mix, its target language is Java.
You could write a Java program that has the functionality of lex, also you could write a C program that has the functionality of jlex.
Note: I guess the OP uses word 'trainer' for 'beginner', word 'request' for 'please give' etc.
These tools are designed to produce source-code to be incorporated into your compiler project. It is most convenient for most people for a tool which generates [Java] source-code to itself be written in [Java]. "Dance with the one who brung 'ya."
As far as I know, lex is written in C, its source language is lex/C mix, its target language is C; jlex is written in Java, its source language is jlex/Java mix, its target language is Java.
You could write a Java program that has the functionality of lex, also you could write a C program that has the functionality of jlex.
Note: I guess the OP uses word 'trainer' for 'beginner', word 'request' for 'please give' etc.
Dear sir, am M.Tech.(CSE) from NIT-Warangal, based on 433 AIR in GATE; and had subject of Compiler Design, in that course.
Am a Lecturer now, and very soon, i.e. from today, the classes will start too, for the odd semester.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.