Created
June 13, 2015 01:50
-
-
Save jwhiteman/adee4036124b3f779153 to your computer and use it in GitHub Desktop.
List Parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Andrea Leopardi's list parser | |
% http://andrealeopardi.com/posts/tokenizing-and-parsing-in-elixir-using-leex-and-yecc/ | |
Nonterminals list elems elem. | |
Terminals '[' ']' ',' int atom. | |
Rootsymbol list. | |
list -> | |
'[' ']' : []. | |
list -> | |
'[' elems ']' : '$2'. | |
elems -> | |
elem : ['$1']. | |
elems -> | |
elem ',' elems : ['$1'|'$3']. | |
elem -> int : extract_token('$1'). | |
elem -> atom : extract_token('$1'). | |
elem -> list : '$1'. | |
Erlang code. | |
extract_token({_Token, _Line, Value}) -> Value. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment