Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.
/ lex-java Public archive

Java SE 17 language Flex description

License

Notifications You must be signed in to change notification settings

agcom/lex-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ Archived in favor of agcom/yacc-java. ⚠️

Lex Java

Java SE 17 language Flex description; was made as a homework for a compiler design principles college course.

For the project's shortcomings, see the issues; if you found one that isn't acknowledged, submit it as a new issue.

Simple build & run

On a Linux operating system, clone the repository and open it in a terminal; then issue the following commands to run the lexical analyzer on Example.java.

flex desc.l && \
gcc lex.yy.c -w && \
cat Example.java | ./a.out

The side effect free version of the above code:

out=$(mktemp) && \
flex -t desc.l | \
gcc -w -x c -o $out - && \
cat Example.java | $out

Resources

Embedding

If you want to use this as embedded, you probably need to expand some rules (and definitions); e.g. 👇

...
ReservedKeyword {AbstractKeyword}|{ContinueKeyword}|{ForKeyword}|...
AbstractKeyword abstract
ContinueKeyword continue
ForKeyword for
...
%%
...
{AbstractKeyword} {return ABSTRACT;}
{ContinueKeyword} {return CONTINUE;}
{ForKeyword} {return FOR;}
...
%%
...

instead of 👇

...
ReservedKeyword abstract|continue|for|...
...
%%
...
{ReservedKeyword} printlnCurrentToken();
...
%%
...

The focus of this project is on its standard text output; token names (first word of each output line) are probable terminals of a grammar for Java 17 language.

Therefore, for example, it's normal to collapse all keywords in one rule, to save some ink and energy.

About

Java SE 17 language Flex description

Topics

Resources

License

Stars

Watchers

Forks