Syntactic tree of a simple instruction : A = 2+3
i was wondering if anyone could help me drawing the syntactic tree of a very very simple instruction 开发者_运维百科in erlang : a simple assignment like A = 2 + 3. using , of course the erlang official grammar available at http://svn.ulf.wiger.net/indent/trunk/erl_parse.yrl
Thanks for everything
You can simply use Erlang own tools:
1> {ok, Toks, _} = erl_scan:string("A=2+3.").
{ok,[{var,1,'A'},
{'=',1},
{integer,1,2},
{'+',1},
{integer,1,3},
{dot,1}],
1}
2> {ok, [AST]} = erl_parse:parse_exprs(Toks).
{ok,[{match,1,
{var,1,'A'},
{op,1,'+',{integer,1,2},{integer,1,3}}}]}
3> AST.
{match,1,{var,1,'A'},{op,1,'+',{integer,1,2},{integer,1,3}}}
精彩评论