Lexical analysis

My goal is to make C. syntax very simple and simple. (Not a complete compiler, but just a basic program that takes the source code as "Enter" and prints the code that displays errors). I want to use C ++ as the language for this.

Can someone guide me to write a regex in 'C ++' for the following:

  • Appointment
  • For
  • Switch

Any details / suggestions / recommendations will be further appreciated.

+3
source share
5 answers

I do not think that you can Conly parse using regular expressions. You will need to start learning lexers, parsers, grammar, etc.

: - .

C grammars yacc/lex.

+6
+3

clang. GitHub.

+2

+1

To recognize C operators, lexical analysis is not enough, because lexers work at the character level. In addition to the C lexer, you need a C parser that will parse the source code. LRSTAR Parser Generator provides a C project to help you get started.

0
source

All Articles