Lost Password?

  #1 (permalink)  
Old 06-11-2008, 07:24 AM
Chinmoy's Avatar   
Chinmoy Chinmoy is offline
Programming Professional
 
Join Date: Feb 2008
Location: where heaven meets earth
Posts: 301
Rep Power: 6
Chinmoy has a spectacular aura aboutChinmoy has a spectacular aura about
Default Working in a maximal munch

Maximal munch

In computer programming, the "maximal munch" principle is the rule that as much of the input as possible should be processed when creating some construct.
[Quoting wikipedia]

But the real problem is where we have to solve such expression.

Welcome to the world of maximal munch.

In one of the early stages of C++ translation, the portion of the compiler that performs “lexical analysis” has the task of breaking up the input stream into individual “words,” or tokens. So when the lexical analyzer encounters a character like (->*), it might reasonably identify three tokens (-, >, and *), two tokens (-> and *), or a single token (->*)!

However to avoid this ambiguous state of affairs, the lexical analyzer has been taught to identify the lingest sequence, thus consuming as many characters as it legally can. The situation :: a maximal munch!

The expression a+++++b is illegal, because it’s tokenized as a ++ ++ + b, and it’s illegal to post-increment an rvalue like a++.

If you had wanted to post-increment a and add the result to a pre-incremented b, you’d have to introduce at least one space as in: a+++ ++b. If you are writing a code which should be reusable, even though it’s not strictly necessary you should consider including one more space as: a++ + ++b, and the last and best is the addition of a few parentheses: (a++) + (++b).

Maximal munch solves many more problems than it causes, but in two common situations, it’s an annoyance. The first is in the instantiation of templates with arguments that are themselves instantiated templates. For example, using the standard library, one might want to declare a list of vectors of strings:
list> lovos; // error!

Unfortunately, the two adjacent closing angle brackets in the instantiation are interpreted as a shift operator, and we’ll get a syntax error. Addition of whitespaces fixes the problem ::
list< vector > lovos;

Another situation - default argument initializers for pointer formal arguments ::
void process( const char *= 0 ); // error!

This declaration is attempting to use the *= assignment operator in a formal argument declaration.That is a syntax error. This problem comes under the “wages of sin” category. It wouldn’t have happened if the author of the code had given the formal argument a name. Not only is such a name some of the best documentation one can provide, its presence would have made the maximal munch problem impossible:
void process( const char *processId = 0 );

Read more on this topic :: The maximal munch | TECHARRAZ
__________________
God is real... unless declared an integer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-11-2008, 07:35 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 5,973
Last Blog:
SAP, ERP and EDI
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default Re: Working in a maximal munch

Another excellent read! +rep
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Don't hesitate to ask any questions that you have! Check out our ASCII Calculator!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
KeyDown Event not working! Help! Urgent proggy123 Visual Basic Programming 6 09-01-2008 11:03 AM
export to excel problem with IPAddress in URL but working with localhost url mustaque ASP, ASP.NET and Coldfusion 5 08-04-2008 07:31 AM
unsafe code i modified isn't working quite right.. David241 C# Programming 1 02-24-2008 11:06 PM
Working with TADO Table MrDiaz Pascal/Delphi 0 07-03-2006 06:28 PM
Why this isnt working? Creature Java Help 1 06-16-2006 07:23 AM


All times are GMT -5. The time now is 01:25 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads