Meus Projetos


Compilador (Linguagem Cianeto)

FEV 2021 - JUL 2021


 

Neste projeto foi desenvolvido um compilador para uma linguagem com a seguinte gramática:

 

Annot ::= "@" Id [ "(" { AnnotParam } ")" ]

AnnotParam ::= IntValue | StringValue | Id

AssertStat ::= "assert" Expression "," StringValue

AssignExpr ::= Expression [ "=" Expression ]

BasicType ::= "Int" | "Boolean" | "String"

BasicValue ::= IntValue | BooleanValue | StringValue

BooleanValue ::= "true" | "false"

ClassDec ::= [ "open" ] "class" Id [ "extends" Id ] MemberList "end"

Digit ::= "0" | ... | "9"

Expression ::= SimpleExpression [ Relation SimpleExpression ]

ExpressionList ::= Expression { "," Expression }

Factor ::= BasicValue | "(" Expression ")" | "!" Factor | "nil" | PrimaryExpr

FieldDec ::= "var" Type IdList [ ";" ]

FormalParamDec ::= ParamDec { "," ParamDec }

HighOperator ::= "∗" | "/" | "&&"

IdList ::= Id { "," Id }

IfStat ::= if" Expression "{" StatementList "}" [ "else" "{" StatementList "}" ]

IntValue ::= Digit { Digit }

LocalDec ::= "var" Type IdList [ "=" Expression ]

LowOperator ::= +" | "−" | "||"

MemberList ::= { [ Qualifier ] Member }

Member ::= FieldDec | MethodDec

MethodDec ::= "func" IdColon FormalParamDec [ "->" Type ] "{" StatementList "}" | "func" Id [ "->" Type ] "{" StatementList "}"

ParamDec ::= Type Id

Program ::= { Annot } ClassDec { { Annot } ClassDec }

Qualifier ::= "private" | "public" | "override" | "override" "public" | "final" | "final" "public" | "final" "override" | "final" "override" "public" | "shared" "private" | "shared" "public"

ReadExpr ::= "In" "." ( "readInt" | "readString" )

RepeatStat ::= "repeat" StatementList "until" Expression

PrimaryExpr ::= "super" "." IdColon ExpressionList | "super" "." Id | Id | Id "." Id | Id "." IdColon ExpressionList | Id "." "new" | "self" | "self" "." Id | "self" "." IdColon ExpressionList | "self" "." Id "." IdColon ExpressionList | "self" "." Id "." Id | ReadExpr

Relation ::= "==" | "<" | ">" | "<=" | ">=" | "!="

ReturnStat ::= "return" Expression

Signal ::= "+" | "−"

SignalFactor ::= [ Signal ] Factor

SimpleExpression ::= SumSubExpression { "++" SumSubExpression }

SumSubExpression ::= Term { LowOperator Term }

Statement ::= AssignExpr ";" | IfStat | WhileStat | ReturnStat ";" | PrintStat ";" | "break" ";" | ";" | RepeatStat ";" | LocalDec ";" | AssertStat ";"

StatementList ::= { Statement }

Term ::= SignalFactor { HighOperator SignalFactor }

Type ::= BasicType | Id

PrintStat ::= "Out" "." ( "print:" | "println:" ) Expression { "," Expression }

WhileStat ::= "while" Expression "{" StatementList "}"

 

O projeto foi dividido em:

 

1. Primera Fase

 

  • Criação de um analisador sintático e semântico da linguagem Cianeto
  • Criação de um gerador de código de Cianeto para Java utilizando métodos da Árvore de Sintaxe Abstrata (ASA)

 

2. Segunda Fase

 

  • Criação de um gerador de código de Cianeto para C utilizando métodos da Árvore de Sintaxe Abstrata (ASA)

Repositório: https://github.com/pietroz123/Lab_Compiladores



Arquivos do Projeto



C Java Compilador