Free Pascal Language Diagram

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Free Pascal Language Diagram

Anthony Walter-3
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.


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:


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

You can look at the source of the page to see exactly what Schematic() commands are given to generate each diagram.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Free Pascal Language Diagram

R0b0t1
Noice.

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

On Tue, Sep 11, 2018 at 1:49 PM, Anthony Walter <[hidden email]> wrote:
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.


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:


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

You can look at the source of the page to see exactly what Schematic() commands are given to generate each diagram.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Free Pascal Language Diagram

Michael Van Canneyt
In reply to this post by Anthony Walter-3


On Tue, 11 Sep 2018, Anthony Walter wrote:

> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Free Pascal Language Diagram

Graeme Geldenhuys-6
In reply to this post by Anthony Walter-3
On 11/09/18 19:49, Anthony Walter wrote:
>
> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Free Pascal Language Diagram

Graeme Geldenhuys-6
In reply to this post by Anthony Walter-3
On 11/09/18 19:49, Anthony Walter wrote:
>
> 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

>>─── 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Free Pascal Language Diagram

Anthony Walter-3
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:


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Free Pascal Language Diagram

Graeme Geldenhuys-6
On 24/09/18 19:51, Anthony Walter wrote:
> 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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal