Skip to content

Commit df0592d

Browse files
Fixed: linking errors (#1)
* added lexer and updated docs * Fixed: linking errors * fixed clang tidy errors and added panic mode for lexing * added main file dummy tests Co-authored-by: Shuvayan Ghosh Dastidar <[email protected]>
1 parent 636f40a commit df0592d

File tree

16 files changed

+495
-22
lines changed

16 files changed

+495
-22
lines changed

.github/workflows/build_tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ jobs:
4747
working-directory: ./build
4848
run: |
4949
bash <(curl -s https://codecov.io/bash)
50-

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,41 @@ This is the official Jadavpur University Compiler Compiler repository.
1616
The JuCC project is built and tested on **Ubuntu 20.04**.
1717

1818
```
19-
git clone https://github.com/TheSYNcoder/JuCC
20-
cd JuCC
21-
sudo ./script/installation/packages.sh
22-
mkdir build
23-
cd build
24-
cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
25-
ninja jucc
26-
./bin/jucc
19+
$ git clone https://github.com/TheSYNcoder/JuCC
20+
$ cd JuCC
21+
$ sudo ./script/installation/packages.sh
22+
$ mkdir build
23+
$ cd build
24+
$ cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
25+
$ ninja jucc
26+
$ ./bin/jucc
2727
```
2828

29+
To run the unit tests provided,
30+
31+
```
32+
$ mkdir build
33+
$ cd build
34+
$ cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
35+
$ ninja
36+
$ ninja test
37+
38+
```
39+
40+
Before pushing or making a pull request
41+
42+
```
43+
$ ninja
44+
$ ninja check-format
45+
$ ninja check-clang-tidy
46+
$ ninja check-lint
47+
$ ninja test ( The tests must pass, compulsory !! )
48+
49+
```
50+
51+
To add a new unit test, make a folder with the same relative path as in the src folder, and define your test. Please refer to [docs](https://github.com/TheSYNcoder/JuCC/tree/main/docs/) for more details about writing tests using the [googletest](https://github.com/google/googletest) framework.
52+
53+
2954
Additional Notes:
3055
- If you know what you're doing, install the prerequisite packages from `./script/installation/packages.sh` manually.
3156

docs/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ You should learn a little about the following:
3737
- You should know these targets.
3838
- `jucc`: Building will build the `jucc` binary and all its dependencies.
3939
- `jucc_benchmark`: Building will build and link the `jucc` object file to the `benchmark` library. Running will run the benchmarks.
40-
- `test`: Building will run all unit tests using `gtest`.
40+
- `test`: Building will run all unit tests using `gtest`. This will not show specifics of failed test, run `build/bin/jucc_test` for detailed info.
4141
- `format`: Building will run the formatter `clang-format` on the codebase with our rules. Use this every time right before you commit and right before you make a pull request!
4242
- `check-format`: Building will check if the codebase is correctly formatted according to `clang-format` with our rules.
4343
- `check-clang-tidy`: Building will check if the codebase passes the `clang-tidy` static analyzer tests with our rules.
@@ -65,7 +65,13 @@ If you run into issues, you may need your default `python` to point to a `python
6565

6666
### Running tests locally
6767

68-
Use `make test` or `ninja test` to run inside your build folder.
68+
Use `make test` or `ninja test` to run inside your build folder to run all tests.
69+
70+
For detailed test info:
71+
1. Go to the folder: `cd ~/JuCC/build`
72+
2. Generate optimized config with `cmake -GNinja .. -DCMAKE_BUILD_TYPE=Release`
73+
3. Build project with `ninja`
74+
4. Run `./bin/jucc_test`
6975

7076
### Benchmarks
7177

docs/cpp_guidelines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ If you need to do complex debugging, you may want to check out the following lin
111111

112112
Unit tests are critical for ensuring the correct functionality of your modules and reduce time spent on debugging. It can help prevent regressions. We use [googletest](https://github.com/google/googletest), a nice unit-testing framework for C++ projects.
113113

114-
You should write unit test cases for each class/algorithm that you have added or modified. See the testing section for detail. Try to come up with test cases that make sure that the module exhibits the desired behavior. Some developers even suggest writing the unit tests before implementing the code. Make sure that you include corner cases, and try to find off-by-one errors.
114+
You should write unit test cases for each class/algorithm that you have added or modified. See the testing section for detail. Try to come up with test cases that make sure that the module exhibits the desired behavior. Some developers even suggest writing the unit tests before implementing the code. Make sure that you include corner cases, and try to find off-by-one errors.
115115

116116
## Documentation
117117

docs/tech_clangtools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Check the [official documentation](https://clang.llvm.org/docs/ClangFormat.html)
6666

6767
**Gotchas**
6868

69-
1. We use the [run_clang_format.py](https://github.com/TheSYNcoder/JuCC/blob/master/build_support/run_clang_format.py) to automate the workflow.
69+
1. We use the [run_clang_format.py](https://github.com/TheSYNcoder/JuCC/blob/main/build_support/run_clang_format.py) to automate the workflow.
7070

7171
## Summary
7272

docs/tech_git.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ Stash is very useful. For example, you will use it before/after (push/pop) merge
2222
* view content of your stash: git stash show -p `stash@\{0\}`
2323

2424
### Rebase or how to screw the history
25-
**Never** rebase commits that were pushed remotely. Rebase can be used to improve your current patch set, or to fast-forward-merge after a fetch. For better software engineering we **never** directly merge the upstream master when doing local development. When accepting a PR, we expect you to fetch the upstream master to your local repository, and rebase all the changes in your local branch on top of the upstream master.
26-
* The rebase command: git rebase -i `<upstream master branch>`
25+
**Never** rebase commits that were pushed remotely. Rebase can be used to improve your current patch set, or to fast-forward-merge after a fetch. For better software engineering we **never** directly merge the upstream main when doing local development. When accepting a PR, we expect you to fetch the upstream main to your local repository, and rebase all the changes in your local branch on top of the upstream main.
26+
* The rebase command: git rebase -i `<upstream main branch>`
2727
* Cancel it : git rebase --abort
2828
* Resolve conflict: git mergetool `<file>`
2929
* Continue rebase: git rebase --continue
3030

3131
### Branch or how to separate your work by feature
32-
Please note that master is actually the default branch
32+
Please note that main is actually the default branch
3333
* List branches: git branch -v
3434
* Switch to another branch: git checkout `<branch>`
3535
* Creates: git branch `<branch>`
@@ -39,11 +39,11 @@ Please note that master is actually the default branch
3939
# Git use case example
4040

4141
### Branch management
42-
Let's say you want to rebase your current branch topic-v1 to topic-v2 with new additions. Note: topic-v1 could also be master too.
42+
Let's say you want to rebase your current branch topic-v1 to topic-v2 with new additions. Note: topic-v1 could also be main too.
4343
* Go to current branch: git checkout topic-v1
4444
* Create a new one: git branch topic-v2
4545
* Go into the new branch: git checkout topic-v2
46-
* Set the reference: git branch --set-upstream-to=origin/master topic-v2
46+
* Set the reference: git branch --set-upstream-to=origin/main topic-v2
4747
* Rebase: git rebase -i
4848
* ...
4949

src/include/lexer/lexer.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#ifndef JUCC_LEXER_H
2+
#define JUCC_LEXER_H
3+
4+
#include <cctype>
5+
#include <cstdio>
6+
#include <fstream>
7+
#include <iostream>
8+
#include <string>
9+
10+
namespace jucc {
11+
12+
enum Token {
13+
TOK_EOF = -1,
14+
TOK_IDENTIFIER = -2,
15+
TOK_DECIMAL = -3,
16+
TOK_FRACTIONAL = -4,
17+
18+
// Conditionals
19+
TOK_IF = -6,
20+
TOK_ELSE = -7,
21+
22+
// Data types
23+
TOK_INT = -8,
24+
TOK_FLOAT = -9,
25+
TOK_VOID = -10,
26+
// error
27+
TOK_ERROR = -100,
28+
29+
// punctuation tokens
30+
31+
TOK_SEMICOLON = -11, // ;
32+
TOK_CURLY_OPEN = -12, // {
33+
TOK_CURLY_CLOSE = -13, // }
34+
TOK_PAREN_OPEN = -14, // (
35+
TOK_PAREN_CLOSE = -15, // )
36+
TOK_DOT = -16, // .
37+
TOK_COMMA = -17, // ,
38+
TOK_LEFT_SHIFT = -18, // <<
39+
TOK_RIGHT_SHIFT = -19, // >>
40+
TOK_LESS_THAN = -20, // <
41+
TOK_GREATER_THAN = -21, // >
42+
TOK_EQUAL_TO = -22, // ==
43+
TOK_ASSIGNMENT = -23, // =
44+
TOK_COMMENT = -24, // //
45+
TOK_LITERAL = -25, // "c++"
46+
TOK_CHARACTER = -26, // 'c'
47+
48+
// cout, cin
49+
50+
TOK_COUT = -27, // cout
51+
TOK_CIN = -28, // cin
52+
};
53+
54+
class Lexer {
55+
public:
56+
/**
57+
* used to store a identifier token
58+
*/
59+
std::string identifier_string_;
60+
/**
61+
* used to store a corresponding error token
62+
* suppose a numerical token 16.3ere which is
63+
* neither a numerical token or a identifier
64+
*/
65+
std::string error_string_;
66+
/**
67+
* used to store a literal string
68+
* literal strings are of type "a string"
69+
*/
70+
std::string literal_string_;
71+
/**
72+
* used to store the value of the integer token
73+
* during tokenization.
74+
*/
75+
int intval_;
76+
/**
77+
* used to store the value of the float token
78+
* during tokenization.
79+
*/
80+
double floatval_;
81+
82+
/**
83+
* Takes a ifstream object as input and gets the next character
84+
* from the input file and returns the appropriate token.
85+
*/
86+
int GetToken(std::ifstream &is);
87+
}; // class Lexer
88+
89+
} // namespace jucc
90+
91+
#endif

src/include/main/jucc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#define JUCC_JUCC_H
33

44
#include <iostream>
5+
#include <string>
56

67
namespace jucc {
78
/**
89
* Dummy function to test setup clang and build config
910
*/
10-
void Hello();
11+
std::string Hello();
1112

1213
/**
1314
* Dummy function increments computes x + y the retarded way

0 commit comments

Comments
 (0)