Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » debugging » parse
next | previous | forward | backward | up | index | toc

parse -- get a concrete syntax tree of Macaulay2 code

Description

This function parses a string s containing Macaulay2 code and returns a list representing the corresponding concrete syntax tree. Each element of the list corresponds a statement. Except for very simple code, they will have a nested structure. The first element is a tag representing the type of node and later elements are its children.

Consider the following:

i1 : parse "2 + 3"

o1 = {{Binary, {Token, 2}, {Token, +}, {Token, 3}}}

o1 : List

We see that this is a Binary node with three children: the left hand side, the operator, and the right hand side. All three are Token nodes.

The next example shows how Macaulay2 deals with the danging else problem:

i2 : parse "if a then if b then s1 else s2"

o2 = {{IfThen, {Token, a}, {IfThenElse, {Token, b}, {Token, s1}, {Token,
     ------------------------------------------------------------------------
     s2}}}}

o2 : List

See also

For the programmer

The object parse is a compiled function.


The source of this document is in /build/reproducible-path/macaulay2-1.26.05+ds/M2/Macaulay2/packages/Macaulay2Doc/functions/parse-doc.m2:36:0.