Git Product home page Git Product logo

Comments (4)

orangeduck avatar orangeduck commented on July 19, 2024 1

Your grammar seems to say that inside the body of a function there should be a single variable declaration followed by multiple statements: '{' <decls> <stmt>* '}'. I think you probably mean something more like there should be multiple of either variable declarations or statements, something more like: '{' (<decls> | <stmt>)* '}'.

Anyway I think these are issues with your grammar rather than the behaviour of mpc which I think you can debug yourself. Feel free to reopen this issue if you think there is a bug with mpc but for now I am going to close it.

Hope you manage to get it working as intended 👍

from mpc.

orangeduck avatar orangeduck commented on July 19, 2024

Looks like it is trying to parse the procedure as a decls and failing. I suspect this might work as intended if you change <decls> to <decls>*.

from mpc.

ikbenlike avatar ikbenlike commented on July 19, 2024

I assume you meant that about the <decls> on this line?

" xenon     : /^/ <use> <decls>* <procedure>* /$/ ; \n"

Doing that (and a few other things) solved the problem, but it also created a new one.
This is my full grammar:

" ident     : /[a-zA-Z_][a-zA-Z0-9_]*/ ;                                                                    \n"
" number    : /-?[0-9]+(\\.[0-9]*)?/ ;                                                                      \n"
" character : /'.' | \".\"/ ;                                                                               \n"
" string    : /\"(\\\\.|[^\"])*\"/ ;                                                                        \n"
" boolean   : /true | false/ ;                                                                              \n"
"                                                                                                           \n"
" print     : /\"print\" (<ident> | <string>)/ ;                                                            \n"
" factor    : '(' <lexp> ')'                                                                                \n"
"           | <number>                                                                                      \n"
"           | <character>                                                                                   \n"
"           | <string>                                                                                      \n"
"           | <ident> '(' <lexp>? (',' <lexp>)* ')'                                                         \n"
"           | <ident> ;                                                                                     \n"
"                                                                                                           \n"
" term      : <factor> (('*' | '/' | '%') <factor>)* ;                                                      \n"
" lexp      : <term> <index>* (('+' | '-') <term> <index>* )* ;                                             \n"
"                                                                                                           \n"
" index     : '[' <number> ']' ;                                                                            \n"
" stmt      : '{' <stmt>* '}'                                                                               \n"
"           | \"while\" '(' <exp> <index>* ')' <stmt>                                                       \n"
"           | \"for\" '(' <exp> <index>* ')' <stmt>                                                         \n"
"           | \"if\"    '(' <exp> ')' <stmt>                                                                \n"
"           | \"loop\" <stmt>                                                                               \n"
"           | <ident> '=' <lexp> <index>* ';'                                                               \n"
"           | \"print\" '(' <lexp>? ')' ';'                                                                 \n"
"           | \"return\" <lexp>? ';'                                                                        \n"
"           | <ident> <index>* ';'                                                                          \n"
"           | <ident> '(' <ident>? (',' <ident>)* ')' <index>* ';';                                         \n"
"                                                                                                           \n"
" exp       : <lexp> '>' <lexp>                                                                             \n"
"           | <lexp> '<' <lexp>                                                                             \n"
"           | <lexp> \">=\" <lexp>                                                                          \n"
"           | <lexp> \"<=\" <lexp>                                                                          \n"
"           | <lexp> \"!=\" <lexp>                                                                          \n"
"           | <lexp> \"==\" <lexp>                                                                          \n"
"           | <lexp> \"in\" <lexp> ;                                                                        \n"
"                                                                                                           \n"
" typeident : (\"int\" | \"char\" | \"str\" | \"bool\" | \"float\" ) <ident> ;                              \n"
" procedure : (\"int\" | \"char\" | \"str\" | \"bool\" | \"float\" ) ':' <ident> '(' <args> ')' <body> ;    \n"
" decls     : <typeident> '=' ( <number> | <character> | <string> | <boolean> | <term> ) <index>* ';' ;  \n"
" args      : <typeident>? (',' <typeident>)* ;                                                             \n"
" body      : '{' <decls> <stmt>* '}' ;                                                                     \n"
" use       : (\"use\" /[a-zA-Z_\\/\\.][a-zA-Z0-9_\\/\\.]*/)* ;                                             \n"
" `xenon     : /^/ <use> <decls>* <procedure>* /$/ ;`                                                          \n"

I'm trying to parse this file (yes, the variable names are just random crap):

int:stuff(str string_to_print){
    int alasfdk = 1;
    puts(stuff);
    float jKAHalskdjf = 1.1;
    str calskf = "stuff";
}

But, it's throwing this error:

print.pxe:4:11: error: expected '=', '[', ';' or '(' at 'j'

from mpc.

ikbenlike avatar ikbenlike commented on July 19, 2024

That worked. Thanks for your help!

from mpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.