473,984 Members | 67,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ excessive bracketts removal

Hello.
I'm looking for any algorithm which can take C++ experssion at input
and offer at output the same expression with excessive bracketts
removed.
Where should I look for it?

Oct 11 '07 #1
7 1481
On Thu, 11 Oct 2007 14:14:17 -0700, Dennis Yurichev
<De************ *@gmail.comwrot e in comp.lang.c++:
Hello.
I'm looking for any algorithm which can take C++ experssion at input
and offer at output the same expression with excessive bracketts
removed.
Where should I look for it?
Google?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Oct 12 '07 #2
On Oct 12, 10:49 am, Jack Klein <jackkl...@spam cop.netwrote:
On Thu, 11 Oct 2007 14:14:17 -0700, Dennis Yurichev
<Dennis.Yuric.. .@gmail.comwrot e in comp.lang.c++:
Hello.
I'm looking for any algorithm which can take C++ experssion at input
and offer at output the same expression with excessive bracketts
removed.
Where should I look for it?

Google?

--
Jack Klein
Home:http://JK-Technology.Com
FAQs for
comp.lang.chttp ://c-faq.com/
comp.lang.c++http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jack,

Actually, I think the OP has a legitimate question (although it's not
strictly a c++ language question.)
The problem is that the OP is probably unfamiliar with the word
"parse". It's hard to find what he's looking for if you don't include
the word "parse" in the google search. "Parsing" is the technical
term for what the OP wants to do.

Hopefully, the OP now has enough info to find what he needs.

Paul Epstein

Oct 12 '07 #3
On 2007-10-11 23:14, Dennis Yurichev wrote:
Hello.
I'm looking for any algorithm which can take C++ experssion at input
and offer at output the same expression with excessive bracketts
removed.
Where should I look for it?
What you want is probably a code prettyfier. The goal of a prettyfier is
to take some code an convert it so that it conforms to some coding
standard, so you want a prettyfier with a standard that do not use
excessive brackets (some standards will include excessive brackets).

--
Erik Wikström
Oct 12 '07 #4
Me:
Parsing C++
expressions is a significant pain, and can't be done without parsing
the entire program to know the types of all the arguments, including
return types of functions.

James Kanze:
That's not true. All you really need to know is which
identifiers resolve to type names, and even then, only in a very
few specific cases (and I'm not even sure that there are such
cases). Parsing C++ in general is very difficult, but if you
know you're dealing with an expression, the expressions
themselves aren't too much of a problem.
Yeah. As usual, you're right James. As long as you've at least done
pre-processing, any embedded "identifier ()" appearing in legal C++ -
where identifier isn't a reserved word (or, and etc) - can be treated
as a discrete value, and types don't affect operator precedence. Of
course, you can't validate expressions without knowing the types. For
example: *f might be a dereferenced pointer, or an attempted
multiplication with the left-hand-side missing. Anyway, that wasn't
what I was thinking about at the time - my mind was running away with
thoughts of evaluating the expressions, confusing the issues....

Thanks,

Tony

Oct 12 '07 #5
James Kanze <ja*********@gm ail.comwrote:
On Oct 12, 9:49 am, tony_in_da...@y ahoo.co.uk wrote:
>Parsing C++ expressions is a significant pain, and can't be done
without parsing the entire program to know the types of all the
arguments, including return types of functions.

That's not true. All you really need to know is which
identifiers resolve to type names, and even then, only in a very
few specific cases (and I'm not even sure that there are such
cases).
Here is one:

typedef int a;
return (a) - 1; //c-style cast, prefix operator, brackets required

const int a = 10;
return (a) - 1; //infix operator, brackets are redundant
Oct 12 '07 #6
On 2007-10-11 22:46:29 -1000, James Kanze <ja*********@gm ail.comsaid:
>
That's the real reason, I suspect. Rather than remove brackets,
it would probably be more useful to insert them everywhere, so
the user could see how the compiler understands what he wrote.
Maybe. I've had to debug Java code compiled to C, with Lots of Infernal
Stupid Parentheses. It's not fun. (Both the compiler and the Java code
were under development at the time; otherwise I wouldn't have been
looking at the generated C code). The parentheses are mostly
distractions. Of course, that's whole programs, not isolated
expressions.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 12 '07 #7
On Oct 12, 8:11 pm, Pete Becker <p...@versatile coding.comwrote :
On 2007-10-11 22:46:29 -1000, James Kanze <james.ka...@gm ail.comsaid:
That's the real reason, I suspect. Rather than remove brackets,
it would probably be more useful to insert them everywhere, so
the user could see how the compiler understands what he wrote.
Maybe. I've had to debug Java code compiled to C, with Lots of Infernal
Stupid Parentheses. It's not fun. (Both the compiler and the Java code
were under development at the time; otherwise I wouldn't have been
looking at the generated C code). The parentheses are mostly
distractions. Of course, that's whole programs, not isolated
expressions.
It depends on context, and too many parentheses can also cause
problems. I think that a program to fully parenthesize isolated
expressions could be useful: any time you're not sure,
copy/paste the expression into it, and find out. That doesn't
mean that I think every expression in the source code should be
completely parenthesized

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 14 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1416
by: postmaster | last post by:
**************** eManager Notification ***************** The following mail was blocked since it contains sensitive content. Source mailbox: <python-list@python.org> Destination mailbox(es): <ymaxwell@csc.com> Policy: Attachment Removal Attachment file name: application.pif - application/octet-stream Action: Replaced with text
2
1525
by: Mirko Zeibig | last post by:
Hello everybody, I recently stumbled across the proposal of removing `callable` in Python 3000 (http://python.org/peps/pep-3000.html) catching an exception instead, maybe something like this: --- snip --- $ python2.3 Python 2.3.3 (#1, Apr 6 2004, 01:47:39) on linux2 Type "help", "copyright", "credits" or "license" for more information.
0
1405
by: Viper99 | last post by:
Need to detect (receive notification) for the insertion/removal of PCMCIA devices on Windows 2000/XP in a C# .Net application. Was able to do this in ATL COM app using CWnd::OnDeviceChange().
0
1241
by: Viper99 | last post by:
I need to detect or be notified of PCMCIA device removal using C# .Net.
4
9033
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working, even the removal, I just don't know how to keep track of the parent, so that I can set its child to the child of the node to be removed. IE - if I had C / \ B D
3
6617
by: sanjana | last post by:
hi willy i have done the code for detecting insertion/removal of device at USB port thanx for ur advice but is there way to detect if sd card is inserted or removed from the device at usb tht is i want to check for sd card insert/remove events thanx
6
8129
by: nekiv90 | last post by:
Greetings, Could someone confirm if the following reasoning is correct (64-bit DB2 on 64-bit AIX v5.3): ================================================================== For each connection to DB2 db, AIX will reserve a 64GB shared memory segment for buffer caching. So if there are connections to 3 different DBs, AIX will reserve a
3
2067
by: tschwartz | last post by:
I'm trying to write a stylesheet which removes nodes which are empty as a result of other template processing. For example, given the following xml, I'd like to: - remove all "b" elements - remove all "a" elements which, as a result of "b" element removal, now have no children so, starting with:
1
1399
by: irfan200x | last post by:
Does Any Body Have The Key and User name of Adware removal 8.0.1 Please give me the key and user or some one have a Adware Removal 8.0.1 Full Software then send to me to this id thak you bye
0
11855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11626
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10933
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10104
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6438
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5181
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3785
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.