I don't think there are any BNF/EBNF grammars for erlang<div>there might be grammars for subsets of the language but not the</div><div>entire language. The problem with NBF/EBNF/PEG grammars</div><div>is that decent error reporting is very difficult. In practice</div>
<div>virtual all languages use hand written recursive descent parsers</div><div>or LALR(1) parsers for which acceptable error recovery strategies exist.</div><div><br></div><div>The official grammar is: (official means this is the actual grammar used by the erlang compiler and all tools) </div>
<div><br></div><div><a href="https://github.com/erlang/otp/blob/master/lib/stdlib/src/erl_parse.yrl">https://github.com/erlang/otp/blob/master/lib/stdlib/src/erl_parse.yrl</a><br><br></div><div>It you look at the productions they are very similar to yacc</div>
<div>productions:</div><div><br></div><div>For example a tuple is defined like this (line 330,331)</div><div><br></div><div><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 12px/normal 'Bitstream Vera Sans Mono', Courier, monospace; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; font-size: 12px; line-height: 1.4; background-color: rgb(255, 255, 255); ">
<div class="line" id="LC330" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; ">tuple -> '{' '}' : {tuple,?line('$1'),[]}.</div>
<div class="line" id="LC331" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; ">tuple -> '{' exprs '}' : {tuple,?line('$1'),'$2'}.</div>
<div><br></div><div>If you forget about the stuff after the ':' this</div><div>reads</div><div><br></div><div> tuple -> '{' '}'</div><div> tuple -> {' exprs '}'</div><div><br>
</div><div>ie a tuple is either {} or { exprs }</div><div><br></div><div>The part after the ':' define the parse tree that</div><div>is returned if the expression is recognised.</div><div><br></div><div>A production like:</div>
<div><br></div><div>a -> b c d : {something, '$2'}</div><div><br></div><div>means is we match an 'a' then the parse</div><div>tree we want returned is {something, '$2'}</div><div><br></div><div>
'$1' is the parse tree of b, '$2' is the parse tree </div><div>of c etc.</div><div><br></div><div>and exprs (line 445/446) is defined</div><div><br></div><div><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 12px/normal 'Bitstream Vera Sans Mono', Courier, monospace; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; line-height: 1.4; ">
<div class="line" id="LC449" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; ">exprs -> expr : ['$1'].</div>
<div class="line" id="LC450" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; ">exprs -> expr ',' exprs : ['$1' | '$3'].</div>
</pre></div><div><br></div><div>ie exprs is an expr or a comma separated</div><div>sequence of expr's</div><div><br></div><div>In the original yacc this would be written</div><div>something like</div><div><br></div><div>
exprs: expr {$$ = $1}</div><div> | expr ',' exprs {$$ = [$1|$3]}</div><div><br></div><div>The yecc manual is at <a href="http://www.erlang.org/doc/man/yecc.html">http://www.erlang.org/doc/man/yecc.html</a></div>
<div><br></div><div>the command</div><div><br></div><div>> erlc erlang.yecc</div><div><br></div><div>compiles the grammar into a beam file</div><div><br></div><div>Cheers</div><div><br></div><div>/Joe</div><div><br></div>
<div><br></div><div><br></div><div><br></div></pre></div><div><div class="gmail_quote">On Fri, Nov 11, 2011 at 5:08 PM, Ryan Molden <span dir="ltr"><<a href="mailto:ryanmolden@gmail.com">ryanmolden@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Howdy fellow Erlangeers. I was wondering if anyone knew of a BNF/EBNF grammar for Erlang? Joe Armstrong pointed me at the YRL grammar at github; unfortunately, I am YRL illiterate so it looked mostly like gibberish to me.<div>
<br></div><font color="#888888"><div>Ryan</div>
</font><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>