Project

layo

0.0
No commit activity in last 3 years
No release in over 3 years
Layo is a LOLCODE interpreter written in plain Ruby. It tries to conform to the LOLCODE 1.2 specification and supports everything described there. Supports interactive mode.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.10.0
 Project Readme

About

Layo is a LOLCODE interpreter written in Ruby. It tries to conform to the LOLCODE 1.2 specification and supports everything described there.

Usage

Through Rubygems:

gem install layo
layo program.lol

If you don't want to install the gem, you can download sources, extract somewhere and run from the project's root:

bin/layo program.lol

Layo treats source files as UTF-8 encoded, if your file contains non-ascii characters, be sure to encode it as UTF-8.

Without arguments Layo works in interactive mode, i.e. it executes statements read from a standard input. A sample session:

[galymzhan@g8host layo]$ bin/layo
Layo version 1.1.0
Press Control-C to exit
 > VISIBLE "HAI WORLD!"
HAI WORLD!
 > I HAS A animal ITZ "cat"
 > BOTH SAEM animal AN "cat", O RLY?
YA RLY, VISIBLE "I HAV A CAT"
NO WAI, VISIBLE "J00 SUX"
OIC
I HAV A CAT
 > ^CExiting

Oh, and there are tests too. In order to run them, you have to install mocha: gem install mocha. Then go to the project's root and execute rake test.

Requirements

  • Ruby >= 1.9.2
  • Mocha for development

LOLCODE examples

Classical hello world:

HAI 1.2
VISIBLE "Hello world!"
KTHXBYE

For more examples see examples and spec/source directories.

Grammar

Layo uses the following grammar to parse programs:

Program = "HAI 1.2" , Newline , Block , "KTHXBYE" ;
Block = { Statement } ;
Newline = ? Newline character (\r, \n, \r\n) or comma ? ;
Identifier = Letter , { Letter | Digit | "_" } ;
Letter = ? Capital or lowercase latin letter ? ;
Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
Type = "NOOB" | "TROOF" | "NUMBR" | "NUMBAR" | "YARN" ;

(* List of statements *)
Statement = ( AssignmentStatement | BreakStatement | CastStatement |
  ConditionStatement | DeclarationStatement | ExpressionStatement |
  FunctionStatement | InputStatement | LoopStatement |
  PrintStatement | ReturnStatement | SwitchStatement ) , Newline ;
AssignmentStatement = Identifier , "R" , Expression ;
BreakStatement = "GTFO" ;
CastStatement = Identifier , "IS NOW A" , Type ;
ConditionStatement = "O RLY?" , Newline , "YA RLY" , Newline , Block ,
  { "MEBBE" , Expression , Newline , Block } , (* else if branches *)
  [ "NO WAI" , Newline , Block ] , (* else branch *)
  "OIC" ;
DeclarationStatement = "I HAS A" , Identifier ,
  [ "ITZ" , Expression ] ; (* initialization expression *)
ExpressionStatement = Expression ;
FunctionStatement = "HOW DUZ I" , Identifier ,
  [ "YR" , Identifier , { "AN_YR" , Identifier } ] , (* argument list *)
  Newline , Block , "IF U SAY SO" ;
InputStatement = "GIMMEH" , Identifier ;
LoopStatement = "IM IN YR" , Identifier ,
  (* loop operation *)
  [ ( "UPPIN" | "NERFIN" | Identifier ) , "YR" , Identifier ] ,
  (* loop condition *)
  [ "TIL" | "WILE" , Expression ] ,
  Block , "IM OUTTA YR" , Identifier ;
PrintStatement = "VISIBLE" , Expression , { Expression } , [ "!" ] ;
ReturnStatement = "FOUND YR" , Expression ;
SwitchStatement = "WTF?" , Newline , SwitchCase , { SwitchCase } ,
  [ "OMGWTF" , Newline , Block ] , (* default case *)
  "OIC" ;
SwitchCase = "OMG" , ConstantExpression , Newline , Block ;

(* List of expressions *)
Expression = BinaryExpression | CastExpression | ConstantExpression |
  IdentifierExpression | NaryExpression | UnaryExpression ;
BinaryExpression = ( "SUM OF" | "DIFF OF" | "PRODUKT OF" | "QUOSHUNT OF" |
  "MOD OF" | "BIGGR OF" | "SMALLR OF" | "BOTH OF" | "EITHER OF" | "WON OF" |
  "BOTH SAEM" | "DIFFRINT" ) , Expression , Operand ;
Operand = [ "AN" ] , Expression ;
CastExpression = "MAEK" , Expression , "A" , Type ;
ConstantExpression = String | Number | "WIN" | "FAIL" ;
IdentifierExpression = Identifier ;
NaryExpression = ( "ALL OF" | "ANY OF" | "SMOOSH" ) ,
  Expression , Operand , { Operand } ;
UnaryExpression = "NOT" , Expression ;