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
2
votes
1 answer

Grammar-Kit: how to handle comment tokens

From the documentation provided for grammar-kit, I cannot figure out how I am supposed to correctly handle something like comments. My lexer currently returns TokenType.WHITE_SPACE for any comment blocks, but then no unique IElementType is generated…
FatalCatharsis
  • 3,407
  • 5
  • 44
  • 74
2
votes
1 answer

CUP parser returns syntax error for a valid input

I'm trying to write a very simple parser. I'm using JFlex with Java CUP. Here's my code: LEX file: import java_cup.runtime.*; %% %class Lexer %line %column %cup %{ …
Plex
  • 21
  • 1
  • 2
2
votes
3 answers

Java regex: First three digits are not 666

I need to create a regex that returns true if the first three digits are not 666. Here are some examples: 66600abc - false 606asdfnh - true 600asdfasdf -true I have tried this but I don't get the desired…
Pravin Tukadiya
  • 489
  • 4
  • 20
2
votes
1 answer

JFlex with CUP compile errors

I am trying to run an example provided by CUP: Parsing directly to XML. I stored the 'Minijava Grammar' in a file named minijava.cup and the scanner into a file named xml.flex. I ran JFlex to obtain Lexer.java from the xml.flex file. After that I…
Dragos Geornoiu
  • 527
  • 2
  • 8
  • 17
2
votes
1 answer

Is it possible to test a lexer made in JFlex without writing a parser?

I am beginning to use JFlex and I want to try to write a lexer first, and then move onto the parser. However, it seems like there is no way to test your JFlex lexer without writing a parser in CUP as well. All I want to do is write a lexer, give it…
John Smith
  • 21
  • 2
2
votes
0 answers

Is it good choice to use JFlex/flex to write a lexer for YAML?

I'm trying to use JFlex to write a lexer for YAML, but found it hard, since: Indentation is sensitive in YAML There are multiline string like: longstr: > This is multiline line is hard to implement. I don't know how to determine and return…
Freewind
  • 193,756
  • 157
  • 432
  • 708
2
votes
1 answer

What's wrong with this simplest jflex code?

I'm learning jflex, and wrote a simplest jflex code, which makes a single character #: import com.intellij.lexer.FlexLexer; import com.intellij.psi.tree.IElementType; %% %class PubspecLexer %implements FlexLexer %unicode %type…
Freewind
  • 193,756
  • 157
  • 432
  • 708
2
votes
3 answers

Parse EOF token in CUP

I'm having trouble making my CUP parser parse the EOF token. I read in the documentation that using the %cup flag in my Jflex code implies that there is something present like this: %eofval{ return new…
Christophe De Troyer
  • 2,852
  • 3
  • 30
  • 47
2
votes
1 answer

Combine grammar infix postfix prefix

I'm writing some kind of calculator using Jflex and CUP, I was able to make my grammar for infix, postfix and prefix notation as seen below, they works well if I just use each grammar and don't combine them. The problem now is how can I combine…
2
votes
1 answer

JFlex - Regex for "Arrow"

So if I wanted to key in an Arrow character, -->, via JFlex's regex, I'd figure it would just be the string "-->". However, if I attempt this, I always get a Could not match Input error. "-->" {} Doesn't work. Neither does a combination of…
Skyl3lazer
  • 368
  • 2
  • 10
2
votes
2 answers

Is there a jflex specification of java string literals somewhere?

And by string literals I mean those containing \123-like characters too. I've written something but I don't know if it's perfect: { \" { yybegin(YYINITIAL); return new…
Paul Brauner
  • 21
  • 1
  • 3
2
votes
1 answer

Jflex Regular expression

I am trying to write a .flex file that recognises a string literal,which is a sequence of characters surrounded by double quotes. No escape characters, but I just cant get it to identify them, This is my latest attempt. \"(\\.|[^"])*\" Any…
user2904478
  • 27
  • 1
  • 4
2
votes
1 answer

Misbehaving JFlex rules - wrong rule matched

I'm writing a (simple?) JFlex tokenizer whose goal is to take a string, and tease apart the chunks that are in Chinese (or rather using the Han script), and the parts that are in a Latin script. The tokenizer is applied to brand names, and in my use…
RuslanD
  • 295
  • 3
  • 12
2
votes
1 answer

JFlex and accented characters

I need to create a parser with JFlex to extract all words from an input file, including those with accented characters like á, é, í, ó, ú, ñ, ... My problem is that even setting all files with UTF8 encoding and the %unicode tag I can't make it…
Sheol
  • 164
  • 1
  • 3
  • 13
2
votes
0 answers

JFlex successor

JFlex is quite old scanner generator; last version (1.4.3) has been released in 2009, and v1.5 is on trunk for a long time. I wonder if someone has found good successor and replacement for JFLex? That would be a scanner generator that can process…
igr
  • 10,199
  • 13
  • 65
  • 111
1 2
3
13 14