Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new interpreter #409

Open
RodrigoDornelles opened this issue Jun 12, 2023 · 6 comments
Open

new interpreter #409

RodrigoDornelles opened this issue Jun 12, 2023 · 6 comments
Assignees

Comments

@RodrigoDornelles
Copy link
Owner

RodrigoDornelles commented Jun 12, 2023

@startuml
start
repeat
repeat :read char;
repeat while (line end?) is (no) not (yes)
repeat :parse line;
repeat while (multine line?) is (yes) not (no)
if (has label?) then (no)
break
else (yes)
endif
repeat while (label pos?) is (forward) not (backward)
repeat :commit;
repeat while (more lines?) is (yes)
stop
@enduml

related #408

@RodrigoDornelles RodrigoDornelles self-assigned this Jun 12, 2023
@RodrigoDornelles
Copy link
Owner Author

/**
 * @file interpreter.c
 * @brief Program example for a 3bc syntax interpreter
 * using a single virtual machine.
 */

#include "lang_3bc.h"
#include "driver_stack.h"
#include "driver_interrupt.h"

int main(int argc, char** argv)
{
    int exitcode = -1;
    static uint8_t stack[255];
    static uint8_t vm[TBC_MACHINE_SIZE];

    driver_stack_init(vm, stack, sizeof(stack));
    lang_3bc_cli_init(vm, argc, argv);

    while (exitcode == -1) {
        lang_3bc_cli_compile(vm);
        exitcode = driver_interrupt(vm);
    }

    return exitcode;
}

@RodrigoDornelles
Copy link
Owner Author

#!/usr/bin/env 3bc
MODE 0 6
ALOC 'i' 3


LOOP:
MODE 0 0d02
STRC 0 'H'
STRC 0 'I'
STRC 0 '!'
STRC 0 0xA

MODE 0 0d08
PUSH 'i' 0

MODE 0 0d12
MATH 0 1

MODE 0 0d08
PULL 'i' 0

MODE 0 9
FGTO 0 $LOOP

@RodrigoDornelles
Copy link
Owner Author

RodrigoDornelles commented Jul 7, 2023

@startebnf

line = instruction, [comment] | comment | tag;

instruction = register, address, constant;

comment = ("#" | ";"), {?any ASCII character? (* Ignore everything until\nline break or end of file *)}-;

register = mnemonic | number | nill;

address = character | number | hash | nill;

constant = character | number | hash | label | nill;

mnemonic = 4*"a-Z0-9";

number = ?0-9?, {?0-9? | "_"} | "0b", ?0-1?, {?0-1? | "_"} | "0o", ?0-7?, {?0-7? | "_"} | ("0d" | "0i"), ?0-9?, {?0-9? | "_"} | "0x", ?0-9A-F?, {?0-9A-F? | "_"};

nill = "nill";

character = "'", ?any ASCII character? , "'" | "'", "\", ("0" | "t" | "n" | "'" | "\") , "'" ;

hash = ":", { ?non-special ASCII character? }-;

label = "$", { ?non-special ASCII character? }-;

tag = { ?non-special ASCII character? }-, ":";

@endebnf

@RodrigoDornelles
Copy link
Owner Author

RodrigoDornelles commented Jul 9, 2023

@startuml
[*] --> TBC_STATE_LANG_READ
TBC_STATE_LANG_READ --> TBC_STATE_LANG_TYPE_TOKEN
TBC_STATE_LANG_TYPE_TOKEN --> TBC_STATE_LANG_LABEL_SCAN
TBC_STATE_LANG_TYPE_TOKEN --> TBC_STATE_LANG_COMMENT
TBC_STATE_LANG_COMMENT --> TBC_STATE_LANG_COMMENT
TBC_STATE_LANG_COMMENT --> TBC_STATE_LANG_READ
TBC_STATE_LANG_LABEL_SCAN --> TBC_STATE_LANG_LABEL_COMMIT
TBC_STATE_LANG_LABEL_COMMIT --> TBC_STATE_LANG_READ
TBC_STATE_LANG_LABEL_COMMIT --> TBC_STATE_LANG_LINE_COMMIT
TBC_STATE_LANG_TYPE_TOKEN --> TBC_STATE_LANG_PARSE_RX
TBC_STATE_LANG_PARSE_RX --> TBC_STATE_LANG_PARSE_RY
TBC_STATE_LANG_PARSE_RY --> TBC_STATE_LANG_PARSE_RZ
TBC_STATE_LANG_PARSE_RZ --> TBC_STATE_LANG_LABEL_COMMIT
TBC_STATE_LANG_LINE_COMMIT --> TBC_STATE_LANG_LINE_COMMIT
TBC_STATE_LANG_LINE_COMMIT --> [*]
@enduml

@RodrigoDornelles
Copy link
Owner Author

RodrigoDornelles commented Nov 1, 2023

/**
 * @file interpreter.c
 * @brief Program example for a 3bc syntax interpreter
 * using a single virtual machine.
 */

#include "lang/lang_3bc_cli.h"
#include "lang/lang_3bc_compile.h"
#include "driver/driver_power.h"
#include "driver/driver_stack.h"
#include "driver/driver_interrupt.h"
#include "ds/ds_ram_array.h"
#include "ds/ds_prog_array.h"

int main(int argc, char** argv)
{
    static volatile uint8_t memory[2048];
    static uint16_t lenght;
    static int status = -1;

    lenght += driver_power_init(memory);
    lenght += driver_stack_init(memory, &memory[lenght], 255);
    lenght += ds_ram_array_init(memory, &memory[lenght], 1024);
    lenght += lang_3bc_cli_init(memory, &memory[lenght], argc, argv, 255);
    lenght += ds_prog_array_init(memory, &memory[lenght], sizeof(memory) - lenght);

    while (status == -1) {
        lang_3bc_compile(memory);
        status = driver_interrupt(memory);
    }

    return status;
}

@RodrigoDornelles
Copy link
Owner Author

heapless first use flag -m to allow dinamic memory usage #221

Repository owner deleted a comment from cyny39 Feb 23, 2024
Repository owner deleted a comment from willnaoosmith Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@RodrigoDornelles and others