Monday, April 18, 2011

Implementing a Lexical Analyzer and Parser

I recently involved in implementing a lexical analyzer and a parser. These were implemented to tokenize and parse a defined language “C-“ with specified conventions and grammar. For this I used JavaCC which is a lexical analyzer generator and a parser generator. The intension of the lexical analyzer was to tokenize the given input file. It will reject the input file if it is not according to the conventions of the C- language. The tokens generated in the lexical analyzer were used for parser. Parser will check the sequence of tokens and validate the grammar for C-.

Here I simply came with two files, LexAnalyzer.jj for tokenizing the input file and validate the generated tokens with C- specified tokens and MyParser.jjt file with the specified the grammar rules for the defined language and to validate whether the input file has been written in accordance with C- grammar. JavaCC which generates all the underline code, made my job much easy.

LexAnalyzer.jj
MyParser.jjt

No comments:

Post a Comment