Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix Flex Regex for Multi-Line Comments

I am making a Lexical Analyzer using Flex on Unix. If you've ever used it before you know that you mainly just define the regex for the tokens of whatever language you are writing the Lexical Analyzer for. I am stuck on the final part. I need the correct Regex for multi-line comments that allows something like

/* This is a comment \*/

but also allows

/* This **** //// is another type of comment */

Can anyone help with this?

like image 248
LunaCodeGirl Avatar asked Jan 21 '11 06:01

LunaCodeGirl


1 Answers

You don't match C style comments with a simple regular expression in Flex; they require a more complex matching method based on start states. The Flex FAQ says how (well, they do for the /*...*/ form; handling the other form in just the <INITIAL> state should be simple).

like image 114
Donal Fellows Avatar answered Oct 11 '22 14:10

Donal Fellows