Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vlasami6/ni-run-template
  • chybijan/ni-run
  • ruzict16/FML
  • rozhovoj/ni-run-template
  • skrabmir/cfml
  • plodeada/ni-run-plodeada
  • stepam38/ni-run
  • hrncikar/ni-run
  • balikvo1/ni-run
9 results
Show changes
Commits on Source (2)
......@@ -6,4 +6,22 @@ test:
- meson compile -C build
- cppcheck --error-exitcode=1 *.c
- env FML="$(readlink -f ./build/fml)" FML_REF_BC_INT=/cfml/fml /FMLtest/suite ast_interpret
hello_world.fml
# hello_world.fml
hello_world
literals
variables
conditionals
loops
functions
function_value
builtins
# arrays
# iterator
# fibonacci
# fizzbuzz_fun
# fizzbuzz_loop
# roman
# stack
# brainfuck
# langtons_ant
#sudoku
CC=gcc
CFLAGS=-Wall -pedantic -Wextra -g
LFLAGS=
OUTPUT=fml
SRC_DIR=./src
BUILD_DIR=./build
.PHONY: init fml
all: init fml
fml: $(BUILD_DIR)/arena.o $(BUILD_DIR)/parser.o $(SRC_DIR)/fml.c #$(BUILD_DIR)/%.o
$(CC) $(CFLAGS) $(LFLAGS) $? -o $(OUTPUT)
%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/parser.o: $(SRC_DIR)/parser.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/arena.o: $(SRC_DIR)/arena.c
$(CC) $(CFLAGS) -c $< -o $@
init:
mkdir -p build
File moved
File moved
File moved
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <ctype.h>
#include "arena.h"
#include "parser.h"
#define AST_INTERPRETER_COMMAND "ast_interpret"
#define RUN "run"
#define MAX_ARG_LEN 20
int main ( int argc, char **argv ) {
if ( argc < 2 ) {
fprintf( stderr, "Error: expected at least one argument\n" );
return 1;
}
u8 flag = 0;
u8 ast_interpret = 0;
size_t len;
for ( int arg = 1; arg < argc; ++arg ) {
len = strlen ( argv [ arg ] );
if ( len > MAX_ARG_LEN ) {
fprintf( stderr, "Error: unsupported argument.\n" );
flag = 1;
}
for ( size_t j = 0; j < len; j++ )
argv [ arg ] [ j ] = tolower ( argv [ arg ] [ j ] );
if ( strncpy ( argv [ arg ], AST_INTERPRETER_COMMAND, len ) == 0 )
ast_interpret = 1;
else if ( strncpy ( argv [ arg ], RUN, len ) == 0 )
ast_interpret = 1;
else {
fprintf( stderr, "Error: unsupported argument.\n" );
flag = 1;
}
}
if ( flag )
return 1;
Arena arena;
arena_init( &arena );
Ast *ast = parse_src ( &arena, (Str) { .str = (u8 *) argv[1], .len = strlen(argv[1]) } );
if ( ast == NULL ) {
fprintf ( stderr, "Failed to parse source\n" );
arena_destroy ( &arena );
return 1;
}
if ( ast_interpret )
return 88;
arena_destroy( &arena );
return 0;
}
File moved
File moved