Import Upstream version 20180207
[hcoop/debian/mlton.git] / mlyacc / examples / calc / README
CommitLineData
7f918cf1
CE
1This is a sample interactive calculator built using ML-Yacc and ML-Lex.
2
3The calculator is defined by the files
4
5 calc.lex (* defines lexer *)
6 calc.grm (* defines grammar *)
7 calc.sml (* defines driver function, Calc.parse *)
8 calc.mlb (* ML Basis file *)
9
10To compile this example, type the following commands
11
12 mllex calc.lex
13 mlyacc calc.grm
14 mlton calc.mlb
15
16in this directory. They will invoke ml-lex and ml-yacc to process the
17lexer specification calc.lex and the grammar specification calc.grm
18respectively. Then it will compile the resulting SML source files
19
20 calc.lex.sml
21 calc.grm.sig
22 calc.grm.sml
23
24and the calc.sml file containing the driver code.
25
26The end result of compiling these files is an executable file named
27"calc", that is based on the structure Calc containing a top-level
28driver function named parse.
29
30 Calc.parse : unit -> unit
31
32The calculator can be invoked by applying Calc.parse to the unit value.
33
34 - Calc.parse();
35 1+3;
36 result = 4
37
38The calculator reads a sequence of expressions from the standard input
39and prints the value of each expression after reading the expression.
40Expressions must be separated by semicolons. An expression is not
41evaluated until the semicolon is encountered. The calculator
42terminates when an end-of-file is encountered. There is no attempt to
43fix input errors: a lexical error will cause exception LexError to be
44raised, while a syntax error will cause ParseError to be raised.
45
46NOTE: The ML Basis file calc.mlb mentions the ml-yacc library
47(ml-yacc-lib.cm). MLton's search path should be configured so that this
48library will be found. This should normally be the case if MLton is
49properly installed.