' Der Mathematische Parser

'-------------------------------------------------------------------------
SUB Mparse(curLine$)

	IF pos0(curLine$,"+") > 0 THEN
        	Mparse anfang$(curLine$,"+")
                PRINT #2,"	push	ax"
                Mparse ende$(curLine$,"+")
                PRINT #2,"	pop	bx"
                PRINT #2,"	add	ax,bx"
        ELSEIF pos0(curLine$,"-") > 0 THEN
        	Mparse anfang$(curLine$,"-")
                PRINT #2,"	push	ax"
                Mparse ende$(curLine$,"-")
                PRINT #2,"	pop	bx"
                PRINT #2,"	sub	ax,bx"
        ELSE
                var%=searchVAR(curLine$)
                IF var% > 0 THEN
                	PRINT #2,"	mov	ax,"+posVAR(var%)
                ELSE
                	PRINT #2,"	mov	ax,"+curLine$
                END IF
        END IF

END SUB

'-------------------------------------------------------------------------
' Gibt den Anfang einer Zeichenkette
FUNCTION anfang$(Kette$,Suche$)
	FUNCTION=LEFT$(Kette$,INSTR(Kette$,Suche$)-1)
END FUNCTION

'-------------------------------------------------------------------------
' Gibt das Ende einer Zeichenkette durch
FUNCTION ende$(Kette$,Suche$)
        FUNCTION=MID$(Kette$,INSTR(Kette$,Suche$)+1)
END FUNCTION

'-------------------------------------------------------------------------
' Durchsucht eine Kette nach einem Zeichen ausserhalb der Klammern!
FUNCTION pos0(Kette$,Suche$) AS INTEGER
        FOR i%=1 TO LEN(Kette$)
        	C$=MID$(Kette$,i%,1)
                IF C$="(" THEN
                	INCR Klammer%
                ELSEIF C$=")" THEN
                	DECR Klammer%
                ELSEIF C$=Suche$ THEN
                        IF Klammer%=0 THEN
                		FUNCTION=i%
                        	EXIT FUNCTION
                        END IF
                END IF
        NEXT i%
END FUNCTION