home *** CD-ROM | disk | FTP | other *** search
- Comment
- ==================================================================
-
- This section contains the logic for processing IF statements. I'm
- writing an interpreter language in MarxMenu. You can add your own
- conditionals for IniTyme here.
-
- ==================================================================
- EndComment
-
-
- Procedure PushStack (V)
- AppendArray(Stack,V)
- EndProc
-
-
- Procedure PopStack
- var X
- if NumberOfElements(Stack) = 0
- Error ('Stack Empty!',LoopIndex)
- endif
- X = Stack[NumberOfElements(Stack)]
- delete(Stack,NumberOfElements(Stack),1)
- Return X
- EndProc
-
-
- Procedure Nugget
- var Word P FirstChar
- Trim(IfLine)
- FirstChar = Left(IfLine,1)
- Word = NextWord(IfLine)
-
- if FirstChar Within('0','9')
- PushStack(Value(Word))
-
- elseif (FirstChar = '"') or (FirstChar = "'")
- PushStack(Word)
-
- else
- P = Hash(Word)
- if P <> Nil
- Run P
- else
- Error ('Word "' + Word + '" not Recognized!',LoopIndex)
- endif
- endif
-
- EndProc
-
-
- Procedure Interpret
- while IfLine > ''
- Nugget
- endwhile
- EndProc
-
-
- Procedure ExecValueOf
- var V P St
- V = UpperCase(NextWord(IfLine))
- if Right(V,1) <> '=' then V = V + '='
- P = FindLine(V)
- if P = 0
- PushStack('')
- else
- St = Orig[P]
- delete(St,1,pos('=',St))
- Trim(St)
- PushStack(St)
- endif
- EndProc
-
-
- Procedure ExecPlus
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A + B)
- EndProc
-
-
- Procedure ExecMinus
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A - B)
- EndProc
-
-
- Procedure ExecEqual
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A = B)
- EndProc
-
-
- Procedure ExecNotEqual
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A <> B)
- EndProc
-
-
- Procedure ExecGreater
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A > B)
- EndProc
-
-
- Procedure ExecLess
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A < B)
- EndProc
-
-
- Procedure ExecGreaterEqual
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A >= B)
- EndProc
-
-
- Procedure ExecLessEqual
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A <= B)
- EndProc
-
-
- Procedure ExecAnd
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A and B)
- EndProc
-
-
- Procedure ExecOr
- var A B
- Nugget
- B = PopStack
- A = PopStack
- PushStack(A or B)
- EndProc
-
-
- Procedure ExecNot
- Nugget
- PushStack(not PopStack)
- EndProc
-
-
- Procedure ExecUpperCase
- Nugget
- PushStack(UpperCase(PopStack))
- EndProc
-
-
- Procedure ExecLeftParen
- var OldParenLevel
- ParenLevel = ParenLevel + 1
- repeat
- Nugget
- until ParenLevel = OldParenLevel
- EndProc
-
-
- Procedure ExecRightParen
- ParenLevel = ParenLevel - 1
- EndProc
-
-
- Procedure ExecIf
- Interpret
- if not PopStack
- LoopIndex = GoToList[LoopIndex]
- endif
- EndProc
-
-
- Procedure ExecGoTo
- LoopIndex = GoToList[LoopIndex]
- EndProc
-
-
- Procedure ExecInGroup
- var Group
- Group = UpperCase(NextWord(IfLine))
- PushStack(PosInSortedList(Group,GroupList) > 0)
- EndProc
-
-
- Procedure ExecExistFile
- PushStack(ExistFile(UpperCase(NextWord(IfLine))))
- EndProc
-
-
- Procedure ExecExistDir
- PushStack(ExistDir(UpperCase(NextWord(IfLine))))
- EndProc
-
-
- Procedure ExecEnvVar
- PushStack(ReadEnv(UpperCase(NextWord(IfLine))))
- EndProc
-
-
- Procedure ExecCPU
- PushStack(CPUClass)
- EndProc
-
-
- Procedure ExecMathChip
- PushStack(McpClass > 0)
- EndProc
-
-
- Procedure ExecUserName
- PushStack(NovLoginName)
- EndProc
-
-
- Procedure ExecStation
- PushStack(NovStationAddress)
- EndProc
-
-
- Procedure ExecDisplay
- var Disp
- Disp = DisplayType
-
- if Disp = 0
- Return 'HERC'
-
- elseif Disp = 1
- Return 'CGA'
-
- elseif Disp = 3
- Return 'EGA'
-
- elseif Disp = 4
- Return 'VGA'
-
- else
- Return ''
-
- endif
- EndProc
-
-
- Procedure SetupLibWords
- HashLevel = 1
- Hash ('(') = Loc ExecLeftParen
- Hash (')') = Loc ExecRightParen
- Hash ('+') = Loc ExecPlus
- Hash ('-') = Loc ExecMinus
- Hash ('<>') = Loc ExecNotEqual
- Hash ('<') = Loc ExecLess
- Hash ('>') = Loc ExecGreater
- Hash ('<=') = Loc ExecLessEqual
- Hash ('>=') = Loc ExecGreaterEqual
- Hash ('=') = Loc ExecEqual
- Hash ('AND') = Loc ExecAnd
- Hash ('OR') = Loc ExecOr
- Hash ('NOT') = Loc ExecNot
- Hash ('GOTO') = Loc ExecGoto
- Hash ('IF') = Loc ExecIf
- Hash ('INGROUP') = Loc ExecInGroup
- Hash ('STATION') = Loc ExecStation
- Hash ('USERNAME') = Loc ExecUserName
- Hash ('VALUEOF') = Loc ExecValueOf
- Hash ('UPPERCASE') = Loc ExecUpperCase
- Hash ('EXISTFILE') = Loc ExecExistFile
- Hash ('EXISTDIR') = Loc ExecExistDir
- Hash ('ENVVAR') = Loc ExecEnvVar
- Hash ('READENV') = Loc ExecEnvVar
- Hash ('CPU') = Loc ExecCPU
- Hash ('MATHCHIP') = Loc ExecMathChip
- Hash ('DISPLAY') = Loc ExecDisplay
- EndProc
-