LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2023, 01:46 AM   #1
ajiten
Member
 
Registered: Jun 2023
Posts: 375

Rep: Reputation: 4
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.

Last edited by ajiten; 07-05-2023 at 01:48 AM.
 
Old 07-05-2023, 02:11 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
flex is written in c, jflex written in java. Otherwise google is your friend.
https://en.wikipedia.org/wiki/Compar...ser_generators
 
Old 07-05-2023, 05:59 AM   #3
ajiten
Member
 
Registered: Jun 2023
Posts: 375

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by pan64 View Post
flex is written in c, jflex written in java. Otherwise google is your friend.
https://en.wikipedia.org/wiki/Compar...ser_generators
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?
 
Old 07-05-2023, 06:25 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
To answer the original question: certainly not.
 
1 members found this post helpful.
Old 07-05-2023, 07:52 AM   #5
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,604

Rep: Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547Reputation: 2547

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.

 
1 members found this post helpful.
Old 07-05-2023, 07:52 AM   #6
ajiten
Member
 
Registered: Jun 2023
Posts: 375

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by NevemTeve View Post
To answer the original question: certainly not.
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.
 
Old 07-05-2023, 08:32 AM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,782

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by ajiten View Post
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.
Um, have you not actually taken the course you're about to be teaching? I believe misread the use of the word "trainer" here. EDIT2: or not?

Regardless, following suggestion still applies:

Why don't you try to figure this out based on the definition of a lexer and tell us where you get stuck.

Last edited by ntubski; 07-10-2023 at 07:22 AM. Reason: I likely misunderstood intended meaning of "trainer". Or not?
 
Old 07-05-2023, 08:37 AM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
A lexer is an executable. You want an example of how it doesn’t matter what language an executable is compiled from?

Not to be rude, but this is something you should have thought about before asking.

EDIT: nevertheless, I found you an example. The Iexer is written in Java, and it’s used to analyze a program written in Kotlin.

http://db.science.uoit.ca/teaching/c...3_antlr_lexer/

Last edited by dugan; 07-09-2023 at 08:18 PM.
 
Old 07-05-2023, 09:13 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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.

Last edited by NevemTeve; 07-05-2023 at 09:19 AM.
 
Old 07-05-2023, 09:28 AM   #10
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

Rep: Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942Reputation: 3942
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."
 
Old 07-05-2023, 03:39 PM   #11
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,782

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by NevemTeve View Post
Note: I guess the OP uses word 'trainer' for 'beginner',
Oh, this makes sense actually. "Trainer" as in "one who is being trained", not "one who is doing the training of others" as I read it first.
 
Old 07-09-2023, 08:05 PM   #12
ajiten
Member
 
Registered: Jun 2023
Posts: 375

Original Poster
Rep: Reputation: 4
Quote:
Originally Posted by NevemTeve View Post
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.

Last edited by ajiten; 07-09-2023 at 08:12 PM.
 
Old 07-09-2023, 11:18 PM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
That is laudable.

Last edited by NevemTeve; 07-10-2023 at 01:21 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to post lexer file related issues. ajiten Programming 5 07-04-2023 02:06 AM
LXer: Singapore's prime minister releases source code for his hand-coded Sudoku-solver LXer Syndicated Linux News 0 05-05-2015 11:03 PM
how to compile a new source coded kernel with android? xlu2000 Linux - Distributions 0 05-19-2013 03:44 AM
mplayer [mpeg4 @ 0x861f2f0]vop not coded? GT_Onizuka Linux - Software 6 05-01-2004 10:07 AM
Color Coded Vim podollb Linux - Software 5 10-16-2003 04:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration