How can I use a JFlex lexer with a JavaCC parser?

I am trying to learn how to use JavaCC to write a parser.

I already created a lexer using JFlex and it returns a list of tokens. Each token is its own class.

I write production rules, but, for example, I cannot write ";" because it will not receive a semicolon, but instead an instance of TokenSemicolon?

What can I do?

Also, I got confused in TokenMangager, etc. I already have lexer and my own list of compatible token classes. What is it?

Please help, because I am very confused.

+4
source share
1 answer

You ask two related questions:

" ?" . , : " ?"

. JavaCC . , Token. .

  • JavaCC . JavaCC , .jj. , JFlex. .
  • . USER_TOKEN_MANAGER=true. JavaCC Java- TokenManager. , , . , , .

" ?"

.

  • JFlex JavaCC. JavaCC , JFlex, , (.. Token.)
  • . JavaCC USER_TOKEN_MANAGER=true , JFlex TokenManager.
  • JFlex , JavaCC. , , , . USER_TOKEN_MANAGER=true. : class FooLexer extends FooJLexLexer implements TokenManager { ...put constructors here... }

3 , , TokenManager. , Token.

2, , , .

TokenManager tm = new AdaptJFlexLexerToJavaCC( jflexLexer ) ;
FooParser p = new FooParser( tm ) ;

3 . , .

3 , JFlex, 1. JFlex JavaCC, , , , . , JFlex, JavaCC , - A / B.

, , JavaCC , Token .kind. , FooConstants.

+2

Source: https://habr.com/ru/post/1612642/


All Articles