Comments (4)
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.
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.
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.
That worked. Thanks for your help!
from mpc.
Related Issues (20)
- Implementation of `mpcf_all_free` not seen in mpc.c HOT 1
- In theory: Can MPC parse C? HOT 2
- scan coverity findings HOT 1
- Add support for arm64 architecture. HOT 4
- CMakeLists.txt suggestion HOT 6
- Release: GNU Guix
- Segmentation fault and timeout occur at mpca_lang_st() HOT 1
- Does the order of definitions matter in languages? HOT 2
- Mix parsers and AST HOT 3
- Greedy matching causes token matching issue HOT 2
- What about MPC now? HOT 1
- "-static" does not work on newer MacOS due to crt0
- make install does not work on newer MacOS (install command/folders)
- dependency errors issue HOT 9
- shared state and multi-threaded use HOT 2
- parser for """long string""" ? HOT 2
- Make include guards unique
- Completion of error handling
- memory leak in mpca_lang function
- Unicode and regexs etc HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpc.