sml Standard ML of New Jersey, Version 110.0.7, September 28, 2000 [CM; autoload enabled] - use "calcLex.lex.sml"; [opening calcLex.lex.sml] GC #0.0.0.0.1.8: (10 ms) GC #0.0.0.1.2.21: (10 ms) GC #0.0.0.1.3.34: (10 ms) structure CalcLex : sig structure Internal : structure UserDeclarations : exception LexError val makeLexer : (int -> string) -> unit -> Internal.result end val it = () : unit - use "rec-descent.sml"; [opening rec-descent.sml] opening CalcLex.Internal structure StartStates : sig datatype yystartstate = STARTSTATE of int val INITIAL : yystartstate end type result = CalcLex.UserDeclarations.lexresult type statedata = {fin:yyfinstate list, trans:string} datatype yyfinstate = N of int exception LexerError val tab : {fin:yyfinstate list, trans:string} vector opening CalcLex.UserDeclarations datatype lexresult = DIV | EOF | EOS | ID of string | LPAREN | NUM of int | PLUS | PRINT | RPAREN | SUB | TIMES val eof : unit -> lexresult val error : string -> unit val linenum : int ref datatype opNode = OP of lexresult datatype synTree = EXP of synTree * synTree | EXP1 of opNode * synTree | Empty | FACTOR of lexresult | TERM of synTree * synTree | TERM1 of opNode * synTree rec-descent.sml:52.11-52.51 Warning: binding not exhaustive (expTree,RPAREN :: rest) = ... rec-descent.sml:15.1-54.10 Warning: match nonexhaustive ID s :: rest => ... NUM n :: rest => ... LPAREN :: more => ... GC #0.0.0.1.4.76: (10 ms) val exp = fn : lexresult list -> synTree * lexresult list val exp1 = fn : lexresult list -> synTree * lexresult list val term = fn : lexresult list -> synTree * lexresult list val term1 = fn : lexresult list -> synTree * lexresult list val factor = fn : lexresult list -> synTree * lexresult list exception SYNTAX_ERROR of lexresult list val allTokens = fn : (unit -> lexresult) -> lexresult list rec-descent.sml:65.1-74.7 Warning: match nonexhaustive nil => ... val parse = fn : unit -> synTree val parse1 = fn : 'a list -> synTree val it = () : unit - use "syn-directed.sml" = ; [opening syn-directed.sml] datatype instruction = DIV_OP | PLUS_OP | PUSH of lexresult | SUB_OP | TIMES_OP syn-directed.sml:4.1-37.42 Warning: match nonexhaustive Empty => ... EXP (termTree,exp1Tree) => ... EXP1 (OP PLUS,expTree) => ... EXP1 (OP SUB,expTree) => ... TERM (factorTree,term1Tree) => ... TERM1 (OP DIV,termTree) => ... TERM1 (OP TIMES,termTree) => ... FACTOR X => ... val genCode = fn : synTree -> instruction list * instruction list val translate = fn : unit -> instruction list val translate1 = fn : synTree -> instruction list val it = () : unit - parse(); val it = EXP (TERM (FACTOR #,TERM1 #),EXP1 (OP #,EXP #)) : synTree - translate (); val it = [PUSH (NUM 1),PUSH (NUM 3),TIMES_OP,PUSH (NUM 4),PUSH (ID "def"), PUSH (NUM 3),PUSH (NUM 4),TIMES_OP,PLUS_OP,TIMES_OP,PUSH (ID "abc"),DIV_OP, ...] : instruction list - drop (it, 10); stdIn:23.1-23.5 Error: unbound variable or constructor: drop - List.drop (it,10); val it = [PUSH (ID "abc"),DIV_OP,PLUS_OP,PUSH (NUM 2),PUSH (NUM 2),TIMES_OP, PUSH (NUM 5),TIMES_OP,PLUS_OP,PUSH (NUM 3),PLUS_OP] : instruction list - ^Dbruce_24% bruce_24% cat testfile 1 * 3 + 4 * (def + ( 3 * 4 )) / abc + 2 * 2 * 5 + 3 bruce_25%