Search code examples
c++cregexvisual-c++compiler-construction

Lexical Analysis


My target is to make a very simple and basic C syntax checker. (Not a full Compiler but just a basic Program which take a source code as Input and would print out the code back showing the errors). I want to use C++ as the language for this.

Can anyone guide me to write regular expression in 'c++' language for the following:

  1. Assignment
  2. For
  3. switch

Any details/suggestions/guidance further would be much appreciated.


Solution

  • I don't think you can parse C with regular expressions alone. You'll need to start looking into lexers, parsers, grammars, etc...

    A good starting point could be this: Quick Starter on Parser Grammars - No Past Experience Required.

    You can find C grammars online for yacc/lex.