Answer the question
In order to leave comments, you need to log in
Code recognition, state machine, lexical analyzer and other buzzwords?
I have very vague ideas about how to solve my problem. There is some text editor, you need to make sure that all elements of this code are recognized by this editor. This is implemented in any framework. The framework can determine where a class, for example, starts and where it ends. On the forums, I was told about the finite state machine, and I still did not understand how it could work with this particular task. Since I see that this problem has already been solved in many projects, there is an assumption that somewhere there is a ready-made example.
Answer the question
In order to leave comments, you need to log in
If you specifically need the simplest syntax highlighting (as in your html example), then lexical analysis is enough for you . You need to select tokens in the text, and depending on the type of token, choose a color for highlighting. In different environments, this will be implemented differently - in Sublime, this is done through a special. a language for describing finite automata, regular expressions can be used in other editors, a lexical analyzer is written in general-purpose PL in Visual Studio.
Look at these tools, C/C++: Flex , ANTLR for dotnet languages, FsLex is also good (although it has F# syntax).
If you need more complex analysis (for example, substitutions depending on the context), see the answerDmitry Makarov is already a syntactic analysis, the next stage after the lexical one. Said Yacc is a classic Lex/Flex pair. There is also a more modern analogue compatible with Yacc - Bison . For dotnet, I can advise the same ANTLR, and FsYacc in pair with FsLex.
I understand you here: Parsing and, for example, here: yacc
On the forums, I was told about the finite state machine, and I still did not understand how it could work with this particular task.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question