Creating an AST node in Erlang
Posted
by dagda1
on Stack Overflow
See other posts from Stack Overflow
or by dagda1
Published on 2010-06-04T15:55:33Z
Indexed on
2010/06/05
11:42 UTC
Read the original article
Hit count: 385
erlang
Hi,
I am playing about with Erlang and I am trying to write a simple arithmetic parser.
I want to try and parse the following expression:
((12+3)-4)
I want to parse the expression into a stack of AST nodes. When parsing this expression, I would first of all create a binary expression for the (12+3) expression which would look something like this in C#:
var binaryStructure = new BinaryStructure();
binaryStructure.Left = IntegerLiteralExpression(12);
binaryStructure.Right = IntegerLiteralExpression(4);
binaryStructure.Operator = binaryExpression.Operator != BinaryOperatorType.Addition;
I am quite new to Erlang and I am wondering how I would go about creating a structure like this in Erlang that I can place on a List that I would use as the stack of expressions.
Can anyone suggest how to create such a tree like structure? Would a function be a good fit?
Thanks
Paul
© Stack Overflow or respective owner