TestLex.mesa, test program for Lex822.
Last edited by HGM, February 27, 1984 9:29:38 pm PST
Last edited by Nichols.pa, June 7, 1983 4:55 pm
Last Edited by: Taft, September 13, 1983 10:41 am
DIRECTORY
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Failed, Parse],
FS USING [Error, StreamOpen],
IO USING [STREAM, PutF, PutRope, rope],
Lex822,
Rope USING [ROPE, Cat, Length, Equal];
TestLex: CEDAR PROGRAM
IMPORTS Commander, CommandTool, FS, IO, Rope, Lex822
= BEGIN
LexMessage: Commander.CommandProc = {
argv: CommandTool.ArgumentVector = CommandTool.Parse[cmd !
CommandTool.Failed => {cmd.out.PutRope[errorMsg]; GOTO GoAway}];
file: IO.STREAM ← FS.StreamOpen[argv[1] !
FS.Error => {cmd.out.PutRope[error.explanation]; GOTO GoAway}];
token, whiteSpace: Rope.ROPE;
tokType: Lex822.TokenType;
DO
token ← Lex822.LexFieldName[file].fieldName;
IF Rope.Equal[token, "\n"] THEN ERROR
ELSE IF token.Length[] = 0 THEN EXIT;
cmd.out.PutRope[token.Cat["\n"]];
DO
[token, whiteSpace, tokType] ← Lex822.LexToken[file];
IF tokType = errorTok THEN cmd.out.PutRope["** Error **\n "];
cmd.out.PutF["\"%h\", \"%h\"\n", IO.rope[whiteSpace], IO.rope[token]];
IF tokType = EOLTok THEN EXIT;
ENDLOOP;
ENDLOOP;
EXITS
GoAway => NULL
};
Commander.Register["Lex822", LexMessage, "Do a lexical analysis of a message (in a file)."];
END.