parse a string as a Maple statement
Maple string containing a Maple expression, or a Maple statement if the 'statement' option is specified
zero or other options
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.
The parse command is thread-safe as of Maple 15.
For more information on thread safety, see index/threadsafe.
Parse generates errors on incorrect input.
Error, incorrect syntax in parse: `^` unexpected (near 3rd character of parsed string)
Parse multiple statements.
n ≔ 0
input ≔ a := 4; a^2; a^3;
input≔a := 4; a^2; a^3;
Download Help Document
What kind of issue would you like to report? (Optional)