Skip to content

Commit

Permalink
close #18, change ʟ to ɔ
Browse files Browse the repository at this point in the history
  • Loading branch information
bigyihsuan committed Jun 23, 2020
1 parent 964f2dd commit c1c3b2b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions sample/factorial.ipel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<factorialCommented> (n -- n!)
/

b1əɐʌʟ|end| (go to end if n==1. skip jump if n!=1)
b1əɐʌɔ|end| (go to end if n==1. skip jump if n!=1)

|loop| (while top != 1, duplicate and decrement)
(check if top == 1 to go to multiplication)
Expand All @@ -23,7 +23,7 @@ b (dup)

ʌ (skip next if a==b)
(-- n n-1)
ʟ|loop| (jump to loop start if a!=b)
ɔ|loop| (jump to loop start if a!=b)

|mult| (begin loop for multiplication)
(-- n n-1 n-2 ... 2 1)
Expand All @@ -38,11 +38,11 @@ t (push stack size)
(-- n n-1 n-2 ... 3 2 size==1?)

ʌ (skip next if size==1)
ʟ|mult| (loop if not)
ɔ|mult| (loop if not)
|end|
\

<factorial>/b1əɐʌʟ|end||loop|b1zb1əʌʟ|loop||mult|ft1əʌʟ|mult||end|\
<factorial>/b1əɐʌɔ|end||loop|b1zb1əʌɔ|loop||mult|ft1əʌɔ|mult||end|\

<f>/
1 (push 1)
Expand Down
4 changes: 2 additions & 2 deletions sample/fib.ipel
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<fib>/b1ɨʌʟ|end|1zb1z<fib>d<fib>s|end|\
<fib>/b1ɨʌɔ|end|1zb1z<fib>d<fib>s|end|\

<fibCommented> (n1 -- n2)
(generates the n1-th fibonacci number)
/
(check for 1)
b1ɨʌʟ|end|
b1ɨʌɔ|end|

(else)
(do fib)
Expand Down
6 changes: 3 additions & 3 deletions sample/fizzbuzz.ipel
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{101}1ɑeb3ⱱɐbʌʟ|a|"Fizz"u|a|q5ⱱɐbʌʟ|b|"Buzz"u|b|ɞʌue1sø"\n"uɒ
{101}1ɑeb3ⱱɐbʌɔ|a|"Fizz"u|a|q5ⱱɐbʌɔ|b|"Buzz"u|b|ɞʌue1sø"\n"uɒ

{101}1 (push loop bounds 1 to 101)
ɑ (start loop)
eb (push and dup loop index)
3ⱱɐbʌʟ|c|"Fizz"u|c| (print if fizzy)
3ⱱɐbʌɔ|c|"Fizz"u|c| (print if fizzy)
q (OVER)
5ⱱɐbʌʟ|d|"Buzz"u|d| (print if buzzy)
5ⱱɐbʌɔ|d|"Buzz"u|d| (print if buzzy)
ɞʌu (else print the number)
e1sø (increment loop index)
"\n"u (print a newline)
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def evaluate(lex, lab, debugmode, unvoiced, voiced, executionStack, currentStack
currentStack.append(eval(list))

if lex[ep].token == T.INSTRUCTION:
if lex[ep].lexeme == "ʟ": # Unconditional jump
if lex[ep].lexeme == "ɔ": # Unconditional jump
ep = lab[lex[ep+1].lexeme]
elif lex[ep].lexeme == "ʌ": # Conditional skip
truthy = False
Expand Down
8 changes: 4 additions & 4 deletions src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def mapLabels(self, lex, lab):
loops.append(i+1) # push a LOOPSTART's index
if i < len(lex):
if lex[i].token == T.LABEL and lex[i].lexeme not in lab:
if i > 0 and lex[i-1].lexeme != "ʟ":
if i > 0 and lex[i-1].lexeme != "ɔ":
lab[lex[i].lexeme] = i
elif i+1 < len(lex):
if lex[i].token == T.FUNNAME and lex[i+1].token == T.FUNDEFSTART:
Expand All @@ -36,7 +36,7 @@ def validateLexemes(self, lex, lab):
Validates the order of lexemes.
Input is a list of lexemes and a dictionary of labels.
Returns true if the lexeme list is valid.
For example, the Jump instruction is needs a COMMAND with lexeme=="ʟ"
For example, the Jump instruction is needs a COMMAND with lexeme=="ɔ"
followed by a LABEL that has been defined.
There weill always be a 1 FUNDEDSTART to each FUNDEFEND, as well as LISTBEGIN and LISTEND.
"""
Expand All @@ -58,7 +58,7 @@ def validateLexemes(self, lex, lab):
loops += 1
if lex[i].token == T.LOOPEND:
loops -= 1
if lex[i].token == T.INSTRUCTION and lex[i].lexeme == "ʟ":
if lex[i].token == T.INSTRUCTION and lex[i].lexeme == "ɔ":
if i+1 < len(lex) and lex[i+1].token != T.LABEL:
errors.append("Missing label after JUMP at Lex {}".format(i))
if i+1 < len(lex):
Expand Down Expand Up @@ -92,7 +92,7 @@ def validateLexemes(self, lex, lab):
FunDef = FUNNAME FunBody
FunBody = FUNDEFSTART Code FUNDEFEND
FunCall = FUNNAME
Jump = "ʟ" LABEL
Jump = "ɔ" LABEL
INSTRUCTION
List = LISTBEGIN {Literal LISTSEP} LISTEND
Literal = NUMBER | STRING | List
Expand Down

0 comments on commit c1c3b2b

Please sign in to comment.