yyyyyyyan / rockstar-py Goto Github PK
View Code? Open in Web Editor NEWPython transpiler for the esoteric language Rockstar
License: MIT License
Python transpiler for the esoteric language Rockstar
License: MIT License
As you're currently the primary implementation of rockstar (good job!), I've noticed that the programs that are verified with rockstar-py often contain invalid variable names. For example:
Put "value" into value
shouldn't compile because "value" isn't a valid variable name (doesn't begin with 'a', 'an', etc. or a capital letter). If you change it to "value" it works fine:
I also understand that if you want to accept invalid rockstar (something compilers do often) if you can make heads or tails of it that's perfectly fine too (I do it with variable name spacing), just wanted to make you aware of it.
Hi, there seems to be an issue with transpiling compound assignments:
X is 1
Let X be with 1
Say X
transpiles into
X = 1
X = + 1
print(X)
and prints 1.
Correct behaviour would be to transpile the second line into X += 1
, making the final X value 2.
See specification
This means variable names get treated like numbers
After a fresh install of Python 3.4 via package manager (onto CentOS 7), followed by pip3 and sudo pip3 install rockstar-py
, running rockstar-py
gives the following error:
[vagrant@adpc-com-039 Python-3.7.0]$ rockstar-py
Traceback (most recent call last):
File "/usr/bin/rockstar-py", line 9, in <module>
load_entry_point('rockstar-py==1.2.1', 'console_scripts', 'rockstar-py')()
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 547, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2719, in load_entry_point
return ep.load()
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2379, in load
return self.resolve()
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2385, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python3.4/site-packages/rockstarpy/__init__.py", line 1, in <module>
from . import rockstar
File "/usr/lib/python3.4/site-packages/rockstarpy/rockstar.py", line 2, in <module>
from . import command_line
File "/usr/lib/python3.4/site-packages/rockstarpy/command_line.py", line 2, in <module>
from . import rockstar
ImportError: cannot import name 'rockstar'
After pip3 install rockstar-py
. I want to run this command rockstar-py --output rockstar.py -i lyrics.txt
but I get this error
-bash: rockstar-py: command not found
Right now the transpiler doesn't ensure correct number types.
Put 421 into my heart
Put 421.0 into my soul
Shout my soul over 2
Say my heart over 2
Results in
210.5
210
It should be either all int
210
210
or all float
210.5
210.5
example:
Example takes test
Give back test
Say My Logf Ext taking "test"
File ".default.py", line 3
print(My_Logf_Ext taking "test)
^
SyntaxError: invalid syntax
transpiled code:
def Example(test):
return test
print(My_Logf_Ext taking "test)
This code should compile:
Listen to your heart
If your heart aint "rock"
Say "Pick rock, paper, or scissors"
But instead, I get this error:
File "output.py", line 2
if your_heart aint "rock":
^
SyntaxError: invalid syntax
How come aint doesn't work?
r'([A-Za-z]+(?: [A-Za-z]+)*) taking ([A-Za-z0-9_]+(?:, [A-Za-z_0-9]+)*)'
will match:
Multiply taking 3, 4
but not:
Say Multiply taking 3, 4
or anything else where a function call is mid-line.
Side point:
Multiply taking 3,4
doesn't either work
numeric literals are not supported as in the code
Limit is 100
Counter is 0
Fizz is 3
Buzz is 5
which generates the output
Limit = 0
Counter = 0
Fizz = 0
Buzz = 0
when it should generate the output
Limit = 100
Counter = 0
Fizz = 3
Buzz = 5
When compiled, while statements don't seem to terminate properly. Everything below the looped code just compiles inside the first while statement. Likewise with If statements; a subsequent If statement gets nested inside the first one. I tried leaving blank lines but all that seems to do is add blank lines to the compiled program.
Is this a bug or am I just doing something wrong?
Great work on the transpiler! ๐
This issue relates to the part of the README that says:
I'll work on the readibility and organization of the code, would love suggestions on how/where to do that.
Would rockstar-py
be better structured as a package? E.g.:
rockstar.py
to rockstar/__init__.py
setup.py
(setuptools) file, with console script entry pointrockstar/__main__.py
for running as a module (e.g. python -m rockstar
)If you think this is a good idea, I'd be happy to make these changes and open a PR
I'm not sure if this is related to this repo not being structured as a package, but after pip install
ing rockstar-py
and running rockstar-py
, a ModuleNotFoundError
is raised:
$ rockstar-py
Traceback (most recent call last):
File "/home/james/.local/share/virtualenvs/test-wygyIHa6/bin/rockstar-py", line 7, in <module>
from rockstarpy.command_line import main
File "/home/james/.local/share/virtualenvs/test-wygyIHa6/lib/python3.6/site-packages/rockstarpy/__init__.py", line 1, in <module>
from .rockstarpy import rockstar
ModuleNotFoundError: No module named 'rockstarpy.rockstarpy'
For example
Tango takes Man and Woman
the music is a strife
My Life is Man with the music
My Life is My Life without Woman
Give back My Life
is evaluated to
def Tango(Man, Woman):
the_music = 16
My_Life = 3435
My_Life = 2455
return My_Life
Is this a bug or is it in accordance to Rockstar specs?
Also, comparison doesn't seem to be working fully as intended. I got If Your Heart is nothing,
to transpile into if Your_Heart = 7:
. It seems that in this case, the transpiler was confused by the comma, as If Your Heart is nothing
transpiles correctly.
However, comparing two variables (eg. If Your Heart is Dying
still doesn't work and transpiles as an assignment). For some reason, this works only if I use your heart
instead of Your Heart
(where this variable is an output of a function).
Rockstar-py seems not to be able to compile 99-beer.rock (from rockstar/examples):
python3 -W ignore -m rockstarpy --output bottles.py --input $ROCKSTAR/examples/99_beers.rock
runs fine, but
python3 bottles.py
Traceback (most recent call last):
File "bottles.py", line 6, in <module>
print(the_beers + your_heart)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
due to the parenthetic nature of comments in rockstar comments can run across multiple lines such as
(
multi
line
comment
)
this can be fixed by replacing " ( " and " ) " with " """ "
the Statement "Roll X into Y" does not work.
Translates in python to either "Roll_X into Y" or "roll X into Y" (depending on capitalization of "Roll".
From the Rockstar docs: "Rockstar also supports a special roll x into y syntax for removing the first element from an array and assigning it to a variable"
Currently building some python code that uses rockstar transpiling (I actually have an almost practicable purpose for rockstar :) ).
I tried using the pip install but the "-" in rockstar-py is not valid in a python incude statement.
Copying the rockstar folder in to my project worked fine so, it is not the code, just the packaging that is the problem.
Hi, it would be awesome if rockstar-py supported list arithmetic (in other words, multiple expressions on the right side of the operator)
Example:
Let X be 1 with 2, 3, 4
Say X (prints 10)
Could be transpiled to:
X = 10 # as result of 1 + 2 + 3 + 4
print(X)
See specification
After running a primality tester written in Rockstar, the generated file is erroring on this line (the_storm is in inputted value):
if the_storm <= a_pair * a_pair: TypeError: '<=' not supported between instances of 'str' and 'int'
This seems to be because Python is treating the_storm as a string instead of an int.
According to the spec
Knock the walls down, down will decrement the value stored in the walls by 2
Currently I get
the_walls -= 1, down
I tried to build this package myself using this repo, I've wrote the following file:
rockstar111.rock:
My heart is ok (should be True)
Tommy says True that (intializes tommy to True that)
Shout My heart
Shout Tommy
I transpiled the file using the follwoing command:
rockstar-py --input rockstar-tut1.rock --stdout
output:
my_heart = true # should be True
Tommy = "True that " # intializes tommy to True that
print(my_heart)
print(Tommy)
Note: using pip install rocstar-py
instead of this very repo I'm getting the right output.
Line 175, your call to convert_code is preceded by 'rockstar.', so it doesn't work.
origin:
rockstar.convert_code(rockstar_code, py_rockstar)
fix:
convert_code(rockstar_code, py_rockstar)
It's working !!
Hello,
From rockstar spec:
If a variable is defined outside of a function, it is in global scope. Global scope variables are available everywhere below its first initialization. If a variable is defined inside of a function, it is in local scope. Local scope variables are available from their initialization until the end of the function they are defined in.
While within a function, if you write to a variable that has been defined in global scope, you write to that variable, you do not define a new local variable.
Currently with rockstar-py, we can read global variables but not reassign them from a function scope. For that, we need to add a global declaration: https://docs.python.org/3/reference/simple_stmts.html?highlight=global#the-global-statement
So the compiler has to list all variables declared as global (i.e. ident == 0
), then add a global myVar
line in each function body that refers to it.
I wish I could contribute to this but I'm still a beginner in Python. I picked rockstar-py because the repository looks active and I got good results so far with my rockstar project.
It's currently extremely easy to insert arbitrary Python statements into the code, like x=1
. For example, the code
for n in 1,2,3,4:Say n*5
Is parsed fine and is basically the same as the equivalent Python.
It seems that code blocks (function body, loop, condition body etc) are not terminated after a blank line.
Example:
While X is greater than 1
Say X
If X is greater than 1
Say X
Transpiles into:
while X > 1:
print(X)
if X > 1:
print(X)
Correct output should be along the lines of:
while X > 1:
print(X)
if X > 1:
print(X)
See specification
Hey it's me again!
The following code should compile, setting my wallet
to 7, as far as my reading of the standard in cwfitzgerald/rockstar-webpiler#1 goes, but rockstar-py substitutes in -
instead of 7.
Side note: I really should put together a compiler test suite that goes through all the edge cases that can come up :)
Example
Put "Say a" into p
becomes
P = "print(a")
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.