This is a compiler for a programming language called Fairytale, which was created by me and Gianna Sheffield. Our code is able to take a Fairytale program and compile it into assembly code.
An example Fairytale hellworld program with correct syntax is as follows:
OnceUponATime
~s hello := "Hello World";
WRITE(hello);
TheEnd
The following is our Context Free Grammar that we dedsigned to form our language. *The little boxes should be arrows
#Start OnceUponATime TheEnd
{ }
:= ; #Assign #MustBeInSymbolTable
:= ; #Assign #MustBeInSymbolTable
:= ; #Assign #MustBeInSymbolTable
:= intLiteral ; #Assign
:= ; #Assign
:= ; #Assign
:= ; #Assign
; #DeclareNotAssign
methodName! #CallMethod
#DefineMethod
LOOP => DeLOOP #LoopNumTimes
LOOP ( ) => DeLOOP #WhileLoop
IF => ENDIF
IFe => ELSE ENDIF
READ ( ) ; #ReadInVariables
WRITE ( ) ; #WriteVariables
WRITE ( ) ; #WriteExpressions
WRITE ( ) ; #WriteStrings
WRITE ( ) ; #WriteBools
DEF methodName INED
AND
OR
>
>=
<
<=
==
!=
{, } #ReadId #AllIdentsMustBeInSymbolTable
{, } #WriteExpr
{, } #WriteString
{, } #WriteBoolean
stringLiteral { + stringLiteral #Concat }
someString
{ }
{ }
{ }
{ }
( )
IntLiteral #ProcessLiteral
OR
AND
NOT
( )
True #StoredAs1
False #StoredAs0
MultOp #ProcessOp
DivOp #ProcessOp
Mod #ProcessOp
PlusOp #ProcessOp
MinusOp #ProcessOp
Id #ProcessId
~i #Int
~s #String
~b #Boolean
EofSym #Finish