Skip to content
/ cxlox Public

A C implementation of lox from the Crafting Interpreters book.

Notifications You must be signed in to change notification settings

nagyj2/cxlox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cxlox

This is a C implementation of the xlox language. There are two banches, main and xlox. The main branch is used for the Crafting Interpreters implementation of the lox language. The xlox branch is used for the implementation of the xlox language.

Grammar

program       := declaration*
declaration   := varDecl
               | funDecl
               | classDecl
               | statement
varDecl       := "var" IDENTIFIER ["=" expression] ";"
funDecl       := "fun" IDENTIFIER "(" [IDENTIFIER ("," IDENTIFIER)*] ")" "{" declaration* "}"
classDecl     := "class" IDENTIFIER "{" methodDecl "}"
methodDecl    := IDENT "(" [IDENTIFIER ("," IDENTIFIER)*] ")" "{" declaration* "}"
statement     := exprStmt
               | printStmt
               | blockStmt
               | ifStmt
               | whileStmt
               | forStmt
               | returnStmt
exprStmt      := expr ";"
printStmt     := "print" expr ";"
blockStmt     := "{" declaration* "}"
ifStmt        := "if" "(" expr ")" statement ["else" statement]
whileStmt     := "while" "(" expr ")" statement
forStmt       := "for" "(" (expr | varDecl)? ";" expr? ";" expr? ")" statement
returnStmt    := "return" expr? ";"
expr          := assignment
assignment    := IDENTIFIER "=" assignment
               | equality
equality      := comparison (("==" | "!=") comparison)*
comparison    := addition (("<" | ">" | "<=" | ">=") addition)*
addition      := multiply  (("+" | "-") multiply)*
multiply 	    := unary (("*" | "/") unary)*
unary         := ( "!" | "-") unary
               | call
call          := primary ["(" [expr ("," expr)*)] ")" | "." expr]
primary       := NUMBER
               | STRING
               | IDENTIFIER
               | "true"
               | "false"
               | "nil"
               | "this"
               | "super"
               | "(" expr ")"
NUMBER        := [0-9]+ ("." [0-9]+)?
STRING        := "\"" (CHARACTER)* "\""
IDENTIFIER    := [a-zA-Z_][a-zA-Z0-9_]*

Build

To make this project, you need to install the following dependencies:

  • CMake >= 3.10

To create the executable, run the following commands:

About

A C implementation of lox from the Crafting Interpreters book.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published