Discussion:
[fpc-pascal] Free Pascal Language Diagram
Anthony Walter
2018-09-11 18:49:25 UTC
Permalink
I posted this link once before, but I thought I'd remind you guys it exists
and ask if anyone would like to take the work from the page, and integrate
it into either the official documentation or maintain it somewhere on the
free pascal website.

https://www.getlazarus.org/learn/language/lexical/

The diagrams are pretty easy to create and edit. For example proecudre
header is defined through a script tag on the page as follows:

<script>
Schematic(
Link('Identifier', '#identifier'),
Optional(Link('Generic Block', '#generic_block')),
Optional(Link('Parameters', '#parameters')),
Keyword(':'),
Link('Identifier Dot', '#identifier_dot'),
Keyword(';'),
Optional(Link('Function Directives', '#function_directives'))
).render();
</script>


And renders like so:

https://www.getlazarus.org/learn/language/lexical/#function_header

To use just copy this css and script file on the any page you want to
display diagrams:

<link rel="stylesheet" type="test/stylesheet" href="//
cache.getlazarus.org/styles/schematic.css">
<script src="//cache.getlazarus.org/scripts/schematic.js"></script>

You can look at the source of the page to see exactly what Schematic()
commands are given to generate each diagram.
R0b0t1
2018-09-11 19:50:41 UTC
Permalink
Noice.

I'd been wanting to collect all of the ones from the docs into a more
coherent representation of the syntax.
Post by Anthony Walter
I posted this link once before, but I thought I'd remind you guys it
exists and ask if anyone would like to take the work from the page, and
integrate it into either the official documentation or maintain it
somewhere on the free pascal website.
https://www.getlazarus.org/learn/language/lexical/
The diagrams are pretty easy to create and edit. For example proecudre
<script>
Schematic(
Link('Identifier', '#identifier'),
Optional(Link('Generic Block', '#generic_block')),
Optional(Link('Parameters', '#parameters')),
Keyword(':'),
Link('Identifier Dot', '#identifier_dot'),
Keyword(';'),
Optional(Link('Function Directives', '#function_directives'))
).render();
</script>
https://www.getlazarus.org/learn/language/lexical/#function_header
To use just copy this css and script file on the any page you want to
<link rel="stylesheet" type="test/stylesheet" href="//
cache.getlazarus.org/styles/schematic.css">
<script src="//cache.getlazarus.org/scripts/schematic.js"></script>
You can look at the source of the page to see exactly what Schematic()
commands are given to generate each diagram.
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Michael Van Canneyt
2018-09-12 03:11:40 UTC
Permalink
Post by Anthony Walter
I posted this link once before, but I thought I'd remind you guys it exists
and ask if anyone would like to take the work from the page, and integrate
it into either the official documentation or maintain it somewhere on the
free pascal website.
https://www.getlazarus.org/learn/language/lexical/
Where did you get the rendering library from ?

Michael.
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo
Graeme Geldenhuys
2018-09-23 09:01:22 UTC
Permalink
Post by Anthony Walter
https://www.getlazarus.org/learn/language/lexical/
Nice, but the mouse over animation is pretty annoying [and unnecessary]
though.

I've also been maintaining my own Object Pascal Grammar (using FPC's
objfpc mode only) in a EBNF (Extended Backus-Naur Form) like style. I
include it as part of the FPC Language Reference (INF help) included
with fpGUI.

It might look confusing to some that don't understand EBNF syntax, but
it really is pretty straight forward. Also with DocView's searching
ability and highlighting search matches is is very quick to find the
grammar of any Object Pascal language construct you are looking for.

Here is a snippet of the grammar...

========================================
Goal -> (Program | Package | Library | Unit)
Program -> [PROGRAM Ident ['(' IdentList ')'] ';']
ProgramBlock '.'
Unit -> UNIT Ident [HintDirective] ';'
InterfaceSection
ImplementationSection
InitSection '.'
Package -> PACKAGE Ident ';'
[RequiresClause]
[ContainsClause]
END '.'
Library -> LIBRARY Ident ';'
ProgramBlock '.'
ProgramBlock -> [UsesClause]
Block
UsesClause -> USES IdentList ';'
HintDirective -> deprecated [String]
-> experimental
-> library
-> platform
-> unimplemented
InterfaceSection -> INTERFACE
[UsesClause]
[InterfaceDecl]...
InterfaceDecl -> ConstSection
-> TypeSection
-> VarSection
-> ExportedHeading
ExportedHeading -> ProcedureHeading ';' [Directive]
-> FunctionHeading ';' [Directive]
ImplementationSection -> IMPLEMENTATION
[UsesClause]
[DeclSection]...
[ExportsStmt]...
Block -> [DeclSection]
[ExportsStmt]...
CompoundStmt
[ExportsStmt]...
ExportsStmt -> EXPORTS ExportsItem [, ExportsItem]...
ExportsItem -> Ident [NAME|INDEX "'" ConstExpr "'"]
[INDEX|NAME "'" ConstExpr "'"]
DeclSection -> LabelDeclSection
-> ConstSection
-> TypeSection
-> VarSection
-> ProcedureDeclSection
LabelDeclSection -> LABEL LabelId
ConstSection -> CONST (ConstantDecl ';')...
ConstantDecl -> Ident '=' ConstExpr [HintDirective]
-> Ident ':' TypeId '=' TypedConstant [HintDirective]
TypeSection -> TYPE (TypeDecl ';')
TypeDecl -> Ident '=' [TYPE] Type [HintDirective]
-> Ident '=' [TYPE] RestrictedType [HintDirective]
TypedConstant -> (ConstExpr | ArrayConstant | RecordConstant)
ArrayConstant -> '(' TypedConstant ',' ')'
RecordConstant -> '(' RecordFieldConstant ';'... ')'
RecordFieldConstant -> Ident ':' TypedConstant

....snip....
========================================



Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.o
Graeme Geldenhuys
2018-09-23 10:41:14 UTC
Permalink
Post by Anthony Walter
https://www.getlazarus.org/learn/language/lexical/
I found a few small bugs in your diagrams.

1) Identifier
[https://www.getlazarus.org/learn/language/lexical/#identifier]

It should look as follows:
┌────────────────────────────────────────────────────────────────────┐
Identifiers
Post by Anthony Walter
─── identifier ──┬─ letter ─┬─┬──────────────┬───────────────────><
└─── _ ────┘ ^─┬─ letter ─┬─┘
├─ digit ──┤
└─── _ ────┘
└─────────────────────────────────────────────────────────────────────┘

Note that identifiers can also start with a <underscore>


2) The Program unit structure
[https://www.getlazarus.org/learn/language/lexical/#program_header]

Strictly speaking (but mostly not used these days), the PROGRAM syntax
can also take a parenthesis with input,output identifiers.

eg:
program MyUnit (input,output);
....

3) Unit Header
[https://www.getlazarus.org/learn/language/lexical/#unit_header]

Again, your syntax is incomplete and should look as follows:

Unit -> UNIT Ident [HintDirective] ';'



I didn't go through the rest in detail, but these are the ones I spotted
immediately.


Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http:/
Anthony Walter
2018-09-24 18:51:25 UTC
Permalink
Regarding Identifier, in my page the diagram shows it must start with a
Letter optionally followed by any Letter or Digit. Letter links to another
diagram defining it as any of A-Z a-z _

This seems correct. I just tested and "const _ = 1" compiles fine using a
lone _ as an identifier.

Try left clicking Letter in the following diagram:

https://www.getlazarus.org/learn/language/lexical/#identifier
Graeme Geldenhuys
2018-09-24 21:50:27 UTC
Permalink
Post by Anthony Walter
Letter links to another
diagram defining it as any of A-Z a-z _
My bad, sorry. I assumed "Letter" meant A-Z and a-z. I didn't click the
link.

Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/
Loading...