Skip to content

misham/prefixer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

First Thing

To build the program, run make help for possible targets.

The program uses prefixer wrapper script for those who do not have and don't want to (or cannot) install Boost library. The script will set the LD_LIBRARY_PATH properly when running the program with the locally built Boost library.

If you have Boost > 1.38.0 installed, all you need to do is run make. See Requirements section below for more info on Boost.

Tests are provided with the library and can be built with make tests. This will also run the tests. You can always run make run_tests to execute the tests again.

There are also 6 examples provided to test with. They are:

  1. 3 * x - 4 + ( 2 * y ) / z
  2. 3 * x + ( 9 + y ) / 4
  3. 3 * 3 + ( 4 + x ) / y
  4. 3 * ( 2 + 4 ) / 2
  5. 3 * ( 2 + 4 ) / x
  6. 3

Run the program with --help option for possible paramaters the program accepts.

Requirements

The program uses Boost library from http://www.boost.org.

You can use the library that came with your distribution as long as the version is > 1.38.0

The library is also provided with the source and can be built on your system. Run make help for instructions on how to build.

Problem

Write a program that given an infix arithmetic expression, outputs a prefix version (the output order is unimportant as long as it evaluates to the same result).

For example:

3 becomes 3
1 + 1 becomes (+ 1 1)
2 * 5 + 1 becomes (+ (* 2 5) 1)
2 * ( 5 + 1 ) becomes (* 2 (+ 5 1))
3 * x + ( 9 + y ) / 4 becomes (+ (* 3 x) (/ (+ 9 y) 4))

The format of the input expression is highly restricted. All values are either single alphabetic characters or positive integers. All operators, including ( and ), are always separated by at least one space from other values or operators.

You should respect operator precedence, so 3 + 5 * 4 should always be parsed as 23, not 32.

Your program should be run from the command line as

prefixer FILE_NAME

where FILE_NAME is the name of a file containing an infix expression.

Final step: Reduce all expressions as much as possible before you output them. This behavior should be triggered by a -r flag.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages