Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing source code

Tags:

c

parsing

yacc

lex

I need to parse the source code of different files, each written in a different language, and I would like to do this using C.

To do that, I was thinking of using yacc / lex, but I find them very hard to understand, maybe due to the complete lack of decent documentation (either that, or they really are cryptic).

So my questions are: where can I find some good documentation for yacc / lex, preferably a tutorial style introduction? Or, is there any better way to do this in C? Maybe there's something else I could use instead of yacc / lex, perhaps even written in a different language?

like image 837
rid Avatar asked Dec 19 '25 22:12

rid


2 Answers

yacc and lex are very powerful tools, built around the theories for compiler construction. To be able to fully understand them you probably need some basics in formal languages, automata theory and compiler construction.

The dragon book is a classic on the subject.

like image 144
Anders Abel Avatar answered Dec 22 '25 12:12

Anders Abel


The second half of Kernighan and Pike's The Unix Programming Environment is an extended introduction to programming an interpreter with lex and yacc. The lex coverage is a little light, as they mostly use a custom scanner.

like image 33
luser droog Avatar answered Dec 22 '25 13:12

luser droog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!