Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 3rd, 2011, 08:32 AM
minor28 minor28 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sweden
Posts: 259 minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 1 m 26 sec
Reputation Power: 19
MPLex problem

Could anyone help me with a MPLex problem.

I want to find comment blocks like
Code:
/*++ BUILD Version: 0091     Increment this if a change has global effects
Copyright (c) Microsoft Corporation. All rights reserved.
*/

and #define statements with two or more lines like
Code:
#define FILE_GENERIC_READ	(STANDARD_RIGHTS_READ |\
							FILE_READ_DATA |\
							FILE_READ_ATTRIBUTES |\
							FILE_READ_EA |\
							SYNCHRONIZE)

in c++ headers.

The comment blocks is OK but not #define blocks. This is
so far I have come.
Code:
%COMMENT
%DEFINE

W	[0-9a-zA-Z_]
S	[ \t\v\n\f\r]

%%
"/*"				{ BEGIN(COMMENT); return (int)HToken.COMMENTBLOCK; }
<COMMENT>[^\|*\n]*	{ return (int)HToken.COMMENTBLOCK; }
<COMMENT>"*/"		{ BEGIN(INITIAL); return (int)HToken.COMMENTBLOCK; }

#define.*"\\"			{ BEGIN(DEFINE); return (int)HToken.DEFINE; }
<DEFINE>(.*"\\"[^\n])+	{ return (int)HToken.DEFINE; }
<DEFINE>.*")"			{ BEGIN(INITIAL); return (int)HToken.DEFINE; }

%%


This is the result of #define block:
Code:
#define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\SYNCHRONIZE)

Reply With Quote
  #2  
Old December 19th, 2011, 05:17 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
Hi there,

I'll say at the outset that I am not familiar with MPlex, but since no one replied so far I thought I would try to give you a hand with a fairly standard syntax.

This expression works using a number of regex flavors: PCRE, Java, Perl, .NET.

Code:
(?s)#define[^(]*?\([^)]*?\)


It matches the define block in your example.

In other flavors, you could remove the inline flag for "dot-matches new line"---the "(?s)" and turn that on using your local syntax.

Hoping this works for you. Please let me know.

Reply With Quote
  #3  
Old December 20th, 2011, 07:29 AM
minor28 minor28 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sweden
Posts: 259 minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 1 m 26 sec
Reputation Power: 19
Thank you for your answer.

Code:
#define{space}+{W}+{space}+	{ BEGIN(DEFINE); return (int)NodeToken.DEFINE_BLOCK; }
<DEFINE>"("{OR}*		{ return (int)NodeToken.DEFINE_BLOCK; }
<DEFINE>[^\\\r\n]+		{
				if (yytext.EndsWith("\\"))
				{
					return (int)NodeToken.DEFINE_BLOCK;
				}
				else
				{
					BEGIN(INITIAL); 
					return (int)NodeToken.DEFINE_BLOCK;
				}
				}
<DEFINE>{OR}*")"$		{ BEGIN(INITIAL); return (int)NodeToken.DEFINE_BLOCK; }

where {W} is word characters and {OR} also include " " and "|" chars.

This will match #defines with one or more lines.

Reply With Quote
  #4  
Old December 20th, 2011, 01:43 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
Hi, you're welcome. Sorry, I don't understand your last post.
Are you saying that you want to match the pattern in the new box?

Reply With Quote
  #5  
Old December 20th, 2011, 02:37 PM
minor28 minor28 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Sweden
Posts: 259 minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level)minor28 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 1 m 26 sec
Reputation Power: 19
My lexer (the new box) will match all #defines for example like these (one or more lines) from a c++ header file.
Code:
#define HSHELL_FLASH	(HSHELL_REDRAW|HSHELL_HIGHBIT)
#define GHND		(GMEM_MOVEABLE | \
			GMEM_ZEROINIT)

My parser will then write these lines to a masm include file
Code:
HSHELL_FLASH equ (HSHELL_REDRAW or HSHELL_HIGHBIT)
GHND equ (GMEM_MOVEABLE or GMEM_ZEROINIT)

The problem is solved.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > MPLex problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap