dontbelieveme / stack Goto Github PK
View Code? Open in Web Editor NEWA small stack based programming language written in C.
License: MIT License
A small stack based programming language written in C.
License: MIT License
Now that the error refactoring is complete, I think refactoring other parts of the code base should be done as well. Rename functions that are confusing to understand, refactoring the parser, and cleaning up the code in general. Adding better documentation is in order also.
I have one question about the Macro
struct in parse.h. What does it do?
Currently error reporting is abysmal and needs some serious refactoring. Certain functions can't report an error if something went awry because: a) the return value is void
or b) the function does return a value but you can't return error codes because it would limit the abilities of particular operations.
Take stack_pop()
for example. It pops the top item off the stack and returns it. If you pop from an empty stack that is called a stack underflow. If the function returns any number like -1 to signify a stack underflow, then arithmetic operations with that designated error number is impossible.
Another example is stack_dup()
. Its implementation pops off a value then pushes it twice back onto the stack. What if the stack is empty? Like said before, popping from an empty stack yields a stack underflow. How do we let the calling user of stack_dup()
know that an error happened? We can't currently because of how the function is setup.
My proposal for the solution is to allow all functions that return a pointer return 0 on failure and every other function have an additional output parameter for the error code. Another one is all functions return a status code and the return value is an output parameter.
For example:
stack *stack_new()
becomes
error_code_t stack_new(stack **new_stack);
I wanted to run this by you before doing the refactoring to see what you think.
When I began this project I had no idea about parsers or anything. Now I return, armed with the knowledge of several crudely implemented simple parsers. Aha!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.