|
| 1 | +/* |
| 2 | + * File: README.txt |
| 3 | + * Creator: Adam Kaplan |
| 4 | + * Time-stamp: October 19, 2016 |
| 5 | + * Project 2 |
| 6 | + */ |
| 7 | + |
| 8 | +== General Information == |
| 9 | + |
| 10 | +This project is a recursive descent parser for arithmetic expressions. We had to implement a straight-forward arithmetic descent parser as well as a table-driven one. Furthermore, we also had to create an evaluator for the parse trees created. |
| 11 | + |
| 12 | + |
| 13 | +== How to get it running == |
| 14 | + |
| 15 | +Before anything you have to run |
| 16 | + make |
| 17 | +This will create all of the executables for you. Now you get to customize how you want to run it. |
| 18 | + |
| 19 | + ./main -t -p -e -f test.txt |
| 20 | + |
| 21 | +Here -t is the flag for activating the table-driven parser. By default the straightforward recursive descent parser will be used. |
| 22 | + |
| 23 | +If you want to see the trees to be printed as well, make sure you include the -p flag. |
| 24 | + |
| 25 | +The next flag is the -e one. This one activates the evaluator, which means you will also see the result to each of the expressions in the file. |
| 26 | + |
| 27 | +The last flag is -f, which lets you specify which file to read in and evaluate the expressions from. (Make sure to keep the file in the same folder) |
| 28 | + |
| 29 | + |
| 30 | +== Warnings == |
| 31 | + |
| 32 | +So since I am using the math.h library, I need to include the -lm flag in my makefile. Now on macs CC will say it is useless, but if you want to compile it on the linux machines, it is actually necessary to do that, as otherwise it would just not include the library by default. |
| 33 | + |
| 34 | + |
| 35 | +== Example runs == |
| 36 | + |
| 37 | +For some quick examples you can run any of these commands after you ran the |
| 38 | + make |
| 39 | +command. |
| 40 | + |
| 41 | + ./main -t -p -e -f test.txt |
| 42 | + ./main -p -e -f test.txt |
| 43 | + ./main -t -e -f test.txt |
| 44 | + ./main -e -f test.txt |
| 45 | + ./main -p -f test.txt |
| 46 | + ./main -t -p -f test.txt |
| 47 | + |
| 48 | + |
| 49 | +== File Layout == |
| 50 | + |
| 51 | +The layout of a file such as test.txt should be as follows: |
| 52 | + |
| 53 | + 1+1 |
| 54 | + 2*2-(5+22) |
| 55 | + ... |
| 56 | + |
| 57 | +The important thing here is that the expressions DO NOT INCLUDE SPACES. |
| 58 | + |
| 59 | + |
| 60 | +== Supported Functions == |
| 61 | + |
| 62 | +My grammar supports the following arithmetic expressions: |
| 63 | + |
| 64 | +* Addition |
| 65 | +* Subtraction |
| 66 | +* Multiplication |
| 67 | +* Division |
| 68 | +* Parentheses: (), [], {} |
| 69 | +* Trigonometric functions: sin(), cos(), tan() |
| 70 | +* Logarithm function: log() |
| 71 | +* Factorial: 5! or 5.2! (yup it also calculates factorials for decimal numbers) |
| 72 | +* Power: 5^2 or 5.2^2.5 |
| 73 | + |
| 74 | +My calculator works for all decimals up to 6 decimal places (because I decided more are not usually necessary). |
| 75 | + |
| 76 | +If you were wondering, it uses the gamma function to calculate the factorials, that way I can also do factorials of decimal numbers. |
| 77 | + |
| 78 | + |
| 79 | +== Extra credit == |
| 80 | + |
| 81 | +You can see that I implemented functions such as sin() and factorial. I also added support for decimal numbers in all aspects. |
| 82 | + |
| 83 | + |
| 84 | +== Mentions == |
| 85 | + |
| 86 | +I had some issues with the scanner, so I looked through StackOverflow, sine we never covered how to make a file reader in C. I wrote down the two threads in Stack Overflow that I used in my code. |
| 87 | + |
| 88 | +I also used an article from StackOverflow, because I noticed that I was wrongly concatenating strings, since an empty char pointer does not end with '\0' and therefore I cannot concatenate them together. I also commented the source to my code |
| 89 | + |
| 90 | + |
| 91 | +== File Information == |
| 92 | + |
| 93 | +* declarations.h: This file does all of the necessary library inclusions as well as type declarations. |
| 94 | +* parse_tree.h: This file is the header file for my parse tree. |
| 95 | +* parse_tree.c: This is the actual parse tree. |
| 96 | +* stack.h: Header file for my stack. |
| 97 | +* stack.c: Actual stack file. |
| 98 | +* bool_parser.h: Header file for a very simple implementation of a recursive descent parser which only tells you if an input is parseable or not. |
| 99 | +* bool_parser.c: The actual bool parser. |
| 100 | +* recursive_parser.h: Header file for my straightforward recursive descent parser. |
| 101 | +* recursive_parser.c: The actual straightforward recursive descent parser. |
| 102 | +* table_parser.h: Header file for my table-driven parser. |
| 103 | +* table_parser.c: Actual table-driven parser. |
| 104 | +* evaluator.h: Header file for my evaluator. |
| 105 | +* evaluator.c: My actual evaluator. |
| 106 | +* scanner.h: Header file for my file scanner. |
| 107 | +* scanner.c: My actual scanner file. |
| 108 | +* main.c: The main executable where everything comes together. |
| 109 | +* test.txt: A testing file for my grammar with some random expressions, feel free to modify/use your own. |
0 commit comments