Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bitwise logical expressions

73 views
Skip to first unread message

mathewji

unread,
Jan 9, 2015, 3:53:09 PM1/9/15
to
Programming: Principles and Practice Using C++ by Bjarne Stroustrup, chapter 6, page 219, exercise 7, "Write a grammar for bitwise logical expressions. A bitwise logical expression is much like an arithmetic expression except that the operators are ! (not), ~ (complement), & (and), | (or), and ^ (exclusive or). Each opeartor does its operation to each bit of its integer operands (see 25.5). ! and ~ are prefix unary operators. A ^ binds tighter than a | (just as a * binds tighter than +) so tha x|y^z means x|(y^z) rather than (x|y)^z. The & operator binds tighter than ^ so that x^y&z means x^(y&z)."

I need help with the whole question..
Message has been deleted

Victor Bazarov

unread,
Jan 9, 2015, 4:10:50 PM1/9/15
to
It's not a question, actually. It's an exercise. "Write a grammar"
means you need to use your hand/hands and some medium, like paper, to
construct and record expressions that would represent the rules stated
in the rest of the exercise description. If you've never written a
grammar, skip this exercise for now, it's probably not terribly important.

If it's part of your coursework, talk to your professor about "needing
help with the whole question." Most likely you missed something
basic/fundamental at the very beginning of the course if you feel
completely at sea with this.

V
--
I do not respond to top-posted replies, please don't ask
Message has been deleted

Jorgen Grahn

unread,
Jan 11, 2015, 5:49:55 AM1/11/15
to
On Sat, 2015-01-10, Stefan Ram wrote:
> Victor Bazarov <v.ba...@comcast.invalid> writes:
>>in the rest of the exercise description. If you've never written a
>>grammar, skip this exercise for now, it's probably not terribly important.
>
> But then, I have sometimes encountered questions in the
> newsgroup, where someone asks how to write a parser for some
> input, but fails to specify the exact rules for the input.

Hm, that happens almost weekily, in my experience.

...
> At some point in his education, a programmer must learn how
> to write a grammar and a parser, but it does not have to be
> at during the first year.

I think it should come early. For me, the idea that you can look at
(textual) data as an instance of a language, that was a very powerful
insight which I still rely on heavily, 25 years later.

Disclaimer: I do a lot of Unix work. Perhaps it's less useful in a
less text-oriented environmant.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Richard

unread,
Jan 12, 2015, 12:02:05 PM1/12/15
to
[Please do not mail me a copy of your followup]

r...@zedat.fu-berlin.de (Stefan Ram) spake the secret code
<grammars-20...@ram.dialup.fu-berlin.de> thusly:

>Victor Bazarov <v.ba...@comcast.invalid> writes:
>>in the rest of the exercise description. If you've never written a
>>grammar, skip this exercise for now, it's probably not terribly important.
>
> But then, I have sometimes encountered questions in the
> newsgroup, where someone asks how to write a parser for some
> input, but fails to specify the exact rules for the input.

I recently gave a presentation to the Utah C++ Programmers meetup on
how to do text parsers using Boost.Spirit. I have a github repository
with two sample parsers: JSON and e-mail date/time (which has some
crazy rules).

<https://github.com/LegalizeAdulthood/ucpp-json-parser>
<https://github.com/LegalizeAdulthood/ucpp-date-time-parser>

You can browse the individual commits to see how the parsers were
incrementally built up using test-driven development.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

Richard

unread,
Jan 12, 2015, 12:08:07 PM1/12/15
to
[Please do not mail me a copy of your followup]

Jorgen Grahn <grahn...@snipabacken.se> spake the secret code
<slrnmb4la5.4...@frailea.sa.invalid> thusly:

>Disclaimer: I do a lot of Unix work. Perhaps it's less useful in a
>less text-oriented environmant.

Oh, it's just as handy there because lots of data is interchanged as
text and you need to parse the text.

Windows/Mac is just as much a text-oriented environment as Unix, it
just has a GUI sitting on top.

If you think Windows doesn't have a decent shell, you should know that
most shell stuff these days is done in Windows PowerShell and not the
DOS prompt. <http://en.wikipedia.org/wiki/Windows_PowerShell>

Also, Windows has had the ability out-of-the-box to write scripts in
JavaScript with Windows Script Host for at least 10 years (probably
more like 15). The sysadmin guys are the only ones who seem to know
about it, as they've been using it (and later PowerShell) to automate
sysadmin tasks. However, it's still damn handy to have it available as
a developer so that you can give scripts to Windows users who won't have
something like cygwin or nodejs installed.
0 new messages