Skip to content

LEOB3TA/MiniC_ANTLR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniC

This is small compiler for a little set of C

Index

How to install

Dependencies

You have to install Java JRE on your computer, the version must be newest than 10

Instructions

  • Download the .jar file from the release
  • In Linux make it executable by:
chmod +x Mini_ANTLR.jar
  • Execute it by double-clicking it, or in alternative you can use:
java -jar MiniC_ANTLR.jar

Usage

The interface is divided in two parts:

  • Input area -> where you can write your code
  • Console -> where the program prints the output

First you have to write some code in the input area or open a file with your code via File menu, after that through the Command menu you can choose :

  • Check input -> checks token and grammar
  • Start evaluation -> after a check, evaluates your code
  • Debug -> after a check, evaluates your code and shows how the memory changes during execution
  • Print parse tree -> prints the parse tree
  • Stop -> stops all running actions

You can use one command at time

The output is written to the Console

The status led indicate if an action is running

You can save your input and your output in a file via the File menu

With Help menu you can read some info about this project, or you can open this page by clicking help

Commands details

Check input

Checks all the input and controls if there are some wrong tokens or if the grammar is not respected Prints all the errors in the console; if there's no errors it prints "ready for evaluation..."

Start evaluation

First checks the code, if the check is correct evaluates the code, otherwise prints all the parser and lexer errors. If errors are found during the evaluation, the evaluation stops and prints the errors to the console.

Debug

The behaviour is the same of "Start evaluation", but in this case, every time the memory changes, prints the memory state in this format:

after evaluation of: <statement that changes the memory>
undefined var:
level n: {<undefined variable at this level>}
level n+1: {<>}
……………
memory :
level n: {<inizialized variable at this level>}
level n+1: {<>}
……………

level matches the blocks ({}), more details about the memory inside the docs

Print parse tree

First checks the code, if the check is correct prints the parse tree, otherwise prints all the parser and lexer error.

Stop

This command stops all the running actions. It can be useful when there are semantic errors in the code; such as an infinite loop

Features

Data type

  • int
  • double
  • bool (true,false) -> are respectively 1 and 0

Operators:

  • '*' -> Times
  • '/' -> Divide
  • '%' -> Module
  • '+' -> Plus
  • '-' -> Minus
  • '<' -> Less than
  • '<=' ->Less equal than
  • '>' -> Greater than
  • '>=' -> Greater equal then
  • '==' -> Equal
  • '!=' -> Not equal
  • '||' -> Or
  • '&&' -> And
  • '!' -> Not
  • '=' -> Assignment

Statements:

  • if-else
  • while
  • block ({})
  • printf -> only for int and double types, you can insert also boolean value that will be cast to integer, you can only use %d and %f format
  • scanf -> only for int and double types, you can insert also boolean value that will be cast to integer, you can only use %d and %f format

Examples

Example of correct evaluation:

Example of evaluation error:

Example of lexer error:

Example of parser error:

Example of correct check:

Example of parse tree:

Contribute

Open a issue or open a pull request

About

small compiler for a little set of C inspired by Fcc by Marco Cova

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •