Questions tagged [jflex]

JFlex — The Fast Scanner Generator for Java. JFlex is a flex-like lexer generator for Java.

JFlex is a lexical analyzer generator (also known as scanner generator) for Java, written in Java. It is also a rewrite of the very useful tool JLex which was developed by Elliot Berk at Princeton University. As Vern Paxson states for his C/C++ tool flex: They do not share any code though.

JFlex is designed to work together with the LALR parser generator CUP by Scott Hudson, and the Java modification of Berkeley Yacc BYacc/J by Bob Jamison. It can also be used together with other parser generators like ANTLR or as a standalone tool.

Related Links:

196 questions
14
votes
4 answers

What is an example of a lexical error and is it possible that a language has no lexical errors?

for our compiler theory class, we are tasked with creating a simple interpreter for our own designed programming language. I am using jflex and cup as my generators but i'm a bit stuck with what a lexical error is. Also, is it recommended that i use…
cesar
  • 8,944
  • 12
  • 46
  • 59
11
votes
1 answer

Case insensitive JFlex regex

How do you achieve case insensitive regular expression patterns in JFlex. Using the standard (?i:) notation does not seem to work. For example: To match the case insensitive word "class", the regex would be (?i:class). But this doesn't work in a…
ChrisM
  • 235
  • 5
  • 13
10
votes
3 answers

What are the disadvantages of using ANTLR compared to Flex/Bison?

I've worked on Flex, Bison few years ago during my undergraduate studies. However, I don't remember much about it now. Recently, I have come to hear about ANTLR. Would you recommend that I learn ANTLR or better to brush up Flex/Bison? Does ANTLR…
user855
  • 19,048
  • 38
  • 98
  • 162
8
votes
1 answer

BNF Rule Syntax Highlighting for Custom Language

I'm trying to develop a custom language plugin for IntelliJ using the Grammar-Kit plugin. I am easily able to provide syntax highlighting for tokens defined, but I cannot figure out how to highlight at the element or token-parent level. Here's a…
pyrospade
  • 7,870
  • 4
  • 36
  • 52
7
votes
0 answers

Convert my .g4 to .flex and .bnf for IDEA syntax highlighter

I have never used JFlex before, and I have no idea how it works. Basically, I've built a runtime for a scheme-esque language in Java, and the parser I have for it was generated using Antlr 4, so I have a .g4 file, which looks like this: program:…
michaelsnowden
  • 6,031
  • 2
  • 38
  • 83
7
votes
3 answers

JFlex match nested comments as one token

In Mathematica a comment starts with (* and ends with *) and comments can be nested. My current approach of scanning a comment with JFlex contains the following code %xstate IN_COMMENT "(*" { yypushstate(IN_COMMENT); return…
halirutan
  • 4,281
  • 18
  • 44
6
votes
1 answer

Keeping track of state in JFlex

I'm writing a custom flex file to generate a lexer for use with JSyntaxpane. The custom language I need to lex has different states that can be embedded into each other in a kind of stack. I.E you could be writing an expression that has a single…
Tom Martin
  • 2,498
  • 3
  • 29
  • 37
6
votes
2 answers

jFlex error: class throws java.io.IOException

I have written a very simple file with specification shown below to to tokenize words: %% %class Lexer %unicode WORD = [^\r\n\t ] %% {WORD} {System.out.println("Word is:"+yytext());} . {System.out.println("Bad character: "+…
Aman Deep Gautam
  • 8,091
  • 21
  • 74
  • 130
6
votes
1 answer

In CUP: How to make something optional to parse?

PROC_DECL -> "proc" [ "ret" TYPE ] NAME "(" [ PARAM_DECL { "," PARAM_DECL } ] ")" "{" { DECL } { STMT } "}" This is the grammar for a Procedure declaration. How do you say that the "ret" TYPE is optional…
magnudae
  • 1,272
  • 2
  • 13
  • 32
5
votes
1 answer

Parse tree generation with Java CUP

I am using CUP with JFlex to validate expression syntax. I have the basic functionality working: I can tell if an expression is valid or not. Next step is to implement simple arithmetic operations, such as "add 1". For example, if my expression is…
user443854
  • 7,096
  • 13
  • 48
  • 63
5
votes
2 answers

Moving to Maven from GNUMake

I've been a long time user of the Make build system, but I have decided to begin learning the Maven build system. While I've read through most of the online docs, none seem to give me the analogies I'm looking for. I understand the system's…
dcolish
  • 22,727
  • 1
  • 24
  • 25
5
votes
1 answer

JFlex Lexer. Multiline strings

I'm trying to parse some language with multiline string literals using JFlex. Examples: ''' this is a valid multiline string literal with 'quoted' word ''' I've created two states: %x IN_QUOTED_STRING %x IN_MULTILINE_QUOTED_STRING and created…
fkorotkov
  • 348
  • 2
  • 13
4
votes
1 answer

How do I use regular expression capturing groups with JFlex?

Although this question is about JFlex, it probably applies to other scanner generators such as lex, flex as well. If I have some rule, how can I create a capturing group in part of that rule and use the result of that captured group as an argument…
Zxaos
  • 7,791
  • 12
  • 47
  • 61
4
votes
1 answer

How can I use a JFlex lexer with JavaCC parser?

I'm trying to learn how to use JavaCC to write a parser. I have already generated a lexer using JFlex, and that returns a list of tokens. Each token is it's own class. I'm writing the production rules, but for instance, I can't write ";" because it…
user2397282
  • 3,798
  • 15
  • 48
  • 94
4
votes
2 answers

Whitespace separation in jflex grammar

Suppose I need simple grammar that describes language like foo 2 bar 21 but not foo1 Using jflex I wrote smt like WORD=[a-zA-Z]+ NUMBER=[0-9]+ WHITE_SPACE_CHAR=[\ \n\r\t\f] %state AFTER_WORD %state AFTER_WORD_SEPARATOR %% {WORD} …
Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132
1
2 3
13 14