CMPE 152: Compiler Design ANTLR 4 and C++

Slides:



Advertisements
Similar presentations
MatLab API in C++ Christopher Dabney. Purpose MatLab … MatLab … is an interpreted scripting language is an interpreted scripting language conversion to.
Advertisements

KEVIN DANIELS ECLIPSE. OVERVIEW Integrated Development Environment (IDE) Usually used to develop applications in various programming languages (C, C++.
CRSX plug-in development. Prerequisites Software and Libraries Eclipse RCP (3.5 or higher) –Go –Select.
 Using Microsoft Expression Web you can: › Create Web pages and Web sites › Set what you site will look like as you design it › Add text, images, multimedia.
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
PARSING FACEBOOK DATA FOR ANDROID 1. Step by Step  Import Android SDK  Get the hash key  Create a new app  Create a new project in Eclipse 
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
Introduction to Android. Android as a system, is a java based operating system that runs on the Linux kernel. The system is very lightweight and full.
CCS APPS CODE COVERAGE. CCS APPS Code Coverage Definition: –The amount of code within a program that is exercised Uses: –Important for discovering code.
WRF Domain Wizard A tool for the WRF Preprocessing System Jeff Smith Paula McCaslin July 17, 2008.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- OpenGL Howto.
Compiled Matlab on Condor: a recipe 30 th October 2007 Clare Giacomantonio.
(1) A Beginner’s Quick Start to SIMICS. (2) Disclaimer This is a quick start document to help users get set up quickly Does not replace the user guide.
File Management Presented to The Glades Computer Club January 4, 2001.
CS 450: COMPUTER GRAPHICS INSTALLING GLUT AND GLEW SPRING 2015 DR. MICHAEL J. REALE.
Prachi Chitnis.  The CSS feel  SDS – Synoptic Display Studio  ADL Converter  PV table, Probe…
Setting Up Eclipse. What is Eclipse? Eclipse is a free, downloadable software that allows us to create, compile, and run JAVA programs.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
Programming with Visual Studio 2005.NET A short review of the process.
Installing Repast in the Eclipse IDE Charlie Gieseler 6/28/04.
CS 153: Concepts of Compiler Design October 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 How to Install OpenGL u Software running under Microsoft Windows makes extensive use of "dynamic link libraries." A dynamic link library (DLL) is a set.
Open project in Microsoft Visual Studio → build program in “Release” mode.
Time to apply stuff… Faculty of Mathematics and Physics Charles University in Prague 5 th October 2015 Workshop 1 – Java Wrestling.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Software Design– Unit Testing SIMPLE PRIMER ON Junit Junit is a free simple library that is added to Eclipse to all automated unit tests. The first step,
HOW TO FIX MSVCR100. DLL IS MISSING ERROR? missing-error.
CLOUD
Development Environment
Getting Eclipse for C/C++ Development
Obtaining the Required Tools
Improving Performance
Java on the LEGO Mindstorms EV3
Download TPL.zip to some directory
Getting started in Eclipse
Bomgar Remote support software
CMPE 152: Compiler Design December 5 Class Meeting
CMPE 152: Compiler Design January 25 Class Meeting
Instructor: Prasun Dewan (FB 150,
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Install Ruby If you are running on Mac OS X, Ruby is preinstalled.
CMPE 152: Compiler Design September 11/13 Lab
JavaTeaching and Importing a github repository
Microsoft Visual Studio
Setting up an Eclipse project from a repository on GitHub
Installing and Using Evolve
Java External Libraries & Case Study
CMPE 152: Compiler Design August 21/23 Lab
CMPE 152: Compiler Design August 28/30 Lab
Setting up CDT Makefile project
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
CMPE 152: Compiler Design April 9 Class Meeting
CMPE 152: Compiler Design March 21 Class Meeting
CMPE 152: Compiler Design February 21/26 Lab
CMPE 152: Compiler Design March 26 – April 16 Labs
Getting Eclipse for C/C++ Development
CS 144 Advanced C++ Programming January 24 Class Meeting
Running a Java Program using Blue Jay.
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Preparation for Assignment 2
Carthage ios 8 onwards Dependency manager that streamlines the process of integrating the libraries into the project.
Working with Libraries
CMPE 135: Object-Oriented Analysis and Design March 14 Class Meeting
CMPE 152: Compiler Design April 18 – 30 Labs
Review of Previous Lesson
Java Code Review with CheckStyle
Introduction to ANTLR Jin Tianxing
CMPE 152: Compiler Design December 4 Class Meeting
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
ECE 3567 Microcontrollers Lab
Presentation transcript:

CMPE 152: Compiler Design ANTLR 4 and C++ Department of Computer Engineering San Jose State University Spring 2018 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Download and Install ANTLR 4 ANTLR is a Java program. Current version is 4.7.1 In order to run it, you must download its binary antlr-4.7-complete.jar. http://www.antlr.org/download/antlr-4.7.1-complete.jar Run on the command line: Tip: Create a script or an alias: java -jar /your/path/to/antlr-4.7/antlr-4.7-complete.jar -Dlanguage=Cpp my.g4 export ANTLR_JAR="/your/path/to/antlr-4.7-complete.jar" export CLASSPATH="$CLASSPATH:$ANTLR_JAR" alias antlr4="java -jar $ANTLR_JAR –Dlanguage=Cpp"

Download and Install the ANTLR 4 Library ANTLR reads a .g4 grammar file and generates .h and .cpp files for a parser, lexer (scanner), and parse tree routines. In order to compile and link these generated compiler files, you need the ANTLR 4 header (.h) files and the ANTLR 4 library. Go to http://www.antlr.org/download.html Scroll down to “C++ target”

The ANTLR 4 Library, cont’d Mac and Linux Install in the standard locations: Header files: /usr/local/include/antlr4-runtime Library files: /usr/local/lib/libantlr4-runtime.* Windows Remember which directory you put the header files in. Unfortunately, the library files you download from the ANTLR site are for Visual Studio C++. Download non-MSVS library files from Remember which directory you put the library files in. http://www.cs.sjsu.edu/~mak/CMPE152/code/antlr4-cpp-runtime-4.7-Windows10.zip

Compile, Link, and Run the Generated Compiler Code To compile and link the ANTLR-generated code, you must use the 2011 dialect of g++ and tell it to use the ANTLR header files and library: If you did not put the library files in the standard location (or if you’re on Windows), you must add the -L option for the library directory before the -l option: For example, to run the executable expr on the input file t.expr: g++ -std=c++0x -I/usr/local/include/antlr4-runtime -lantlr4-runtime -o expr *.cpp -L/your/path/to/lib ./expr t.expr

More Headaches for Windows When you run the the generated compiler in Windows 10, it wants to use the dynamically linked library cygantlr4-runtime-4.7.dll in the lib directory. Therefore, you must first put the lib directory in your execution path. Run the path command to verify it’s there. You may have to restart Windows. If you don't know how to do this, a backup strategy is to copy the .dll file to the same directory as your compiler executable. You still need the -L and -l options to compile and link (previous slide).

Download and Install the Eclipse Plug-in Download and install the latest version “Oxygen” of Eclipse CDT (C/C++ Development Tooling) from https://www.eclipse.org/cdt/ Follow the instructions at https://github.com/jknack/antlr4ide under “Eclipse Installation”. Use the “Oxygen” version of Eclipse, not “Luna”. Ignore the software version numbers. Install the latest versions of the software.

An ANTLR Eclipse Project Create a new C++ project. Not an ANTLR 4 project, which is for Java. Copy all the .h and .cpp files that you’ve previously generated by running ANTLR on the command line. Include the .g4 file and any .h and .cpp files you’ve written, and any input files.

An ANTLR Eclipse Project, cont’d Open the project’s Property sheet. C/C++ Built  Settings C++ Compiler  Dialect Language standard: Choose “ISO C++11” C++ Compiler  Includes Include paths (-I): /usr/local/include/antlr4-runtime (or wherever you put the ANTLR header files) Linker  Libraries Libraries (-l): antlr4-runtime Library search path (-L): The directory where you put the ANTLR 4 libraries if they’re not in the standard place.

An ANTLR Eclipse Project, cont’d Now you can compile and run as you would any other C++ program. Unfortunately, there’s no way to tell the Eclipse plug-in not to generate Java files from the .g4 grammar file but to generate C++ files instead. The plug-in may insist on generating Java files.

An ANTLR Eclipse Project, cont’d To turn off automatic file generation in Eclipse: Open the properties sheet of the project. Click on ANTLR 4  Tool Uncheck ”Enable project specific settings” Click on the link “Configure Workspace Settings ...” Uncheck “Tool is activated” This means that you must run ANTLR on the command line outside of Eclipse if you want to generate new compiler files. Then copy the new files into your Eclipse project.

An ANTLR Eclipse Project, cont’d To generate a syntax diagram in Eclipse: Eclipse Window menu  Other ...  Syntax Diagram That creates a Syntax Diagram tab at the bottom

An ANTLR Eclipse Project, cont’d To generate a parse tree in Eclipse: Eclipse Window menu  Show View  Other ...  Parse Tree That creates a Parse Tree tab at the bottom Open your .g4 grammar file in Eclipse. Open the Parse Tree tab. Click the name of the starting rule of your grammar. Copy the text of your source program into the left pane of the Parse Tree tab. Make sure the last line ends in a line feed. The parse tree appears in the right pane.