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

Stuck at script parsing #44

Open
jenya7 opened this issue Jan 9, 2022 · 2 comments
Open

Stuck at script parsing #44

jenya7 opened this issue Jan 9, 2022 · 2 comments

Comments

@jenya7
Copy link

jenya7 commented Jan 9, 2022

I test the interpreter

`
poolsize = 1 * 1024;
line = 1;

// allocate memory for virtual machine
if (!(text = old_text = malloc(poolsize)))
    return -1;

if (!(data = malloc(poolsize))) 
    return -1;

if (!(stack = malloc(poolsize))) 
    return -1;

if (!(symbols = malloc(poolsize)))
    return -1;

memset(text, 0, poolsize);
memset(data, 0, poolsize);
memset(stack, 0, poolsize);
memset(symbols, 0, poolsize);
bp = sp = (int *)((int)stack + poolsize);
ax = 0;

src = "char else enum if int return sizeof while "
      "open read close printf malloc memset memcmp exit void main";

// add keywords to symbol table
i = Char;
while (i <= While) 
{
    next();
    current_id[Token] = i++;
}

// add library to symbol table
i = OPEN;
while (i <= EXIT) 
{
    next();
    current_id[Class] = Sys;
    current_id[Type] = INT;
    current_id[Value] = i++;
}

next(); current_id[Token] = Char;
next(); idmain = current_id; 

src = "int vara;
int varb;
while (1)
{
vara=2;
varb=3;
int varc = vara + varb;
if (varc >= 5)
return varc;
}";

 program();

`
It stuck at program() after while at (1). What do I do wrong?

@lotabout
Copy link
Owner

lotabout commented Jan 9, 2022

@jenya7 All variables should be declared before using. In your code, varc is not declared first. Checkout the example below:

#include <stdio.h>

int main()
{
    int vara;
    int varb;
    int varc;
    while (1)
    {
        vara=2;
        varb=3;
        varc = vara + varb;
        if (varc >= 5)
        return varc;
    };
}

@jenya7
Copy link
Author

jenya7 commented Jan 9, 2022

Still it stops at (1). May be it's mandatory to include all code in
void main() { }
?

I see. Thank you, it works.

May I port it to an embedded system (a micro controller) as is?

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