By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

C++ syntax expressed in toot-toot diagrams?

P: n/a
In the old ages when I was taught Pascal, the manual had nice
syntax diagrams. Each grammatical structure was shown as
round boxes connected by arrows, with a model railway look,
with the boxes representing either lexical tokens or other
diagrams (i.e. terminals/nonterminals). They seemed very
intuitive because you could toot-toot one finger along the
rails in the book while moving another finger over your code.

Does anything similar exist for C++? Or am I stuck with the bnf?
(I really appreciate the hyperlinked version http://www.nongnu.org/hcb/
but it's still a mess...)

If I have to create the diagrams myself, I might as well use UML,
that being the company standard. But I'm not sure whether I
shold use state diagrams or activity diagrams or something else
- the state diagrams are conceptually close but they represent
states as boxes and transitions as arrows, which is the opposite
of what I want. Activity diagrams seem a better graphical match
but perhaps less appropriate conceptually.

Any hints?
Sep 10 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ole Nielsby wrote:
In the old ages when I was taught Pascal, the manual had nice
syntax diagrams. Each grammatical structure was shown as
round boxes connected by arrows, with a model railway look,
with the boxes representing either lexical tokens or other
diagrams (i.e. terminals/nonterminals). They seemed very
intuitive because you could toot-toot one finger along the
rails in the book while moving another finger over your code.

Does anything similar exist for C++? Or am I stuck with the bnf?
(I really appreciate the hyperlinked version http://www.nongnu.org/hcb/
but it's still a mess...)

If I have to create the diagrams myself, I might as well use UML,
that being the company standard. But I'm not sure whether I
shold use state diagrams or activity diagrams or something else
- the state diagrams are conceptually close but they represent
states as boxes and transitions as arrows, which is the opposite
of what I want. Activity diagrams seem a better graphical match
but perhaps less appropriate conceptually.

Any hints?

I really doubt such a thing exists in the wild. Maybe at Dinkumware
they might have something like that...I doubt gnu would... I doubt Dink
will share but you could try.
Sep 10 '07 #2

P: n/a
Noah Roberts wrote:
Ole Nielsby wrote:
>In the old ages when I was taught Pascal, the manual had nice
syntax diagrams. [...] with a model railway look [...]
Does anything similar exist for C++?

I really doubt such a thing exists in the wild. Maybe at Dinkumware they
might have something like that...I doubt gnu would... I doubt Dink will
share but you could try.
Never mind, I decided to do the graphics from scratch, using an
egg-laying turtle.... I hope I can get someone to review the diagrams
when I think I'm done.
Sep 11 '07 #3

P: n/a
On Mon, 10 Sep 2007 15:12:15 +0200, Ole Nielsby wrote:
In the old ages when I was taught Pascal, the manual had nice
syntax diagrams. Each grammatical structure was shown as
round boxes connected by arrows, with a model railway look,
with the boxes representing either lexical tokens or other
diagrams (i.e. terminals/nonterminals). They seemed very
intuitive because you could toot-toot one finger along the
rails in the book while moving another finger over your code.

Does anything similar exist for C++? Or am I stuck with
the bnf? (I really appreciate the hyperlinked version
http://www.nongnu.org/hcb/ but it's still a mess...)
I also loved those diagrams you mentioned in some Pascal book.
Recently I found them used at http://www.json.org/ , but I still
don't know what if anything produces them.

However, I managed to create a program that converts EBNF style
grammar into Graphviz graph files that resemble loosely the
diagrams which you describe.
An example of its input and the matching product are shown
respectively here:
http://tasvideos.org/SiteTechnology/...tatementSyntax
http://bisqwit.iki.fi/kala/snap/tasvqueryflowchart.png
And the source of the converter:
http://bisqwit.iki.fi/src/bnf_to_graph.php.txt

--
Joel Yliluoma - http://bisqwit.iki.fi/
: comprehension = 1 / (2 ^ precision)
Sep 11 '07 #4

P: n/a
Joel Yliluoma <bi*****@iki.fiwrote:
On Mon, 10 Sep 2007 15:12:15 +0200, Ole Nielsby wrote:
>[...] syntax diagrams [...] with a model railway look

I also loved those diagrams you mentioned in some Pascal book.
Recently I found them used at http://www.json.org/ , but I still
don't know what if anything produces them.

However, I managed to create a program that converts EBNF style
grammar into Graphviz graph files [...]
I dug up the old turtle graphics concept from the Logo days and adapted
it into a thing I call tokentoot-turtletalk when I'm sober - now I can hand-
code the diagrams with relative ease. The JSON ref looks nice, I'll go for
a similar look.

(The bnf grammar for C++ is too lax, it accepts too much rubbish, I
need something tighter even if I have to produce it myself.)

In case anyone wonders what tokentoot-turtletalk looks like, here's
a sample that tries to describe a decl-specifier - it's all very
prelimiary...
the graphs look nicer than the code...

:y 70 .tokentoot .
bar
right 30
fork up 50 right 600 down 50 right 60 bar join
fork
right 60
fork
right 30
fork right 60 hit "export" right 60 down 25 left 120 down 10 join
down 50 right 60 hit "template" right 60
fork down 25 right 360 down 10 join
right 40 hit "<"
right 40
fork
up 40
right 100
box "template-parameter" right 100
fork up 35 left 100 hit "," left 100 down 35 right 10 end join
down 40 right 10
join
right 100 toot "-export" right 140 hit ">" right 40 down 200 left 510
down 10
join
down 300 right 30 bar right 10 bar
join
down 400 right 10 bar
Sep 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.