Skip to content

SapphireDragoness/AcDcCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AcDcCompiler

A simple compiler from the ac (adding calculator) language to the dc (desktop calculator) language. Documentation and interface are entirely in italian.

How to use this program

The program can be easily run from the executable CompilatoreACDC.jar. Just feed it a text file containing a (valid) ac source file and let the program do its magic.

How this compiler works

The compiler is made up of a scanner, whose job is to break down the source code into tokens; a parser, that checks if the tokens received from the scanner follow the ac grammar (spedified below) and builds an abstract syntax tree representing the syntax of the source code; a typechecker, that decorates the AST with information regarding data types; and a code generator, that walks the AST and generates dc code.

ac's grammar

  1. Prg → DSs $
  2. DSs → Dcl DSs
  3. DSs → Stm DSs
  4. DSs → ϵ
  5. Dcl → Ty id DclP
  6. DclP → ;
  7. DclP → opAss Exp;
  8. Stm → id opAss Exp;
  9. Stm → print id;
  10. Exp → Tr ExpP
  11. ExpP → -Tr ExpP
  12. ExpP → +Tr ExpP
  13. ExpP → ϵ
  14. Tr → Val TrP
  15. TrP → /Val TrP
  16. TrP → *Val TrP
  17. TrP → ϵ
  18. Ty → float
  19. Ty → int
  20. Val → intVal
  21. Val → floatVal
  22. Val → id

Special features

  • GUI to make compilation more accessible
  • "panic mode" in parser: if the source code is malformed, the parser keeps on parsin' by finding the delimiter ';' and resuming operation

About

A compiler written in Java, University project.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages