Skip to content

Commit 2648e01

Browse files
committed
Merge branch 'awesome-intro' of https://github.com/sachinkamath/explore-git into sachkat1
2 parents d811ed3 + d8c0f38 commit 2648e01

26 files changed

+830
-1
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@
2626
*.exe
2727
*.out
2828
*.app
29+
30+
# Code Blocks things
31+
*.cbp
32+
*.depend
33+
*.layout
34+
35+
# Other
36+
37+
*wiki*

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#CONTRIBUTING
22

3+
Fork this repo, make changes, test code, submit pr.
4+
***
5+
***Comment on the issue to let everyone know you are working on it. Why should 14 people develop just 1 feature which can be developed by a far less number of people and there are numerous other things to work on?
6+
Be responsible.***
7+
***
38
The aim of the event is to **Teach Git Hands-On**. Due to time constraints, the projects we provide for hacking ***cannot***
49

510
- be difficult, the aim is to learn `git` and not computer science.

cpp/liquid/Makefile

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ADD THE SOURCE FILE NAME THAT YOU HAVE JUST CREATED to the `src_files` VARIABLE.
2+
# FOLLOW THE CONVENTION:
3+
# prefix function name with `ml_`
4+
#
5+
# run:
6+
#
7+
# $ make liquid
8+
#
9+
# YOU'LL FIND AN EXECUTABLE CALLED `liquid`
10+
#
11+
# launch it using
12+
#
13+
# $ ./liquid
14+
15+
# ADD THE FILE NAME HERE
16+
# \/\/\/\/\/\/\/\/\/\/\/
17+
src_files = ml_add \
18+
ml_sub \
19+
ml_mul \
20+
ml_div \
21+
ml_mod \
22+
ml_power \
23+
ml_perms \
24+
ml_combos \
25+
ml_isPrime \
26+
ml_nextPrime \
27+
ml_factorial \
28+
ml_factorise \
29+
ml_gcd \
30+
ml_lcm
31+
32+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
33+
# DON'T TOUCH BELOW THIS #
34+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
35+
36+
srcdir = src/
37+
build_dir = build/
38+
39+
DEPS = math-lib.h
40+
41+
CFLAGS = -Wall -std=c99 -c -I. -I$(srcdir)
42+
LDFLAGS = -lm
43+
SOURCES = $(src_files:%=$(srcdir)%.cpp)
44+
OBJECTS = $(src_files:%=$(build_dir)%.o)
45+
46+
# $@ is TARGET
47+
# $< is first pre-requisite
48+
# $^ is space-separated list of all pre-requisites
49+
50+
$(build_dir)%.o: $(srcdir)%.c $(srcdir)math-lib.h
51+
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
52+
53+
%.o: %.c shunting-yard.h stack.h $(DEPS)
54+
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
55+
56+
liquid: liquid.o $(OBJECTS) shunting-yard.o stack.o
57+
$(CC) -Wall -std=c99 -I $(srcdir) -I. $? -o $@ $(LDFLAGS)
58+
59+
again: clean liquid
60+
61+
test:
62+
./liquid
63+
64+
clean:
65+
@rm build/*.[ao]
66+
@rm *.[ao]

cpp/liquid/README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#The `liquid`
2+
3+
`liquid` is a simple CLI math application that can solve simple math problems.
4+
5+
#How is the code organised?
6+
7+
This is the directory structure:
8+
```
9+
└── liquid
10+
├── liquid.cpp
11+
├── testing.cpp
12+
├── shunting-yard.cpp
13+
├── shunting-yard.h
14+
├── Makefile
15+
└── src
16+
├── math-lib.h
17+
├── ml_add.cpp
18+
├── ml_div.cpp
19+
├── ml_mul.cpp
20+
├── ml_sub.cpp
21+
├── .
22+
├── .
23+
├── .
24+
└── ml_*****.cpp
25+
```
26+
27+
28+
We've already made the CLI which can be used to input a math expression and get the result.
29+
>Credit: @bamos for implementing the Shunting-Yard Algorithm in `cpp`.
30+
It's basically the RPN expression parser, which pushes into a `stack` to parse an expression and then evaluate based on priority rules by `popping` the `stack`.
31+
32+
The name of the CLI file is `liquid.cpp`. *You don't have to edit `liquid.cpp`.*
33+
34+
#What do I edit?
35+
36+
See the `src/` directory? Read `math-lib.h`. This is the list of functions that provide the computational functionality to `liquid`.
37+
```
38+
double ml_add(double, double);
39+
double ml_mul(double, double);
40+
double ml_div(double, double);
41+
double ml_sub(double, double);
42+
43+
```
44+
But, except the `add`, `mul`, `div`, and `sub`, files, the rest are empty.
45+
And there's also a template file (`ml_template.cpp`).
46+
47+
#Appendix
48+
49+
**CLI**
50+
*Command Line Interface. It means a* **terminal** *is opened for the user, not a GUI.*

cpp/liquid/liquid.c

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "shunting-yard.h"
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include <stdlib.h>
5+
/*
6+
* DONT EDIT THIS FILE!
7+
* See the wiki, for a list of keywords that are understood by Liquid.
8+
*/
9+
10+
void strip_wspace(char *ipstr, char* stripped){
11+
int i, j = 0;
12+
for (i=0; ipstr[i] != '\0' && i<99; i++){
13+
if (ipstr[i] != ' ')
14+
stripped[j++] = ipstr[i];
15+
}
16+
stripped[j] = '\0';
17+
//printf("%s\n", stripped);
18+
}
19+
20+
int main(int agrc, char *argv[]){
21+
double result;
22+
char input[100], stripped[100];
23+
int i,j;
24+
//Introduction
25+
system("cowsay 'Welcome to the awesome calculator. Moo!'");
26+
printf("Liquid is a smooth CLI math expression evaluator.\nEnter expressions, you need to match all parens.\n\nSee the wiki to know the keywords understood by Liquid\nTo quit just type 'Q'\n");
27+
while(1)
28+
{
29+
printf("<< ");
30+
gets(input);
31+
if(strcmp(input,"Q")==0)
32+
break;
33+
strip_wspace(input, stripped);
34+
Status response = shunting_yard(stripped, &result);
35+
printf(">> %f\n", result);
36+
}
37+
return 0;
38+
}

0 commit comments

Comments
 (0)