UP | HOME

Infix2postfix Exercise
COP-3402

Table of Contents

1. Overview

In this project you will create an infix2postfix translator using the ANTLR parsing framework for C++.

2. Project setup and usage

The project has three required files:

File Description
Arithmetic.g4 The grammar file
infix2postfix.cpp The translator program
Makefile The build script

Be sure that all three files are in the root of your git repository.

2.1. infix2postfix.cpp

Hand-type by yourself the infix2postfix.cpp program shown in the image below. Receiving a copy of the text of this program or copying in any other way besides personally typing it out yourself is unauthorized assistance.

infix2postfix.cpp.png

2.2. Setup

mkdir -p ~/cop3402spring25/infix2postfix
cd ~/cop3402spring25/infix2postfix
wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402spring25/files/Arithmetic.g4
wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402spring25/files/Makefile

2.3. Compiling

To build your project, run make

make

If you see the following warnings, you can ignore them:

g++ -I /usr/include/antlr4-runtime -c ArithmeticBaseListener.cpp
In file included from /usr/include/antlr4-runtime/atn/PredictionContext.h:10,
                 from /usr/include/antlr4-runtime/LexerInterpreter.h:9,
                 from /usr/include/antlr4-runtime/antlr4-runtime.h:32,
                 from ArithmeticBaseListener.h:7,
                 from ArithmeticBaseListener.cpp:5:
/usr/include/antlr4-runtime/atn/ATNState.h:73:26: warning: type attributes ignored after type is already defined [-Wattributes]
   73 |   class ANTLR4CPP_PUBLIC ATN;

2.4. Running

echo "1+2" | ./infix2postfix 

Here are several example runs of the translator:

$ echo "1+2" | ./infix2postfix 
12+
$ echo "1+2*3" | ./infix2postfix 
123*+
$ echo "1+2*3+4" | ./infix2postfix 
123*+4+

3. Submitting your project

3.1. git setup

Be sure to complete the git exercise before attempting this project.

Create a new local repository, following the directions in the git exercise (including running git push --set-upstream submission master in the last step). Instead of using hello, set the local and remote repository URLs to be the following locations:

Local repository ~/cop3402spring25/infix2postfix
Remote repository gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/infix2postfix

3.2. Commands to setup your repo

These steps only setup the repo, do not submit your code, and assume you have already completed the git exercise. Consult that exercise for specifics on validating each step and submitting your code.

mkdir -p ~/cop3402spring25/infix2postfix
cd ~/cop3402spring25/infix2postfix
git init
echo "infix2postfix project" > README.md
git add README.md
git commit README.md
# Enter a commit message in the editor that pops up
git remote add submission gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/infix2postfix
git push --set-upstream submission master

3.3. Adding, commit, and pushing your project files

See the hello project for instructions on using git to submit your project.

3.4. Self-check

See the hello project for instructions on cloning a project from the grading server.

4. Grading schema

Criterion Points
The git repo exists 1
The repo contains the three required files 1
The program builds 1
The program runs correctly 1
TOTAL 4

Author: Paul Gazzillo

Created: 2025-03-25 Tue 07:48

Validate