Coder Social home page Coder Social logo

pythoncompiler's Introduction

PythonCompiler

Code used on "Writing your own programming language and compiler with Python" post

pythoncompiler's People

Contributors

marcelogdeandrade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pythoncompiler's Issues

Strange answer of print

Hey, i have the same code. I compile with clang but the executable say "-458475770" for this code :
print(4 + 4 - 2);

Only single-line code works

So only single-line code works, so this is not possible:

print(1+1)
print(1+2)

Is there a workaround to this, or is this my error?

How to create a `print` function for different types?

Hi, can I get general guidance on the correct way to implement the print function to be able to print different types:

print(10)
print(7.3)

It's not possible to define a function with the same name for different types, maybe I can somehow cast arguments to strings first and then always pass only strings?

rply.errors.LexingError

specification

python version: 3.10.9
cpu: M1
os: macOS Ventura 13.1
MBA 2020

error

if I run it using the print(1) method it works. but if I try a str print("Hello, World") it gives this error:
rply.errors.LexingError: (None, SourcePosition(idx=0, lineno=1, colno=1))

Full error:

  return self.pg.build()
Traceback (most recent call last):
  File "/Users/klestiselimaj/Projects/lang/main.py", line 21, in <module>
    parser.parse(tokens).eval()
  File "/Users/klestiselimaj/Library/Python/3.9/lib/python/site-packages/rply/parser.py", line 32, in parse
    lookahead = next(tokenizer)
  File "/Users/klestiselimaj/Library/Python/3.9/lib/python/site-packages/rply/lexer.py", line 62, in __next__
    return self.next()
  File "/Users/klestiselimaj/Library/Python/3.9/lib/python/site-packages/rply/lexer.py", line 58, in next
    raise LexingError(None, SourcePosition(
rply.errors.LexingError: (None, SourcePosition(idx=0, lineno=1, colno=1))```

gcc not compiling

After compiling with llc, when output.o file is compiled using gcc the error message flashes
screenshot from 2018-07-03 15-03-15

Error running your example on python3

python main.py

PythonCompiler/parser.py:41: ParserGeneratorWarning: 4 shift/reduce conflicts
return self.pg.build()

Did you come across a similar error

parsing error for multiple line file code

greeting sir.
my name is Aditya Gupta. we have been working a project. and wanted to make a python based compiler. so we started following your blog, which by the way is very helpful. but now we are stack at a point where we have to give an file in input.

input file: in.txt
print(1) print(2)

in.txt

output obtained for this input:

Token('PRINT', 'print') Token('OPEN_PAREN', '(') Token('NUMBER', '0') Token('SUM', '+') Token('NUMBER', '9') Token('CLOSE_PAREN', ')') Token('PRINT', 'print') Token('OPEN_PAREN', '(') Token('NUMBER', '9') Token('CLOSE_PAREN', ')') Traceback (most recent call last): File "C:\Users\admin\AppData\Local\Programs\Python\Python37\CompNew\check2.py", line 385, in <module> parser.parse(tokens).eval() File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\rply\parser.py", line 65, in parse raise ParsingError(None, lookahead.getsourcepos()) rply.errors.ParsingError: (None, None)

error.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.