Skip to content

Rabrg/jlex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

jlex

A lexical analyzer for Java source code written in Python

Example

Code

from jlex.lexer import lex_source_file
from jlex.type import Type

tokens = lex_source_file('Example.java')

for token in tokens:
    if token.type not in [Type.SPACE, Type.NEW_LINE]:
        print(token)

Input

public class Example {

    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

Output

Type Value
PUBLIC public
CLASS class
IDENTIFIER Example
OPEN_CURLY_BRACE {
PUBLIC public
STATIC static
VOID void
IDENTIFIER main
OPEN_PAREN (
STRING String
OPEN_BRACE [
CLOSE_BRACE ]
IDENTIFIER args
CLOSE_PAREN )
OPEN_CURLY_BRACE {
IDENTIFIER System
POINT .
IDENTIFIER out
POINT .
IDENTIFIER println
OPEN_PAREN (
STRING_LITERAL "Hello world!"
CLOSE_PAREN )
SEMICOLON ;
CLOSE_CURLY_BRACE }
CLOSE_CURLY_BRACE }

About

A lexical analyzer for Java source code written in Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages