parse - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


parse

parse a string as a Maple statement

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Calling Sequence

parse(string, option)

Parameters

string

-

Maple string containing a Maple expression, or a Maple statement if the 'statement' option is specified

option

-

zero or other options

Description

• 

The parse command takes a Maple string and parses the string into a Maple expression as if it had been entered or read from a file.

• 

The string must consist of exactly one Maple expression. The expression is parsed, and returned unevaluated.

• 

If the option 'statement' is specified, the string must consist of exactly one Maple statement (which includes expressions). The statement is parsed and evaluated, and the result is returned.

• 

Partial statements or expressions cannot be parsed.

• 

The 'lastread' and 'offset' options can be used to parse multiple statements or expressions.  The calling sequence parse("expr1; expr2;",'lastread' = 'n'), parses the given string, and assigns n the offset of the next unparsed character. Thus parse("expr1; expr2;",'offset' = n) can be used to parse the next statement in the string.  The variable indicated by lastread should have single uneval quotes around it to prevent evaluation if it is already assigned a value.  The lastread variable is not updated when parsing generates a syntax error.

• 

If the string is syntactically incorrect, parse returns an error of the form "incorrect syntax in parse: ... (near n'th character of parsed string)". The "n'th" part of the message indicates the offset, in characters, counted from the beginning of the string, at which the syntax error was detected.  The error can be trapped by using a try-catch construct, like any other Maple run-time error.

• 

If the string does not end with a semicolon (or colon) and a newline character, a semicolon and newline character is supplied automatically. This behavior can be suppressed by specifying the option 'nosemicolon'.

• 

If the string ends with a semicolon (or colon) but no newline character, the newline character is supplied automatically.

• 

Whether the expression is displayed when parse is called depends on whether the call to parse ends in a semicolon or a colon.

• 

When using the statement option you can prevent evaluation by also using the noeval option.  In this case NULL is always returned. This can be useful in combination with lastread to determine statement boundaries.

• 

If parse is called with no arguments, it returns either true or false depending on whether  the last string parsed by parse ended with a colon.

• 

To convert a Maple statement to a string use convert/string.

Thread Safety

• 

The parse command is thread-safe as of Maple 15.

• 

For more information on thread safety, see index/threadsafe.

Examples

parsea+b

a+b

(1)

parsea+b:

a+b

(2)

parsea+b;

a+b

(3)

parsea+b::

parse

true

(4)

parsea+b;:

parse

false

(5)

Parse generates errors on incorrect input.

parsea^^b

Error, incorrect syntax in parse: `^` unexpected (near 3rd character of parsed string)

parsesin(3.0)

sin3.0

(6)

parsesin(3.0),statement

0.1411200081

(7)

Parse multiple statements.

n0

n0

(8)

inputa := 4; a^2; a^3;

inputa := 4; a^2; a^3;

(9)

parseinput,lastread=n,offset=n,statement

4

(10)

parseinput,lastread=n,offset=n,statement

16

(11)

parseinput,lastread=n,offset=n,statement

64

(12)

See Also

convert/string

dismantle

sscanf