In article <
7d7efe1c-47c8-432a...@googlegroups.com>,
rug...@gmail.com wrote:
>
> So you already have the railroad diagrams? For original Pascal, they are
> also found in Wirth's _Algorithms and Data Structures_ (1976 edition)
> in the appendix.
>
Well no. I want to apply the same principle to a completely
different application:
<traversing syntax diagrams to parse other languages,
eg. to make a syntax-aware editor, so that it shows you, what's
the next possible valid entry, like a menu shows you,
so that you just need to recognise, instead of remember>.
> I don't offhand know of any online on the web except the Pascal-ish
> PL/0 offshoot XPL0:
>
>
http://www.xpl0.org/syntax.html
>
Ok, that may be good to have on-file.
> > The FSM was represented by arrays. IIRC, one per each column of
> > my paper diagram. BTW this is one BIG reason why I oppose
> > Oberon's abandonment of <data-arrays>.
>
> I don't understand what this means. AFAICT, Oberon arrays are the same as
> Pascal. Sure, for dynamic structured data, you'd be better off with POINTER
> TO RECORD, but ARRAY OF CHAR, INTEGER, etc. is still available.
> Or maybe you mean Oberon-07 restrictions? Dunno.
>
IIRC in Turbo-PASCAL [and definitely in my PLO-derivative] I could write:
CharY[ "B","S","A","I","R"];
IntR[1,4,7,3,5];
and by suitably spacing/formatting the source code, it looked like
a 2-dim-array. Which is a massively powerfull tool. Which is why
spreadseets were the killier-app. because you can easily map
cause-and-effect, from eg. a bus/train time-table.
Oberon doesn't allow this.
> > This may finally be an opportunity for me to learn to THINK
> > in terms of records? But it seems absurd to use 1 record per
> > node of the syntax diagram?
>
> Just try it out and see. If it doesn't work, use something else. There's no=
> fixed answer, just use whatever works.
>
> > Can someone suggest a suiatble data stucture for the syntax diagrams?
>
> In Wirth's 1976 A+D book, chapter five was the mini PL/0 compiler example. =
> Later he ripped that out in lieu of a separate book entirely: _Compiler Con=
> struction_
>
>
http://www.inf.ethz.ch/personal/wirth/books/CBEAll.pdf
>
> > The correspondence between the code and the paper diagrams must be
> > easy and obvious, for ease of maintenance, because the intended
> > application
> > is structured editors for 'your next new languages'.
> > Fill in the table and let it guide you, when writing code,
> > instead of having to remember a new syntax.
>
> > BTW, for google: what is the name [L, LR, ?] of the family of grammars
> > like PASCAL which need only one-token look-ahead to parse?
>
> I believe Pascal's grammar is called LL(1), but most other languages use
> more complicated ones, e.g. LALR or LR (or even GLR). I suppose Pat Terry's
> adaptation of Coco/R is probably the easiest non-YACC/LEX toolset to use.
>
>
http://en.wikipedia.org/wiki/LL_parser
>
>
http://www.scifac.ru.ac.za/compilers/
>
http://www.scifac.ru.ac.za/coco/
I've looked at coco previously. It lacks: what I had was MAGIC!
You just look at the paper, and at any node you can see immediately:
= what the valid Next-Tokens are,
= what action is done at that node.
So you don't need to write a top-down-compiler, with the
syntax of the langauge interwoven in the compiler's code.
You write a utility to read the syntax diagrams, where the reader
is completely separate from the particular syntax. The syntax is in the
diagrams. And the code-generation is also separate, and represented
by notation next the the corresponding node.
So, IIRC, I needed a dummy node, so that when exiting from an
assignment statement: X := 2+3
the action at the dummy-node was:
pop [the SymbtblPointer (which was pushed at node "ID=X"]
and use it to show where to store [block & offset] the
value of the expression: 2+3.
==============