Lexer that recognizes blocked blocks

I want to write a compiler for a language that designates program blocks with spaces, for example, in Python. I prefer to do this in Python, but C ++ is also an option. Is there an open source lexer that can help me do this easily, for example, by creating INDENT and DEDENT identifiers, like Python lexer does? An appropriate parser generator will be a plus.

+5
source share
2 answers

LEPL is pure Python and supports off-line parsing.

+4
source

- lex, :

^[ \t]+              { int new_indent = count_indent(yytext);
                       if (new_indent > current_indent) {
                          current_indent = new_indent;
                          return INDENT;
                       } else if (new_indent < current_indent) {
                          current_indent = new_indent;
                          return DEDENT;
                       }
                       /* Else do nothing, and this way
                          you can essentially treat INDENT and DEDENT
                          as opening and closing braces. */
                     }

, , DEDENT , .

count_indent .

lexer/parser Python, , , lex/flex, yacc/bison, . C ++ .

+1

All Articles