CMPE 152: Compiler Design March 26 – April 16 Labs Department of Computer Engineering San Jose State University Spring 2019 Instructor: Ron Mak www.cs.sjsu.edu/~mak
Today’s Lab: Assignment #5 Write the first draft of the ANTLR 4 grammar file for your source language. Use the Eclipse ANTLR plugin. Generate a syntax diagram from the grammar. Generate a parse tree from the source program. Generate the parser and lexer. For the External Tool Configuration, use: Compile a sample source program. Due: Wednesday, April 17. -no-listener -visitor -encoding UTF-8 -Dlanguage=Cpp
Starter Main Program for Assignment #5 #include <iostream> #include <fstream> #include "antlr4-runtime.h" #include "PclLexer.h" #include "PclParser.h" #include "PclBaseVisitor.h" using namespace std; using namespace antlrcpp; using namespace antlr4; int main(int argc, const char *args[]) { ifstream ins; ins.open(args[1]); ANTLRInputStream input(ins); PclLexer lexer(&input); CommonTokenStream tokens(&lexer); PclParser parser(&tokens); tree::ParseTree *tree = parser.program(); PclBaseVisitor compiler; compiler.visit(tree); return 0; }