Alright, so, I think I understand better now, and I am going to recommend you restructure your code a little bit. (Sorry!)
First, the syntax you shared with me leads me to the following syntaxis:
<symbol> ::= 'a' .. 'z'
<integer> ::= '-'? ('0'..'9')+
<value> ::= <symbol> | <integer>
<operator> ::= '+' | '-' | '*' | '/' | '=' | '<' | '<=' | '>' | '>=' | '!='
<expression> ::= <value> (<operator> <value>)*
<declaration> ::= 'INT' <symbol>
<assignment> ::= <symbol> '=' <expression>
<line-number> ::= <expression>
<jump> ::= 'JUMP' <line-number>
<if> ::= 'IF' '(' <expression> ')' 'THEN' <statement>
<output> ::= 'SHOW' <expression>
<statement> ::= <assignment> | <jump> | <output>
|
All statements are terminated by a newline.
This is very, VERY limited, but sufficient. Specifically:
• Input does not exist
• Output is limited to a single integer value, newline automatically appended
• IF cannot nest directly
• No ELSE
• No commentary possible
• Variable names are single, lowercase, alphabetic letters
• Mathematical expressions are managed strictly left-to-right (no precedence ordering)
• Comparison operators produce integer 0 or 1 for result
• IF executes THEN only if the argument expression evaluates to non-zero
Most of these limitations are significant — specifically with respect to the IF statement and how it affects the interpreter’s design. That said, at this point it is not too much to make major modifications should we wish to improve the language. Also, it is easy to start with; we can drop-in something like proper mathematical expression handling later.
@
Ivitoh
Let me know if the above syntaxis is incomplete or in any way incorrect.
Using that, we can write a program that will solve the following pair of congruences:
x ≡ 2 (mod 3)
x ≡ 3 (mod 7)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
INT a
INT m
a = 2
m = 3
INT b
INT n
b = 3
n = 7
IF (a = b) THEN JUMP 21
IF (a < b) THEN JUMP 18
b = b + n
JUMP 11
a = a + m
JUMP 11
SHOW a
m = m * n
SHOW m
|
When run, the program should produce the following output:
Which is correct:
x ≡ 17 (mod 21)
Let me know if we can continue from here.