liam-ilan / crumb Goto Github PK
View Code? Open in Web Editor NEWThe Crumb Programming Language
The Crumb Programming Language
The following code has O(n^2) complexity (n
is the length of in
), accidentally quadratic:
Line 13 in 5ff70a2
Compile the interpreter with no optimizations and try to execute the output of the following Python program:
print("(print\"" + "a" * int(1e6) + "\")")
It will take about 10^12 operations, seconds at the very least. -O2
is typically smart enough to optimize reading strlen()
on each iteration, but I would not rely on that.
The following snippet can access array out of bounds:
Lines 53 to 66 in 5ff70a2
Consider a string that terminates with "
. The program enters the first if
statement, increases i
, now code[i]
is \0
. Then it enters the while
loop, increases i
one more time, now code[i]
is out-of-bounds. It does not cause crash currently for me, though. You can also see a hint by passing -fsanitize=address
to gcc
/clang
.
Another issue is with isdigit
function that expects a non-negative number, but you give it a char
that can be (and typically) is signed:
Lines 53 to 66 in 5ff70a2
isdigit
was accessing an array under the hood, and negative index was very out-of-bounds.Currently the project has no open source license, and neither do any contributions in the pull requests. Will this project be open sourced?
Is (3*5)^(1/2)
not 3.87 instead of 5.83 like you have shown in your example?
It seems to me that the lexer is ad-hoc with no specific grammar for what it's trying to lex:
Lines 53 to 85 in 5ff70a2
In particular, it seems to assume that \"
always terminates the string literal. It's not the standard behavior for other programming languages; one can escape the backslash with another backslash, e.g. "\\"
.
Just as the title says
I only started learning C early this year (late Jan early Feb) and reading through this code I'm impressed by how much I understand obviously from the fact that you wrote such concise and easy to understand code.
I've picked up on a few memory handling tricks along the way that I didn't think of and will actually be rewriting a simple interpreter-ish project I did a few weeks back (shameless plug here) based on some of the practices I've picked up in this codebase
Thank you for sharing this project and writing neat concise code like this. I'm not done reading through everything but it's like a very good book you can't put down. I'm taking notes as I read in case I forget something
Anyway keep being awesome Liam ๐๐พ
There seems to be a read-past-buffer issue in the lexer. Let's say that you have a file that ends with /
, then here you peek behind the end of the buffer. This pattern is used several times. I did not look closer into the potential effects of this pattern but it might lead to crashes if by chance the lexer continues to find valid patterns, I assume.
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.