Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

simple python compiler by using flex\bison

License

NotificationsYou must be signed in to change notification settings

fadel-hasan/python-compiler

Repository files navigation

compiler for python made using lex yacc /GNU's flex bison.

The current version of this code supportsdefining a function,defining a class,calling a function, various types ofexpressions,assignment statements, andif conditions, in addition to loops such asfor andwhile and some other structures such astry,match,yield,global,nonlocal,return,break,continue,INDENT \DEDENT analysis usingstack

How to make

You will needflex,bison, andgcc installed on your machine

To change sh script permission:

$ chmod +x build.sh clear.sh

To build:

$ ./build.sh
compiled:compiler,parser.tab.c,parser.tab.h,lex.yy.c

To run:

$ ./compiler test.py

To clear:

$ ./clear.sh

Explaining the operating steps without using the build file

This program is run using the following commands:

bison -d parser.y
  • This instruction produces two files:
    • parser.tab.h : We use this to include it inside the flex file to read the token
    • parser.tab.c : We use this file to make a compiler with the resulting flex file
flex pycompile.l
  • This instruction produces lex.yy.c file: We use this file to make a compiler with the resulting bison file(parser.tab.c)

Finally, to compile flex and bixon, we write this command:

 gcc -o<program file name> parser.tab.c lex.yy.c
  • This produces .exe file

Note : Thestack file is included in order to deal with indentation in a file pycompile.ltest file is : test py

but now is ready to execution ^_____^

Authors

License

MIT License


[8]ページ先頭

©2009-2025 Movatter.jp