Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-09

Free Pascal Language Diagram

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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 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.

Reply by email

R0b0t1
to Anthony Walter

Noice.

I'd been wanting to collect all of the ones from the docs into a more coherent representation of the syntax.

Anthony Walter wrote 43 lines
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. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Anthony Walter: I posted this link once before, but I thought I'd remind you guys it exists and ask if…
Anthony Walter wrote 6 lines
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.

Reply by email

Graeme Geldenhuys
to Anthony Walter: I posted this link once before, but I thought I'd remind you guys it exists and ask if…
Anthony Walter wrote

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

Reply by email

Graeme Geldenhuys
to Anthony Walter: I posted this link once before, but I thought I'd remind you guys it exists and ask if…
Anthony Walter wrote

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

>─── 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

Reply by email