/blocks.c (176e50b9b24ded89c009136a2386586cacd5fcd2) (1431 bytes) (mode 100644) (type blob)
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "blocks.h"
#include "misc.h"
struct block_start {
int lineno;
enum block_type type;
};
static struct block_start *blocks = NULL;
static size_t size = 0;
static size_t capacity;
static char* names[] = { "function", "loop", "if" };
void block_push(int lineno, enum block_type type){
if(! blocks){
capacity = 7;
blocks = malloc(sizeof(struct block_start) * capacity);
}else if(size >= capacity){
capacity *= 2;
blocks = realloc(blocks, capacity * sizeof(struct block_start));
}
blocks[size].type = type;
blocks[size].lineno = lineno;
size++;
}
bool block_pop(enum block_type type, char *buf, size_t len){
if(size == 0){
// Standalone end* found
snprintf(buf, len, "Standalone %s (no corresponding opening block)", names[type]);
return false;
}
if(blocks[size-1].type != type){
// Missing end* for blocks[size-1].type
snprintf(buf, len, "Missing end%s for block openend in line %d", names[blocks[size-1].type], blocks[size-1].lineno);
return false;
}
size--;
return true;
}
void block_missing_error(char *msg, size_t len){
if(size == 0){
return;
}
snprintf(msg, len, "Missing end%s for block opened in line %d.", names[blocks[size-1].type], blocks[size-1].lineno);
size--;
}
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
170 |
28f83f8deb57bbc09c713a866975355fd9225827 |
.gitignore |
100644 |
blob |
48 |
3bfb16e6c32903fb8e4db429b412ee6e8ef23a14 |
AUTHORS |
100644 |
blob |
3557 |
a62ad00cdae7cd8a72c80d1d6ce2796e53b6d58c |
GNUmakefile |
100644 |
blob |
1313 |
4dc80d23e5c4804173171f9e03724a7d9fff66a1 |
LICENSE |
100644 |
blob |
1431 |
176e50b9b24ded89c009136a2386586cacd5fcd2 |
blocks.c |
100644 |
blob |
284 |
fe2c87b1e497bec19349f6250c1be9552b956e09 |
blocks.h |
100755 |
blob |
428 |
cc6218cbb759cfd1deef9a20b246b8ed7697bd02 |
check.sh |
100755 |
blob |
273 |
b0e5e8c7418adb04f6a7d76e9c011b4ba4ef3092 |
fail.sh |
100644 |
blob |
266 |
88a7c9f4c9cfca968c1b863d4fd49131b5c2e175 |
funcdecl.c |
100644 |
blob |
276 |
f409be6b975f0a454de860058f1bf91849f1de96 |
funcdecl.h |
100644 |
blob |
22110 |
8c657ae69ee3b922184ea8f413911dae2cfd9d6e |
grammar.y |
100644 |
blob |
1684 |
3f87f5c4542560d5ded7bd36438657a5869771ca |
hashtable.c |
100644 |
blob |
501 |
2185dc1cb949f6fa3a1b0985b4caaf7769456156 |
hashtable.h |
100644 |
blob |
6470 |
e50f3c6407908ffbd851b8de72229baf649c3e64 |
main.c |
100644 |
blob |
24835 |
d8c7e95fd1820e4ecb3bc360399c46c04a2555ae |
misc.c |
100644 |
blob |
4829 |
9aec7195b5a40740b417910a6a3e2a60966b4eda |
misc.h |
100644 |
blob |
330 |
92a4597d6df5097c58649391541d54f06b3bda1b |
paramlist.c |
100644 |
blob |
256 |
bb253362ef26a0ea881856aebeb8503fb82646fb |
paramlist.h |
100644 |
blob |
3680 |
0d3a55aa2bd7911e71390008b7723399c094eba1 |
readme.md |
100644 |
blob |
2441 |
ea188616a23838fd64aceadf9bd596b0b19bb20c |
sstrhash.c |
100644 |
blob |
135 |
c5326df74bb15edc131620941e0d4dc25ef2abb4 |
sstrhash.h |
040000 |
tree |
- |
75397ec6ff0b0aaa3c97aadebdae1dfc50cc49c0 |
tests |
100644 |
blob |
6893 |
3557a23418579be48085fe5e8ec0733bf3f68965 |
token.l |
100644 |
blob |
1287 |
753fde490a39a9c775f5565af6ea5e6a8b64d419 |
tree.c |
100644 |
blob |
356 |
d943f2d407216cea33c9931439d6802af7d08ce6 |
tree.h |
100644 |
blob |
2502 |
fee7aee3384745b8f13f8b98870814cc109981b6 |
typeandname.c |
100644 |
blob |
914 |
c7c2ecbf5459c7cb80bd2661e6ca78c32a780e10 |
typeandname.h |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/vrtc/pjass
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/vrtc/pjass
Clone this repository using git:
git clone git://git.rocketgit.com/user/vrtc/pjass
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main