Implementation of a parser module.
Parser for a calculator.
make run args=<...>
to build the parser and run with args given (quote them if you have spaces).
make
to only build it.
Example:
make run < tokens.json
will parse the input and print the ast
make run-test
to build and run all tests.
make test
to only build test.
make run-test args=--ast
to build and run all test printing the ast each time.
make valgrind
to build the test and run them with valgrind.
The root is one of the nodes below.
The key type
starts with literal
.
Key type
: literal.float
.
Key value
: string representation of the float.
The key type
starts with operator
.
Key type
: operator.minus
.
Key operand
: node to negate.
- eval(this->operand)
Key type
: operator.X
where X
is plus
, subtract
, multiplication
or division
.
Key lhs
: left operand's node.
Key rhs
: left operand's node.
eval(this->lhs) op eval(this->rhs)
whereop
is+
,-
,*
or/