previous                   ToC                next


4.      Parsing


Now we have to specify the syntactic structure of mjava well-formed programs.

By means of Cup, we’ll then transform the parser specification (grammar, conflict resolution directives, ...) into a Java program implementing an LALR parser.

The parser specification of the mjava language is reported in the mjava.cup file, that uses the scanner generated by mjava.flex to perform lexical analysis and then generates the interface and the parser

We have slightly modified the previous version of mjava.flex, by introducing the class to retrieve more detailed information about lexical tokens.


You can generate a parser for mjava and run it on an input program such as SampleProgram.mjava by means of the Windows batch file mjava.bat or the Linux  shell script mjava.spt:

· put the mjava.flex, mjava.cup,, SampleProgram.mjava and mjava.bat / mjava.spt files in a same directory and “cd”  into it

· run mjava.bat / mjava.spt

· the files, and will be generated

· you will get something like SampleProgramParsingResult.txt printed to your Java console.



previous                   ToC                next