C++ syntax expressed in toot-toot diagrams?

O

Ole Nielsby

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?
 
N

Noah Roberts

Ole said:
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.
 
O

Ole Nielsby

Noah said:
Ole said:
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.
 
J

Joel Yliluoma

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/API.html#SupportedSelectStatementSyntax
http://bisqwit.iki.fi/kala/snap/tasvqueryflowchart.png
And the source of the converter:
http://bisqwit.iki.fi/src/bnf_to_graph.php.txt
 
O

Ole Nielsby

Joel Yliluoma said:
[...] 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top