D
D
doublench212018-02-26 21:24:27
C++ / C#
doublench21, 2018-02-26 21:24:27

Lexer for highlighting language syntax given by BNF grammar?

Good day.
I wanted to implement syntax highlighting for the language using a lexer for this. The essence is simple, we find a token, we frame it with a set of symbols for a particular color. But the fact is that language tokens are described in BNF, and lex / flex work with regular expressions to write tokens. The question actually is how to build a lexer for the BNF grammar?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2018-02-26
@zagayevskiy

Are you confusing a token with a terminal/non-terminal? Because for lexical analysis and parsing into tokens, a grammar in the form of BNF is not needed. More precisely, it will be very simple - stupidly listing all the tokens.

J
jcmvbkbc, 2018-02-27
@jcmvbkbc

qF5rfVj.png

This grammar is easily reduced to flex regular expressions.
a grammar parser is needed if you are going to highlight language constructs.
Well, in general, there is a bison for this, since you came from flex.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question