Trying a c parser
This commit is contained in:
parent
107f295d7e
commit
e78bc6f54a
|
@ -0,0 +1,22 @@
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
AlignOperands: DontAlign
|
||||||
|
AllowShortBlocksOnASingleLine: Always
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: TopLevel
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BreakBeforeBraces: WebKit
|
||||||
|
IndentCaseLabels: false
|
||||||
|
TabWidth: 4
|
||||||
|
IndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
UseTab: ForContinuationAndIndentation
|
||||||
|
ColumnLimit: 0
|
||||||
|
ReflowComments: false
|
||||||
|
SortIncludes: false
|
||||||
|
SpaceBeforeParens: false
|
|
@ -0,0 +1,15 @@
|
||||||
|
.DS*
|
||||||
|
*jpg~
|
||||||
|
*png~
|
||||||
|
*gif~
|
||||||
|
*bmp~
|
||||||
|
/bin
|
||||||
|
*io.bit
|
||||||
|
*.bak
|
||||||
|
/*-test
|
||||||
|
/screenshot-*.bmp
|
||||||
|
|
||||||
|
*snarf
|
||||||
|
*theme
|
||||||
|
|
||||||
|
*.[o0125678vqki]
|
|
@ -0,0 +1,26 @@
|
||||||
|
RELEASE_flags=-DNDEBUG -O2 -g0 -s
|
||||||
|
DEBUG_flags=-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined
|
||||||
|
|
||||||
|
.PHONY: all debug dest run test install uninstall format clean
|
||||||
|
|
||||||
|
all: dest bin/modal
|
||||||
|
|
||||||
|
dest:
|
||||||
|
@ mkdir -p bin
|
||||||
|
run: all
|
||||||
|
@ bin/modal test.modal
|
||||||
|
test: all
|
||||||
|
@ bin/modal -v
|
||||||
|
@ bin/modal test.modal
|
||||||
|
install: all
|
||||||
|
@ cp bin/modal ~/bin/
|
||||||
|
uninstall:
|
||||||
|
@ rm -f ~/bin/modal
|
||||||
|
format:
|
||||||
|
@ clang-format -i src/modal.c
|
||||||
|
clean:
|
||||||
|
@ rm -fr bin
|
||||||
|
|
||||||
|
bin/modal: src/modal.c
|
||||||
|
@ cc ${DEBUG_flags} ${CFLAGS} src/modal.c -o bin/modal
|
||||||
|
|
2
modal.py
2
modal.py
|
@ -303,7 +303,7 @@ def run(rules, queue, limit=pow(2, 32)):
|
||||||
result, queue = operation(queue, rules, pattern, *parameters)
|
result, queue = operation(queue, rules, pattern, *parameters)
|
||||||
if result == True:
|
if result == True:
|
||||||
failures = 0
|
failures = 0
|
||||||
#print("<>: ", inspect(seek(queue, ["SRT"])))
|
print("<>: ", inspect(seek(queue, ["SRT"])))
|
||||||
#print("<>: ", inspect(queue))
|
#print("<>: ", inspect(queue))
|
||||||
#input()
|
#input()
|
||||||
steps = steps + 1
|
steps = steps + 1
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
walk(FILE *f)
|
||||||
|
{
|
||||||
|
char c, token[0x40], *cptr = token;
|
||||||
|
while(f && fread(&c, 1, 1, f)) {
|
||||||
|
if(c < 0x21) {
|
||||||
|
*cptr++ = 0x00;
|
||||||
|
printf("> %s\n", token);
|
||||||
|
cptr = token;
|
||||||
|
} else if(cptr - token < 0x3f)
|
||||||
|
*cptr++ = c;
|
||||||
|
else
|
||||||
|
return printf("Token too long: %s\n", token);
|
||||||
|
}
|
||||||
|
*cptr++ = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
eval(char *path)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
if(!(f = fopen(path, "r")))
|
||||||
|
return !printf("Invalid file: %s\n", path);
|
||||||
|
walk(f);
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if(argc < 2)
|
||||||
|
return !printf("usage: modal [-v] source.modal\n");
|
||||||
|
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
|
||||||
|
return !printf("Modal - Modal Interpreter, 3 Apr 2024.\n");
|
||||||
|
return !eval(argv[1]);
|
||||||
|
}
|
|
@ -1,7 +1,3 @@
|
||||||
define nil ((0))
|
<> (hello) (bye)
|
||||||
define (pair (?x) (?y)) ((?x ?y))
|
|
||||||
define (first (?x ?y)) (?x)
|
|
||||||
define (second (?x ?y)) (?y)
|
|
||||||
define (quote ?x) (quote ?x)
|
|
||||||
|
|
||||||
define test (first pair (A) (pair (B) (pair (C) nil)))
|
hello world
|
Loading…
Reference in New Issue