AI KI AGENT A FIXES
08:17 17/04/2026 A12: Create co2.inc for code common to co2 and co2m64
08:10 17/04/2026 A11: Disagree oxideutil.inc findreplace
07:52 17/04/2026 A10: More efficient lcase(), in SearchString (searchutil.inc
07:37 17/04/2026 A9: Extend filenamelen to 512, but stay with ansi filenames
01:26 17/04/2026 A8: Static array hfont[4]... DeleteObjecthfont[1] etc
00:30 17/04/2026 A7: Restructure CompilerInfo() (OxideUtil.inc)
00:05 17/04/2026 A6: Comment out md expression in Oxide
23:52 16/04/2026 A5: Disagree Peroxide file saving
21:40 16/04/2026 A4: Fix text line buffer size s=nuls 512
21:29 16/04/2026 A3: Fix FindFirstFile : if h>0
14:02 16/04/2026 A2: Fix return codes from exec() etc. (sysutil.inc)
13:52 16/04/2026 A1: Make co2 and co2m64 compilers commandlinecase-sensitive (tools\co2*)
function getVar(string nn) as double
int i
string name=nn
name = normalizeName(name)
for i = 0 to varCount-1
if varName[i] = name then return varValue[i]
next
string msg = "Unknown variable: "
msg += name
setError(msg)
return 0
end function'parser
'Nicola Piano con aiuto di copilot
'15-04-2026
'Modificato
use console
indexbase 0
' ============================
' GLOBALI
' ============================
string expr
sys pos
string varName[20]
double varValue[20]
int varCount = 0
declare function parseExpression() as double
'declare function parseTerm() as double
'declare function parsePower() as double
'declare function parseFactor() as double
' ============================
' VARIABILI
' ============================
sub setVar(string name, double value)
varName[varCount] = name
varValue[varCount] = value
varCount++
end sub
function getVar(string name) as double
int i
for i = 0 to varCount-1
if varName[i] = name then return varValue[i]
next
print "Unknown variable: " name
return 0
end function
' ============================
' LETTURA CARATTERI
' ============================
function peek() as byte
if pos < len(expr) then
return asc(mid(expr, pos+1, 1))
else
return 0
end if
end function
sub advance()
pos++
end sub
sub skipSpaces()
while peek() = 32 or peek() = 9 or peek() = 160
advance()
wend
end sub
' ============================
' PARSER
' ============================
function parseFactor() as double
skipSpaces()
' --- UNARIO + e - ---
if peek() = asc("-") then
advance()
return -parseFactor()
elseif peek() = asc("+") then
advance()
return parseFactor()
end if
' parentesi
if peek() = asc("(") then
advance()
double v = parseExpression()
skipSpaces()
if peek() = asc(")") then advance()
return v
end if
' numero
if peek() >= asc("0") and peek() <= asc("9") then
double v = val(mid(expr, pos+1))
while (peek() >= asc("0") and peek() <= asc("9")) or peek() = asc(".")
advance()
wend
return v
end if
' variabile
if (peek() >= asc("a") and peek() <= asc("z")) or _
(peek() >= asc("A") and peek() <= asc("Z")) then
string name = ""
while (peek() >= asc("a") and peek() <= asc("z")) or _
(peek() >= asc("A") and peek() <= asc("Z"))
name += chr(peek())
advance()
wend
return getVar(name)
end if
return 0
end function
function parsePower() as double
double base = parseFactor()
skipSpaces()
' ^ destra-associativo: 2^3^2 = 2^(3^2)
if peek() = asc("^") then
advance()
double exp = parsePower()
base = base ^ exp
end if
return base
end function
function parseTerm() as double
double v = parsePower()
skipSpaces()
while peek() = asc("*") or peek() = asc("/")
byte op = peek()
advance()
double v2 = parsePower()
if op = asc("*") then v = v * v2
if op = asc("/") then v = v / v2
skipSpaces()
wend
return v
end function
function parseExpression() as double
double v = parseTerm()
skipSpaces()
while peek() = asc("+") or peek() = asc("-")
byte op = peek()
advance()
double v2 = parseTerm()
if op = asc("+") then v = v + v2
if op = asc("-") then v = v - v2
skipSpaces()
wend
return v
end function
' ============================
' WRAPPER EVAL
' ============================
function eval(string s) as double
expr = s
pos = 0
return parseExpression()
end function
sub calc(string s)
printl "Expressione: " s " ----> Result: " eval(s)
end sub
' ============================
' TEST
' ============================
setVar("b", 2)
setVar("c", 5)
setVar("d", 7)
calc("341 -((b+c)*d^2 - 3)")
calc("(b+c)*d^2 - 3)")
calc("-3+2")
calc("2^3^2")
calc("-2^3^2")
waitPage created in 0.096 seconds with 16 queries.