Index of /~lloyd/tildeFP/SML/1997/Exp

      Name                    Last modified       Size  Description

[DIR] Parent Directory 15-Aug-2006 18:55 - [   ] data 07-Aug-2006 12:24 1k [   ] exp.sml 07-Aug-2006 17:11 6k [   ] main.sml 07-Aug-2006 12:22 1k


^ LA / FP / SML / 97 / ^   [Parsing] in [C] [Java]

Simple example recursive-descent parser for expressions.

exp.sml -- parser
The lexical analysis function converts a char list into a Symbol list; to see this try, e.g.,
    use "exp.sml";
    lexical(explode "(1+2)*3-4/5+x");
The parser takes a Symbol list and produces a parse tree : Exp, e.g.,
    expression(lexical(explode "(1+2)*3-4/5+x"));
main.sml -- parse text from a file
wrapper for the parser, asks for a file name, opens it, calls the parser, e.g.,
    use "main.sml";
    run "data";
 
Note, these expressions include arithmetic (+, -, *, /), relational (=, <>, <=, >=, < >), and logical (and, or, not) operators.
 
And there is a syntax (and semantics) for a small programming language [here].

L. Allison, Monash U., Australia 3800. www.csse.monash.edu.au/~lloyd/tildeFP/SML/1997/Exp/