Giter Site home page Giter Site logo

compiler's Introduction

git status

Compiler

Um compilador desenvolvido em Python para a linguagem Carbon.

Diagrama Sintático

diagrama sintatico

EBNF

PROGRAM = { DECLARATION } ;
DECLARATION = "fn", IDENTIFIER, "(", ( "" | ARGUMENT, { ",", ARGUMENT } ), ")", ( "" | "->", TYPE ), BLOCK ;
ARGUMENT = IDENTIFIER, { "," }, ":", TYPE ;
BLOCK = "{", { STATEMENT }, "}" ;
STATEMENT = (( λ | ASSIGNMENT | PRINT | ("var", IDENTIFIER, {",", IDENTIFIER}, ":", TYPE) ), ";" | ( LOOP | CONDITION | BLOCK ) | "return" REL_EXPRESSION ) ;
ASSIGNMENT = IDENTIFIER, "=", REL_EXPRESSION ;
PRINT = "Print", "(", REL_EXPRESSION, ")" ;
LOOP = "while", "(", REL_EXPRESSION, ")", STATEMENT ;
CONDITION = "if", "(", REL_EXPRESSION, ")", STATEMENT, ( λ | "else", STATEMENT ) ;
REL_EXPRESSION = EXPRESSION, { ("==" | ">" | "<" | "."), EXPRESSION } ;
EXPRESSION = TERM, { ("+" | "-" | "||"), TERM } ;
TERM = FACTOR, { ("*" | "/", "&&"), FACTOR } ;
FACTOR = (("+" | "-" | "!"), FACTOR) | NUMBER | "(", EXPRESSION, ")" | IDENTIFIER, ( "" | "(", ( "" | REL_EXPRESSION, { ",", REL_EXPRESSION } ), ")" ) | "Read", "(", ")" ;
IDENTIFIER = LETTER, { LETTER | DIGIT | "_" } ;
NUMBER = DIGIT, { DIGIT } ;
LETTER = ( a | ... | z | A | ... | Z ) ;
DIGIT = ( 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 ) ;
TYPE = ( "String" | "i32" ) ;

Visualização

O script main também gera um arquivo em linguagem DOT que pode ser usado para visualizar a AST do código.

Você pode desenhá-lo usando o software que desejar ou, caso possua graphviz instalado, executar o script draw.py e desenhar a AST como essa abaixo que calcula os 102 primeiros termos da sequência de Fibonacci:

exemplo AST

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.