CpSc 423, Language Processor Techniques

Assignment 1

due March 11

Lexical Analyzer

Your first project is to write a scanner for the example programming language. You may use C or C++; if you wish to use another programming language, please contact me.

The scanner should take an input filename on the command line (e.g., lex filename) and produce a list of tokens on standard output.

Output

The output should contain each token, its corresponding lexeme, and the corresponding line number, one per line. For example, the input file:

IF x = 4 THEN
	x := x + 1;
	WriteLn(x)
END

should yield output similar to the following:

1	KEYWORD			IF
1	IDENTIFIER		x
1	RELATIONAL_OPERATOR	=
1	INTEGER			4
1	KEYWORD			THEN
2	IDENTIFIER		x
2	ASSIGNMENT		:=
2	IDENTIFIER		x
2	ARITHMETIC_OPERATOR	+
2	INTEGER			1
2	SEMICOLON		;
3	IDENTIFIER		WriteLn
3	LEFT_PARENTHESIS	(
3	IDENTIFIER		x
3	RIGHT_PARENTHESIS	)
4	KEYWORD_END		END

Notes