Skip to content

drewbanas/jloxcs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

jloxcs

A Csharp port of the Lox tree-waliking interpreter from Bob Nystrom’s Crafting Interpreters book. An attempt is made to stay close to the original Java code so one easily can refer to the Crafting Interpreters book for explanations. Nonetheless, to get jlox working in Csharp some differences are unavoidable.

Noted differences from jlox (or mostly Java vs C#)

  • "clock()" is defined in NativeFunctions.cs. There were problems trying to cram the clock class into to the function argument as jlox did.
  • C# dictionary behaves differently from Java hashmap so checking and handling is done to see if added keys already exists.
  • The Resolver's "scopes "stack was implemented as a list. C# doesn't access stacks by index number (in resolveLocal). There were work arounds to use Linq, but I prefer doing things in a minimal way.
  • The TokenType enum members maintain their prefix.
  • Substring behaves differently in C#. In Java, the second argument is the ending index. In C#, the second argument is the length of the substring to be retrieved.
  • A public access modifier is placed where Java has none. It seems the implied default Java modifier is analogous to C#' "internal".
  • The override modifier is not necessary for C# interfaces (and in fact, shows up as an error).
  • "toString" in jlox classes are changed to "ToString" for correct printing.
  • globals cannot be assigned to environment in Csharp's field initializations, hence it is done on Interpreter's constructor. An alternative coule be to make globals static.
  • object is used instead where jlox uses "Void"
  • ParseError is not allowed to be static.

That being said, despite not coding more than 100 lines of Java many many years ago (Hello World was enough to make me hate it back then), it is fairly safe to say that Java and C# are very similar.

About

Csharp port of Crafting Interpreters' jlox

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages