Meus Projetos


Compilador (Linguagem Kandinsky)

ABR 2020 - DEZ 2020


 

Como projeto da disciplina de Compiladores, foi proposto a criação de um compilador para a linguagem Kandinsky, uma linguagem ficticia com a seguinte gramática.

 

Program ::= Func { Func }Func ::= \"def\" Id [ \"(\" ParamList \")\" ] [ \":\" Type ] \"{\" StatList \"}\"ParamList ::= ParamDec { \",\" ParamDec }ParamDec ::= Type IdType ::= \"int\" | \"boolean\" | \"String\"StatList ::= { Stat }Stat ::= AssignExprStat | ReturnStat | VarDecStat | IfStat | WhileStatAssignExprStat ::= Expr [ \"=\" Expr ] \";\"ReturnStat ::= \"return\" Expr \";\"VarDecStat ::= \"var\" Type Id \";\"IfStat ::= \"if\" Expr \"then\" StatList [ \"else\" StatList ] \"endif\"WhileStat ::= \"while\" Expr \"do\" StatList \"endw\"Expr ::= ExprAnd { \"||\" ExprAnd }ExprAnd ::= ExprRel { \"&&\" ExprRel }ExprRel ::= ExprAdd [ RelOp ExprAdd ]RelOp ::= \"<\" | \"<=\" | \">\" | \">=\" | \"==\" | \"!=\"ExprAdd ::= ExprMult { ( \"+\" | \"-\" ) ExprMult }ExprMult ::= ExprUnary { ( \"*\" | \"/\" ) ExprUnary }ExprUnary ::= [ ( \"+\" | \"-\" ) ] ExprPrimaryExprPrimary ::= Id | FuncCall | ExprLiteralExprLiteral ::= LiteralInt | LiteralBoolean | LiteralStringLiteralBoolean ::= \"true\" | \"false\"FuncCall ::= Id \"(\" [ Expr { \",\" Expr } ] \")\"

 

Implementação

 

A implementação do compilador foi realizada na linguagem Java. O projeto foi composto por 3 fases:

 

  1. Primeira Fase: Análise Léxica e Análise Sintática da linguagem
  2. Segunda Fase: Correções da primeira fase e Análise Semântica da linguagem
  3. Terceira Fase: Geração de código em C a partir da linguagem Kandinsky

 


Repositório: https://gitlab.com/pietroz123/compilador-kandinsky



Arquivos do Projeto



C Java Compilador