I wrote it in Python. It's dirty because it's defeated. I'm not familiar with Python, but it's a level of Yoshi because the life game worked.
https://github.com/sonota88/vm2gol-v2-python
I made a simple compiler for my own language in Ruby
Base version: around tag: 45
Assembler / VM has been excluded from porting. Use the Ruby version.
Since the amount of tokenizer is not so large so far, I wrote it in the same file as the parser, but after all I felt like I should divide it.
The ported version will not be maintained continuously in the future, but it will be over when you feel like making it, so feel free to experiment with the modifications that may be included in the Ruby version.
I was thinking about making the grammar of the high-level language part look like Ruby, and this time I tried a part of it.
Change func
to def
, change {...}
to ... end
, change the start character of the line comment to #
, and so on. It looks suspicious as below. Something like var
or set
still remains.
def calc_next_gen(current_val, count)
#Next-generation life and death of the cell of interest
var next_val = 0;
case
when (current_val == 0)
case
when (count == 3)
set next_val = 1;
end
when (0 == 0)
case
when (count == 2)
set next_val = 1;
when (count == 3)
set next_val = 1;
end
end
return next_val;
end
I'm suspicious, but when I check the grammar with ruby -c test /*.vg.txt
, it says OK.
When I run it in Ruby, I think I'll get an error ... I tried it and it ended normally. At first, it seemed surprising, but it seems that there is no run-time error because only the method is defined (not executed). So that's it.
I'm trying to port it to various languages.
Recommended Posts