Skip to content

Lexer, parser, compiler and interpreter for the 'x' language, implemented in Java. Part of SFSU CSC413 coursework.

Notifications You must be signed in to change notification settings

tartunian/x-lang

Repository files navigation

x-lang

The purpose of this project is to learn about the compilation process of programming languages by implementing one in Java.

Completed Components

  • Lexer
  • Parser
  • Constrainer
  • Compiler
  • Interpreter

Tokens

  • And &
  • Assign =
  • BOOLean boolean
  • Case case
  • Char char
  • CharLit
  • Colon :
  • Comma ,
  • Comment //
  • Default default
  • Divide /
  • Else else
  • EndProgram XD
  • Equal ==
  • Function function
  • Greater >
  • GreaterEqual >=
  • INTeger
  • Identifier
  • If if
  • Int int
  • LeftBrace {
  • LeftParen (
  • Less <
  • LessEqual <=
  • Minus -
  • Multiply *
  • NotEqual !=
  • Or |
  • Plus +
  • Program program
  • Return return
  • RightBrace }
  • RightParen )
  • StringLit
  • StringType string
  • Switch switch
  • Then then
  • Unless unless
  • While while

Grammar

Production Description
TYPE->'char' Char Token
TYPE->'string' StringType Token
F→<char> Char literals
F→<string> String literals
S→'if' E 'then' BLOCK if statement (without else)
S→'unless' E 'then' BLOCK unless statement
SwitchBlock→'{' CaseStatement+ DefaultStatement? '}' switch statement block (one or more case statements followed by none or one default statement)
CaseStatement→'case' <int> ':' S case statement with only one statement
DefaultStatement→'default' ':' S default statement with only one statement
E→SE '>' SE Greater token
E→SE '>=' SE GreaterEqual token

Compilation

Batch files are provided for compiling and executing most components. For example, to compile the lexer, run clexer in the project root. To run the lexer, run lexer {source_file}. The commands which accept a source file as input use sample_files\simple.x as a default source file.

Written with StackEdit.

About

Lexer, parser, compiler and interpreter for the 'x' language, implemented in Java. Part of SFSU CSC413 coursework.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages