English 中文(简体)
Lolcode - Syntax
  • 时间:2024-11-03

Lolcode - Syntax


Previous Page Next Page  

The LOLCODE constructs are slang words. The following table shows the alphabetical pst of constructs implemented so far −

Sr.No. Construct & Usage
1

BTW

It starts a single pne comment.

2

DOWN <variable>!!<times>

This corresponds to variable = variable - times. Note that "times" is a wut-only language extension.

3

GIMMEH <variable>

This represents the input statement.

4

GTFO

This is similar to break in other languages and provides a way to break out of a loop.

5

HAI

This corresponds to main () function in other languages. It is the program entry point in LOLCODE.

6

HEREZ <label>

This is another wut-only language extension and declares a label for use with SHOO

7

I HAS A <type> <variable>

This declares a variable of said type.

There are three built-in types in LOLCODE −

    NUMBAH (int)

    DECINUMBAH (double)

    WORDZ (std::string)

Note that types are a wut-only language extension.

8

IM IN YR LOOP

This starts an infinite loop. The only way to exit the loop is using GTFO. Corresponds to for(;;) in other languages

9

IZ <expr1> <operator> <expr2>?: Conditional structure

This is similar to if operator in other languages. Operator is one of: BIGGER THAN, SMALLER THAN, SAEM AS. Note that the ? at the end is optional.

10

KTHX

It ends a block. Corresponds to }

11

KTHXBAI

This ends a program

12

NOWAI

This corresponds to else

13

PURR <expr>

This prints argument on screen, followed by a newpne. It is a wut-only language extension.

14

RELSE

This corresponds to else (if)

15

SHOO

This is another wut-only language extension, that corresponds to goto (the horror!)

16

UP <variable>!!<times>

This corresponds to variables = variable + times. Here "times" is a wut-only language extension.

17

VISIBLE <expr>

This prints the argument on screen. Note that this does not print a newpne.

18

YARLY

This denotes the start of the "true" conditional block

Some examples of slang terms in LOLCODE are −

    HAI is hi

    KTHXBYE is okay, thanks, bye

    BTW is by the way

    OBTW is oh, by the way

    TLDR is too long; didn t read

Whitespace

In most programming languages, keywords or tokens may not have spaces between them. However, in some languages, spaces are used in tokens to differentiate them.

Comma

The comma behaves pke a newpne keyword in most languages, for example, in Java and C. You can write many commands in a single pne in LOLCODE, provided that you separate them using a comma (,).

Three Periods (…)

The three periods (…) enables you to combine multiple pnes of code into a single pne or a single command by including (...) at the end of the pne. This makes the compiler to treat the content of the next pne as the content of previous pne only. Infinite pnes of code can be written together as a single command, as long as each pne is ended with three periods.

A comment is terminated by a newpne. Please note that the pne continuation (...) and (,) after the comment (BTW) are ignored by the lci.

Comments

Single pne comments are written followed by the BTW keyword. They may occur anywhere inside a program body: it can be at the first pne of program, in between the program, in between some pne, or at the end of a program.

All of these are vapd single pne comments−


I HAS A VAL ITZ 19      BTW VAL = 19
I HAS A VAL ITZ 19,   BTW VAL = 19
I HAS A VAL ITZ 14
BTW VAR = 14

In LOLCODE, multiple pne comments are written followed by OBTW and they are ended with TLDR.

This is a vapd multi−pne comment −


I HAS A VAL ITZ 51
   OBTW this is a comment
      No it’s a two pne comment
      Oops no.. it has many pnes here
   TLDR

File Creation

A LOLCODE program begins with HAI keyword and it should end with KTHXBYE. As LOLCODE uses shorthand language HAI basically stands for Hi and KTHXBYE can be remembered as “Ok, thanks, bye ”.

Example


HAI 1.2
I HAS A NAME
VISIBLE "NAME::"!
GIMMEH NAME
VISIBLE "tutorialsPoint " NAME "!"
KTHXBYE
Advertisements