Ported a naive homebrew language compiler to Python


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

Porting source

I made a simple compiler for my own language in Ruby

Base version: around tag: 45

Note

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.

Other transplants

I'm trying to port it to various languages.

Recommended Posts

Ported a naive homebrew language compiler to Python
Introduction to Python language
Try to make a Python module in C language
A road to intermediate Python
Try to select a language
Use a scripting language for a comfortable C ++ life-OpenCV-Port Python to C ++-
How to write a Python class
Introduction to Protobuf-c (C language ⇔ Python)
Python to switch from another language
5 Ways to Create a Python Chatbot
Ported from R language of "Sazae-san's rock-paper-scissors data analysis" to Python
[Python] How to make a class iterable
A super introduction to Python bit operations
Send a message from Python to Slack
I want to build a Python environment
[Python] How to invert a character string
How to get a stacktrace in python
A memo corresponding to Django's runserver moss in Python 2.7.11 entered with Homebrew
I tried a functional language with Python
Ported Python parallel computing sample to F #
Python as a strongly, dynamically typed language
A way to understand Python duck typing
Add a Python virtual environment to VSCode
How to run a Maya Python script
3. Natural language processing with Python 1-2. How to create a corpus: Aozora Bunko
I made a module in C language to filter images loaded by Python
C language to see and remember Part 3 Call C language from Python (argument) c = a + b
Send a message from Slack to a Python server
[Python] List Comprehension Various ways to create a list
Edit Excel from Python to create a PivotTable
How to read a CSV file with Python 2/3
Send a message to LINE with Python (LINE Notify)
How to create a Python virtual environment (venv)
Python inexperienced person tries to knock 100 language processing 14-16
How to open a web browser from python
[Python] Road to a snake charmer (4) Tweak Numpy
How to clear tuples in a list (Python)
To execute a Python enumerate function in JavaScript
How to embed a variable in a python string
Is sys.settrace, a python genius feature, another language?
[Python] Road to a snake charmer (6) Manipulate Pandas
I want to create a window in Python
How to create a JSON file in Python
Try to draw a life curve with python
I want to make a game with Python
Writing logs to CSV file (Python, C language)
I wanted to install Python 3.4.3 with Homebrew + pyenv
How to generate a Python object from JSON
Try to make a "cryptanalysis" cipher with Python
A clever way to time processing in Python
How to add a Python module search path
Steps to develop a web application in Python
Decide to assign a laboratory with Python (fiction)
[Introduction to Python3 Day 23] Chapter 12 Become a Paisonista (12.1 to 12.6)
Python Note: When assigning a value to a string
Why does Python have to write a colon?
Steps to create a Twitter bot with python
To add a module to python put in Julialang
How to notify a Discord channel in Python
Python inexperienced person tries to knock 100 language processing 07-09
Export Python3 version OpenCV KeyPoint to a file