Skip to content

rbbarbosa/Petit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Petit

Petit programming language and compiler

Example

Petit is an educational programming language for learning compilers. Here's an example:

factorial(integer n) =
    if n then n * factorial(n-1) else 1

Tutorials and exercises

  1. Tutorial I: Lexical analysis
  2. Tutorial II: Advanced lex features
  3. Tutorial III: Syntactic analysis
  4. Tutorial IV: Abstract syntax
  5. Tutorial V: Semantic analysis
  6. Tutorial VI: Code generation
  7. Solutions for most exercises

Grammar

program: functions

functions: function
         | functions function

function: IDENTIFIER '(' parameters ')' '=' expression

parameters: parameter
          | parameters ',' parameter

parameter: INTEGER IDENTIFIER
         | DOUBLE IDENTIFIER

arguments: expression
         | arguments ',' expression

expression: IDENTIFIER
          | NATURAL
          | DECIMAL
          | IDENTIFIER '(' arguments ')'
          | IF expression THEN expression ELSE expression
          | expression '+' expression
          | expression '-' expression
          | expression '*' expression
          | expression '/' expression
          | '(' expression ')'

About

Petit programming language and compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published