# Present syntax rules in a more succinct way

I am resuming syntax rules for a small language:

\begin{eqnarray*} e_C &::=& \epsilon \mid constant \\ \textit{prefix-op} &::=& - \\ \textit{infix-op} &::=& + \mid - \mid * \\ e_E &::=& e_C \mid \textit{prefix-op} \; e_E \mid e_E \; \textit{infix-op} \; e_E \mid \textit{function}_E (e_{E,0}, e_{E,1},\ldots) \mid \textit{specialE} \\ e_V &::=& e_C \mid \textit{prefix-op} \; e_V \mid e_V \; \textit{infix-op} \; e_V \mid \textit{function}_V (e_{V,0}, e_{V,1}, \ldots) \mid \textit{specialV} \end{eqnarray*}

The expressions $e_E$ and $e_V$ have something common: $e_C$. Some of their operators look same: $\textit{prefix-op}$ and $\textit{infix-op}$. Their functions $\textit{function}_E$ and $\textit{function}_V$ are 2 different sets, and $\textit{specialE}$ and $\textit{specialV}$ are totally different.

I am wondering if it is still possible to present this syntax more succinct, more compact in a conventional way... Could anyone help?

Van Wijngaarden grammars are a way to handle this problem. It would be something like:

KIND : e ; v .

e KIND : e c ; prefix-op, e KIND ; e KIND, infix-op, e e; function KIND (e KIND, ",", e KIND, "," ... ) ; special KIND .


(There is no "..." in the formalism, so you'd have either to extend the grammar syntax or express it in another way).

One direct way of solving this problem is to make the syntax rules parameterised, as follows:

\begin{eqnarray*} e_{X,Y} &::=& e_C \mid \textit{prefix-op} \; e_{X,Y} \mid e_{X,Y} \; \textit{infix-op} \; e_{X,Y} \mid Y (e_{X,Y}, e_{X,Y},\ldots) \mid X \\ \end{eqnarray*}

And then to set \begin{eqnarray*} e_E &::=& E_{\mathit{specialE},~\mathit{function}_E} \\ e_V &::=& E_{\mathit{specialV},~\mathit{function}_V} \\ \end{eqnarray*}

This is using notation I just invented, and it could probably be reworked, but you get the idea, I hope.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6300168,"math_prob":0.99412894,"size":941,"snap":"2021-43-2021-49","text_gpt3_token_len":330,"char_repetition_ratio":0.20384204,"word_repetition_ratio":0.016393442,"special_character_ratio":0.34962806,"punctuation_ratio":0.1978022,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99658227,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-04T16:38:21Z\",\"WARC-Record-ID\":\"<urn:uuid:c1127583-9cbf-4e61-9b53-f2fde48be7cb>\",\"Content-Length\":\"142945\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f4427d99-d095-489d-896c-b2c4fad373b3>\",\"WARC-Concurrent-To\":\"<urn:uuid:eff2dead-bd88-4135-8f22-194612564b8e>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://cs.stackexchange.com/questions/7300/present-syntax-rules-in-a-more-succinct-way/7303\",\"WARC-Payload-Digest\":\"sha1:XSLRE2R3YD7B4ABRZBGNYSPRP5SN5JBG\",\"WARC-Block-Digest\":\"sha1:SQC57VZPPQRZNMLPGPXVVBU5NRY4HG4G\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964362999.66_warc_CC-MAIN-20211204154554-20211204184554-00084.warc.gz\"}"}