Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lexical Analysis [closed]

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.

like image 890
Sadique Avatar asked Oct 24 '25 15:10

Sadique


1 Answers

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.

like image 199
Mat Avatar answered Oct 27 '25 03:10

Mat