Erlang (programming language)/Tutorials/Yecc: Difference between revisions
Jump to navigation
Jump to search
imported>Eric Evers (New page: Making Parsers with yecc Yecc is an erlang version of yacc. We have a BNF grammar in a source file ending in .yrl yrl means yecc rule list. We can parse simple a simple xhtml file using ...) |
imported>Eric Evers mNo edit summary |
||
Line 6: | Line 6: | ||
yrl means yecc rule list. | yrl means yecc rule list. | ||
We can parse simple a simple xhtml file using yecc. | We can parse simple a simple xhtml file using yecc. | ||
(Of course a more powerful way to xml in erlang is xmerl) | (Of course a more powerful way to do xml in erlang is xmerl) | ||
html.yrl source: | html.yrl source: |
Revision as of 12:46, 1 May 2008
Making Parsers with yecc
Yecc is an erlang version of yacc.
We have a BNF grammar in a source file ending in .yrl yrl means yecc rule list. We can parse simple a simple xhtml file using yecc. (Of course a more powerful way to do xml in erlang is xmerl)
html.yrl source:
Nonterminals tag elements element start_tag end_tag . Terminals 'atom' '<' '>' '/'. Rootsymbol tag. tag -> start_tag tag end_tag : ['$1', '$2', '$3']. tag -> start_tag tag tag end_tag : ['$1', '$2', '$3', '$4']. tag -> start_tag elements end_tag : ['$1', {'contents','$2'}, '$3']. tag -> start_tag end_tag : ['$1','$2'].
start_tag -> '<' 'atom' '>' : {'open','$2'}. end_tag -> '<' '/' 'atom' '>' : {'close','$3'}. elements -> element : ['$1']. elements -> element elements : ['$1', '$2']. element -> atom : '$1'.
% yecc:yecc("html.yrl","html_parser.erl"). % c(html_parser). % f(B), {_,B,_} = % erl_scan:string( % "<html><head></head><body>hello_world</body></html>"). % html_parser:parse(B).