I just started with Graphviz and am reading the DOT documentation. The online grammar is a considerable improvement over the previous pdf version, but it still appears incorrect. Here are some comments and a ‘corrected’ grammar. Note that the ‘corrected’ version is different in some notable aspects with the online grammar, and hence may not be acceptable, and I have not run it through a LR(1) parser generator (Bison/[ABJ]Yacc) or a LALR(1) parser (ANTLR), so the new grammar may be incorrect (sigh). I don’t know how to attach a PDF document so I am providing a text version.
Existing grammar Note:
1. Only one graph can be seen. You can not have two graphs represented, as graph1 immediate;y followed by graph2.
2. stmt-list requires that either there is no statement or thate are at least two statements, as in:
stmt; stmt or stmt stmt
3. A valid attr_list is [ ] [ ] [x]
4. Valid a-list statement: id = id . Id = id id
5. Valid a-list statement: 3.14 = 2
6. Valid a-list statement: <https://website.com> = 2
7. From graph, stmt, edge_stmt, subgraph, edgeRHS the following is legal:
{ ? {} }
8. Making compass_pt part of your grammar interfers with the definition of id. However , if your grammar is strictly discursive then it appears ok but without extending the lexical definitions to include each of the compass points individually is confusing, and it is confusing in any case. It is my belief that the implementation probably makes compass-pt a semantic check rather than a syntactic check.
9. The grammar can not recognize A -> { B C }
-
The lexical definition of a number is incorrect.
a) By your definition both ‘-’ and ‘’ are numbers.
b) A corrected syntax using your syntax is:
c) [-]?(.[0-9]+ | [0-9]+.[0-9]+))where ‘.’ is the literal period
New Grammar:
DOT Syntax
graph_list : graph_list graph
| graph
;
*graph* : [*strict*] ( *digraph*) | *graph* ) [ *lhs* ] ‘{‘ *stmt-list* ‘}’
;
*stmt-list* : *stmt-lis*t *stmt* [ ‘;’ ]
| *stmt* [ ‘;’ ]
|
;
*stmt* : *node_stmt*
| *edge_stmt*
| *attr_stmt*
| *lhs* ‘=’ *rhs*
;
*attr-stmt* : ( *graph* | *node* | *edge* ) *attr-list*
;
*attr-list* : *attr-list* ‘[‘ [ *a-list* ] ‘]’
: ‘[‘ [ *a-list* ] ‘]’
;
*a-list* : *a-list* *lhs* ‘=’ *lhs* [ ( ‘.’ | ‘;’ ) ]
| *lhs* ‘=’ *lhs* [ ( ‘.’ | ‘;’ ) ]
;
*edge-stmt* : ( *node-id* | *subgraph* ) *edgeRHS* attr*-*list
;
*edgeRHS* : *edgeRHS* *edgeop* ( *node-id* | *subgraph* )
| *edgeop* ( *node-id* | *subgraph* )
;
*node-stmt* : *node-id* *attr-list*
| *node-id*
;
*node-id* : *lhs* *port*
| *lhs*
;
*port* : ‘:’ *lhs* [‘:’ compass_pt ]
|
;
*port-location* : ‘:’ *lhs*
| ‘:’ ‘(‘ *lhs* ‘,’l*hs* ‘)’
| ‘:’ *compass_pt*
;
*subgraph* : *subgraph_prefix* ‘{‘ *stmt-list* ‘}’
;
*subgraph_prefix*: **subgraph** *lhs*
| **subgraph**
*compass_pt* : (n | ne | e | se | s | sw | w | nw | c | _ )
;
*edgeop* : **->** | **-**
;
*comments* : ‘/*’ text ‘*/’
| ‘//’ text
;
*lhs* : ***alpha*** *alpha_list*
| *string*
;
*alpha_list* : *alpha_list* ( ***alpha*** | ***numeric*** | **_** )
| ( alpha | numeric | ‘_’ )
|
;
*string* :***"*** *string_list* ***"***
;
*string_list* : *string_list* *string_prim*
| *string_prim*
;
*string_prim* : ‘ ‘
| ***alpha***
| ***numeric***
;
*html* : ‘< ***html_expression*** ‘>’
;
***html_expression***: lexical construct;
***alpha*** : lexical construct;
***numeric*** : lexical construct;
Meta-Language
‘ ‘ literal string, part of input language
: separator for first element of grammar expressions
; grammar statement termination
bold literal string, part of input language
bold italic lexeme
italic grammatical element
( ) grouping, an item within the grouping is required
[ ] grouping, items witing the grouping are optional
| alternation, a logical ‘or’ between options