Skip to content

Toy programming language from the book Moden Compiler Implementation in ML

License

Notifications You must be signed in to change notification settings

romildo/straightline-ocaml-2022-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The straightline programming language

Straightline is a micro programming language used in the book series Modern Compiler Implementation by Andrew Appel.

Grammar

  • The syntax of the language is given by a context free grammar.
  • Only the production rules are explicitly given.
  • The sets of terminals and non-terminals are obtained from the rules.
  • The initial symbol is the non-terminal on the left side of the first production rule.

Production rules

StmStm ; Stm
Stmid := Exp
Stmprint ( ExpList )
Expid
Expnum
ExpExp Binop Exp
Exp( Stm , Exp )
ExpListExp
ExpListExp , ExpList
Binop+
Binop-
Binop*
Binop/

Operator Precedence and Associativity

In order to resolve possible conflicts during syntactic analysis, the following relation of operator precedence and associativity, in descending order, should be observed:

operators associativity
* / left
+ - left
:= right

Lexical symbols

  • Spaces, newlines, and tabulators are white spaces.
  • Comments starts with # and extends to the end of the line.
  • A numerical literal is a sequence of one or more digits.
  • An identifier is a sequence of one or more letters, digits and underscores, beginning with a letter, that is not a keyword.
  • The keywords are: print.
  • The operators are: :=, +, -, * and /.
  • The special symbols are: ,, ;, ( and ).

Example

a := 5 + 3;
b := ( print(a, a-1), 10*a );
print(b)

About

Toy programming language from the book Moden Compiler Implementation in ML

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published