motoko icon indicating copy to clipboard operation
motoko copied to clipboard

top two rules unclear

Open mesbahkhan opened this issue 3 years ago • 4 comments

`<list(X, SEP)> ::= X X SEP <list(X, SEP)>

<list1(X, SEP)> ::= X X SEP <list(X, SEP)>`

the first two rules they don’t seem to be part of the standard BNF syntax

e.g. <list(X,SEP)> this looks like a template for a rule, I can’t seem to locate this in the official BNF syntax.

I am trying to parse the grammar in ANTLR4 and it seems to not recognize the first two rules which have this syntax. Typically an BNF rule id is meant to just be a string of chars with ‘-’ or numbers (according to the antlr grammar for BNF this is what an ID is supposed to be made of:

id_ : LT ruleid GT ;

ruleid : ID ;

ID : (‘a’…‘z’|‘A’…‘Z’) (‘a’…‘z’|‘A’…‘Z’|‘0’…‘9’|’-’|’ ')+ ;

and a rule is

rule_ : lhs ASSIGN rhs ;

where the ASSIGN is ::==

ASSIGN : ‘::=’ ;

So a little lost here, what syntax do the first two rules follow, they almost look like meta-rules. Is the tool that generates them something internal or open source?

mesbahkhan avatar Jul 24 '22 16:07 mesbahkhan

These syntax descriptions resemble EBNF, but were generated from the menhir grammar in src/mo_frontend/parser.mly.

ggreif avatar Aug 02 '22 09:08 ggreif

Menhir also has an option to produce a yacc compatible grammar from the menhir grammar, if I recall correctly. (UPDATE: having looked at the doc, I can't actually find the option anymore).

In any case, http://gallium.inria.fr/~fpottier/menhir/ is the tool we use.

crusso avatar Aug 02 '22 10:08 crusso

If it helps (not sure it will, unless Rust is familiar), but we are in the process of making another, totally compatible reference implementation in Rust.

This part is relevant for translating that aspect of the existing parser. Very WIP.

matthewhammer avatar Aug 02 '22 14:08 matthewhammer

Transferring to Motoko repo as this is related to Motoko syntax, not documentation/website content.

jessiemongeon1 avatar Mar 11 '24 13:03 jessiemongeon1