Search code examples
parsingcompiler-constructioncompilationconditional-compilation

How a control-statement, array, function (procedure) is compiled by a simple compiler?


I just want to know a simple explanation of how if-else statements, loops, procedures get parsed by a compiler ?

I found it ungoogleable..... :( Please Help me to get into this...!!!


Solution

  • Parsing is a fairly large and somewhat complicated subject. If you're familiar with Python, the Pyparsing module might be a good place to start. It's not a parser itself, but sort of a parser generator.

    Some other well-known parser generators are ANTLR and Lex/Yacc. Pyparsing is simpler (if slower), and it accepts the well-known BNF as its description language. Check out the examples below.

    http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form

    https://github.com/pyparsing/pyparsing

    https://github.com/pyparsing/pyparsing/tree/master/examples