I wrote a parser grammar in ANTLR4 which looks like this:
parser grammar IFJ23;
tokens {
Identifier, Type,
LeftBracket, RightBracket,
LeftCurlyBracket, RightCurlyBracket,
Semicolon, Colon, Arrow, Comma,
/** Keywords */
FunctionKeyword
}
swiftFile
: functionDeclaration swiftFile
;
/** Statements */
statement
: declaration Semicolon?
;
statements
: statement statements?
;
codeBlock
: LeftCurlyBracket statements? RightCurlyBracket
;
/** Declarations */
declaration
: functionDeclaration
// | variableDeclaration
;
/** Function declarations */
functionDeclaration
: FunctionKeyword Identifier functionSignature functionBody
;
functionSignature
: parameterClause functionResult?
;
functionBody
: codeBlock
;
parameterClause
: LeftBracket RightBracket
| LeftBracket parameterList RightBracket
;
functionResult
: Arrow Type
;
parameterList
: parameter
| parameter Comma parameterList
;
parameter
: externalParameterName? localParameterName typeAnnotation
;
externalParameterName
: Identifier
;
localParameterName
: Identifier
;
typeAnnotation
: Colon Type
;
Now, the problem I am facing is that I already have a functional lexer that is not written in ANTLR4. It's written in C and it generates a list of tokens for a file.
Is there a way to somehow make ANTLR4 accept this token list as input and try to generate a parse tree?
I would also need to match the tokens in the Tokens {} list with their respective token types generated from my lexer.