Skip to content

Lolcode spec fixes - #102

Open
novo52 wants to merge 6 commits into
masterfrom
lolcode-spec-fixes
Open

Lolcode spec fixes#102
novo52 wants to merge 6 commits into
masterfrom
lolcode-spec-fixes

Conversation

@novo52

@novo52 novo52 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Some fixes/clarifications to the lolcode spec

novo52 added 6 commits July 28, 2026 11:33
IT was used ("if IT can be cast to WIN") without ever being introduced.
Doc claimed "three types" while listing four; clarify TROOF is a value
type produced by comparisons, not a declarable variable type.
LOLCODE's math operators are fully bracketed by keywords (SUM OF x AN y),
so there's no ambiguous infix chain for precedence rules to resolve; this
was unadapted leftover content.
The "types must match" requirement contradicted this doc's own math-operator
casting rule and the official LOLCODE spec, which auto-casts YARN/NUMBR the
same way for both.
The official LOLCODE spec never specifies scope more finely than
function/main-block level, leaving if/loop block scoping undefined.
State it explicitly for this course's implementation.

Parenthesis ('()') can be used to group operations to override precedence or
clarify the evaluation order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precedence is implicit because of the operators

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the parenthesis because I didn't understand how precedence works. Can you show me some examples? Can we put them in the spec so it's clear for the students?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might get it: is x+2*y written as sum of x an produkt of 2 an y?

@novo52 novo52 Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. And (x+2)*y is written as produkt of sum of x an 2 an y

All variable scope is local to the main program block.
Variables are only accessible after declaration, and there is no global scope.

Blocks introduced by ``O RLY?``/``YA RLY``/``MEBBE``/``NO WAI``, ``WTF?``/``OMG``, and ``IM IN YR``/``IM OUTTA YR`` are their own scope: a variable declared with ``I HAS A`` inside one of these blocks is only visible within that block, and ceases to exist once the block ends.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is the intention, we may also want a single global scope? However, the

IM IN YR <label> <operation> YR <variable> [TIL|WILE <expression>]
  <code block>
IM OUTTA YR <label>

loop has a temporary local variable, so they have to do scoping anyway.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I had a Scope section that reads something like:

All variable scope, as of this version, is local to the enclosing function or to the main program block. Variables are only accessible after declaration, and there is no global scope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is that section. However,

  1. This version does not have functions
  2. <variable> in the loop example above is local according to the spec, so your scope rule alone is inconsistent with this part of the spec.

I would prefer that we have no scope, as SCalc has no scope and I have written VCalc exams with the assumption that VCalc introduces scoping. However, IDK how to resolve this—maybe the loop requires an already declared variable?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reading of the Scope section is that there is no scope since we don't have functions, i.e. it already was like SCalc. Somehow I thought you were adding block scoping with your suggested changes.

I suggest we resolve the weird loop iterators exactly as intended by the spec: they are special variables that do not need to be declared and only exist within their loop body. That's the great fun of inventing your own language - you can do whatever you want!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I was saying, but I no longer hold that position.

I am thinking of how the student implement the parser/interpreter. If there are these temporary variables that only exist within the loop body, then they must implement a scope table—which they did not have to do for SCalc. Then, lolcode does not have global scope, it also has block scoping rules, but only for this one specific part of the language.

I think this is not educational for the students, and we should either do real block scoping (not recommended) or get rid of this specific type of block scoping (recommended).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decision: advise students they should not bother with a scope table, all global scope except for implicit loop vars.

Note: investigate nested loops

~~~~~

For the purposes of this assignment, LOLCODE only recognizes three types:
For the purposes of this assignment, LOLCODE recognizes four types, though only three of them can be declared as variables:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is like SCalc

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCalc (and VCalc) only have integers. I found the interpreter was much trickier to write with two types (and automatic promotion). It actually made we want to do more passes (symbol creation and type checking) before doing the interpreter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I say "this is like SCalc", I mean that SCalc also has an implicit boolean type that exists for conditionals but can not be explicitly created by the programmer.

@novo52
novo52 requested a review from rcunrau July 28, 2026 17:43

@rcunrau rcunrau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good analysis and good suggestions!


These operators apply to both strings and integers. Since both types are
supported, the types of ``<x>`` and ``<y>`` must match.
These operators apply to both strings and integers. As with the math operators above, if either argument is a ``YARN``, it is converted to an integer and the operation proceeds if the conversion succeeds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going from the compare op in the spec:

Comparisons are performed as integer math in the presence of two NUMBRs, but if either of the expressions are NUMBARs, then floating point math takes over. Otherwise, there is no automatic casting in the equality, so BOTH SAEM "3" AN 3 is FAIL.

If-then
~~~~~~~

A bare expression statement (one not assigned to a variable) stores its result in the implicit variable ``IT``. ``IT`` holds that value until the next bare expression replaces it, and is what ``O RLY?`` and ``WTF?`` test against.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IT is used in a bunch of places in the spec, but not anywhere else in our spec. Do you think we should introduce it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decision: Remove IT, use explicit conditions in every case

All variable scope is local to the main program block.
Variables are only accessible after declaration, and there is no global scope.

Blocks introduced by ``O RLY?``/``YA RLY``/``MEBBE``/``NO WAI``, ``WTF?``/``OMG``, and ``IM IN YR``/``IM OUTTA YR`` are their own scope: a variable declared with ``I HAS A`` inside one of these blocks is only visible within that block, and ceases to exist once the block ends.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I had a Scope section that reads something like:

All variable scope, as of this version, is local to the enclosing function or to the main program block. Variables are only accessible after declaration, and there is no global scope.

~~~~~

For the purposes of this assignment, LOLCODE only recognizes three types:
For the purposes of this assignment, LOLCODE recognizes four types, though only three of them can be declared as variables:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCalc (and VCalc) only have integers. I found the interpreter was much trickier to write with two types (and automatic promotion). It actually made we want to do more passes (symbol creation and type checking) before doing the interpreter.


Parenthesis ('()') can be used to group operations to override precedence or
clarify the evaluation order.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the parenthesis because I didn't understand how precedence works. Can you show me some examples? Can we put them in the spec so it's clear for the students?


Parenthesis ('()') can be used to group operations to override precedence or
clarify the evaluation order.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might get it: is x+2*y written as sum of x an produkt of 2 an y?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants