I have tried to understand your code but it is not complete code . from where I will get full code for understanding .
Those are examples, but you probably are already missing the very foundations. There are lots of books and lectures on compiler construction, one of the most famous ones is the script for the Compiler Construction course from Niklaus Wirth he tought on the ETH Zürich:
https://people.inf.ethz.ch/wirth/CompilerConstruction/CompilerConstruction1.pdfIt's quite theoretical, if you want something more hands on, there have been other suggestions here. At it's core a compiler consists of three quite distinct parts, the lexer/tokenizer, which is based on regular expressions, then the parse which is using a stack based state machine (Stack Automaton) for creating the abstract syntax tree, and then the backend, which is highly dependent on the target for your language.
In practice you usually do not need to construct the formal automatons, this is what I was trying to show with these examples. Instead of building a powerset automaton, you usually just construct some state machines that you iterate through to simulate such an automaton. Instead of building a stack automaton for the parsing you can make use of the stack of recursive calls to build a recursive descent parser for LL(1) languages. This does not mean you don't need the theory, because you need to know what you can and cannot express in your language. For example for tokenization, you are bound to what regex (and by this I mean true regex, not this backtracking stuff that modern regex engines do) is capable off (keyword: pumping lemma). For the parser, it really helps to write down the language formally and to check if it is left recursive, right recursive and if it can be resolved with a lookahead of 1.
What you can also look at is the
Gold Parsing system. I've written a few gold engines (in
Pascal,
Typescript and Haskell) and wrote down (including some of the theory) how it works and how to build your own:
https://github.com/Warfley/GoldEngines/blob/master/docs/index.mdAlso I've built some tooling for VSCode to not have to use the awful editor that is shipped with GOLD:
https://github.com/Warfley/gold-parser-toolsBut either way I recommend to first start looking at least a bit at the theory, it will make things much easier. Once you know the basics, writing a small parser for a simple language from scratch only takes like a few days.