home *** CD-ROM | disk | FTP | other *** search
/ TopWare Tools / TOOLS.iso / tools / top1478 / inityme.inc < prev    next >
Encoding:
Text File  |  1994-03-06  |  6.0 KB  |  309 lines

  1. Comment
  2. ==================================================================
  3.  
  4. This section contains the logic for processing IF statements. I'm
  5. writing an interpreter language in MarxMenu. You can add your own
  6. conditionals for IniTyme here.
  7.  
  8. ==================================================================
  9. EndComment
  10.  
  11.  
  12. Procedure PushStack (V)
  13.    AppendArray(Stack,V)
  14. EndProc
  15.  
  16.  
  17. Procedure PopStack
  18. var X
  19.    if NumberOfElements(Stack) = 0
  20.       Error ('Stack Empty!',LoopIndex)
  21.    endif
  22.    X = Stack[NumberOfElements(Stack)]
  23.    delete(Stack,NumberOfElements(Stack),1)
  24.    Return X
  25. EndProc
  26.  
  27.  
  28. Procedure Nugget
  29. var Word P FirstChar
  30.    Trim(IfLine)
  31.    FirstChar = Left(IfLine,1)
  32.    Word = NextWord(IfLine)
  33.  
  34.    if FirstChar Within('0','9')
  35.       PushStack(Value(Word))
  36.  
  37.    elseif (FirstChar = '"') or (FirstChar = "'")
  38.       PushStack(Word)
  39.  
  40.    else
  41.       P = PosInSortedList(Word,LibList)
  42.       if P > 0
  43.          Run LibProcList[P]
  44.       else
  45.          Error ('Word "' + Word + '" not Recognized!',LoopIndex)
  46.       endif
  47.    endif
  48.  
  49. EndProc
  50.  
  51.  
  52. Procedure Interpret
  53.    while IfLine > ''
  54.       Nugget
  55.    endwhile
  56. EndProc
  57.  
  58.  
  59. Procedure ExecValueOf
  60. var V P St
  61.    V = UpperCase(NextWord(IfLine))
  62.    if Right(V,1) <> '=' then V = V + '='
  63.    P = FindLine(V)
  64.    if P = 0
  65.       PushStack('')
  66.    else
  67.       St = Orig[P]
  68.       delete(St,1,pos('=',St))
  69.       Trim(St)
  70.       PushStack(St)
  71.    endif
  72. EndProc
  73.  
  74.  
  75. Procedure ExecPlus
  76. var A B
  77.    Nugget
  78.    B = PopStack
  79.    A = PopStack
  80.    PushStack(A + B)
  81. EndProc
  82.  
  83.  
  84. Procedure ExecMinus
  85. var A B
  86.    Nugget
  87.    B = PopStack
  88.    A = PopStack
  89.    PushStack(A - B)
  90. EndProc
  91.  
  92.  
  93. Procedure ExecEqual
  94. var A B
  95.    Nugget
  96.    B = PopStack
  97.    A = PopStack
  98.    PushStack(A = B)
  99. EndProc
  100.  
  101.  
  102. Procedure ExecNotEqual
  103. var A B
  104.    Nugget
  105.    B = PopStack
  106.    A = PopStack
  107.    PushStack(A <> B)
  108. EndProc
  109.  
  110.  
  111. Procedure ExecGreater
  112. var A B
  113.    Nugget
  114.    B = PopStack
  115.    A = PopStack
  116.    PushStack(A > B)
  117. EndProc
  118.  
  119.  
  120. Procedure ExecLess
  121. var A B
  122.    Nugget
  123.    B = PopStack
  124.    A = PopStack
  125.    PushStack(A < B)
  126. EndProc
  127.  
  128.  
  129. Procedure ExecGreaterEqual
  130. var A B
  131.    Nugget
  132.    B = PopStack
  133.    A = PopStack
  134.    PushStack(A >= B)
  135. EndProc
  136.  
  137.  
  138. Procedure ExecLessEqual
  139. var A B
  140.    Nugget
  141.    B = PopStack
  142.    A = PopStack
  143.    PushStack(A <= B)
  144. EndProc
  145.  
  146.  
  147. Procedure ExecAnd
  148. var A B
  149.    Nugget
  150.    B = PopStack
  151.    A = PopStack
  152.    PushStack(A and B)
  153. EndProc
  154.  
  155.  
  156. Procedure ExecOr
  157. var A B
  158.    Nugget
  159.    B = PopStack
  160.    A = PopStack
  161.    PushStack(A or B)
  162. EndProc
  163.  
  164.  
  165. Procedure ExecNot
  166.    Nugget
  167.    PushStack(not PopStack)
  168. EndProc
  169.  
  170.  
  171. Procedure ExecUpperCase
  172.    Nugget
  173.    PushStack(UpperCase(PopStack))
  174. EndProc
  175.  
  176.  
  177. Procedure ExecLeftParen
  178. var OldParenLevel
  179.    ParenLevel = ParenLevel + 1
  180.    repeat
  181.       Nugget
  182.    until ParenLevel = OldParenLevel
  183. EndProc
  184.  
  185.  
  186. Procedure ExecRightParen
  187.    ParenLevel = ParenLevel - 1
  188. EndProc
  189.  
  190.  
  191. Procedure ExecIf
  192.    Interpret
  193.    if not PopStack
  194.       LoopIndex = GoToList[LoopIndex]
  195.    endif
  196. EndProc
  197.  
  198.  
  199. Procedure ExecGoTo
  200.    LoopIndex = GoToList[LoopIndex]
  201. EndProc
  202.  
  203.  
  204. Procedure ExecInGroup
  205. var Group
  206.    Group = UpperCase(NextWord(IfLine))
  207.    PushStack(PosInSortedList(Group,GroupList) > 0)
  208. EndProc
  209.  
  210.  
  211. Procedure ExecExistFile
  212.    PushStack(ExistFile(UpperCase(NextWord(IfLine))))
  213. EndProc
  214.  
  215.  
  216. Procedure ExecExistDir
  217.    PushStack(ExistDir(UpperCase(NextWord(IfLine))))
  218. EndProc
  219.  
  220.  
  221. Procedure ExecEnvVar
  222.    PushStack(ReadEnv(UpperCase(NextWord(IfLine))))
  223. EndProc
  224.  
  225.  
  226. Procedure ExecCPU
  227.    PushStack(CPUClass)
  228. EndProc
  229.  
  230.  
  231. Procedure ExecMathChip
  232.    PushStack(McpClass > 0)
  233. EndProc
  234.  
  235.  
  236. Procedure ExecUserName
  237.    PushStack(NovLoginName)
  238. EndProc
  239.  
  240.  
  241. Procedure ExecStation
  242.    PushStack(NovStationAddress)
  243. EndProc
  244.  
  245.  
  246. Procedure ExecDisplay
  247. var Disp
  248.    Disp = DisplayType
  249.  
  250.    if Disp = 0
  251.       Return 'HERC'
  252.  
  253.    elseif Disp = 1
  254.       Return 'CGA'
  255.  
  256.    elseif Disp = 3
  257.       Return 'EGA'
  258.  
  259.    elseif Disp = 4
  260.       Return 'VGA'
  261.  
  262.    else
  263.       Return ''
  264.  
  265.    endif
  266. EndProc
  267.  
  268.  
  269. Procedure AddCommand (St,Cmd)
  270.    AppendArray(LibList,St)
  271.    AppendArray(LibProcList,Cmd)
  272. EndProc
  273.  
  274.  
  275. Procedure SetupLibWords
  276.  
  277.    AddCommand('(',Loc ExecLeftParen)
  278.    AddCommand(')',Loc ExecRightParen)
  279.    AddCommand('+',Loc ExecPlus)
  280.    AddCommand('-',Loc ExecMinus)
  281.    AddCommand('<>',Loc ExecNotEqual)
  282.    AddCommand('<',Loc ExecLess)
  283.    AddCommand('>',Loc ExecGreater)
  284.    AddCommand('<=',Loc ExecLessEqual)
  285.    AddCommand('>=',Loc ExecGreaterEqual)
  286.    AddCommand('=',Loc ExecEqual)
  287.    AddCommand('AND',Loc ExecAnd)
  288.    AddCommand('OR',Loc ExecOr)
  289.    AddCommand('NOT',Loc ExecNot)
  290.    AddCommand('GOTO',Loc ExecGoto)
  291.    AddCommand('IF',Loc ExecIf)
  292.    AddCommand('INGROUP',Loc ExecInGroup)
  293.    AddCommand('STATION',Loc ExecStation)
  294.    AddCommand('USERNAME',Loc ExecUserName)
  295.    AddCommand('VALUEOF',Loc ExecValueOf)
  296.    AddCommand('UPPERCASE',Loc ExecUpperCase)
  297.    AddCommand('EXISTFILE',Loc ExecExistFile)
  298.    AddCommand('EXISTDIR',Loc ExecExistDir)
  299.    AddCommand('ENVVAR',Loc ExecEnvVar)
  300.    AddCommand('READENV',Loc ExecEnvVar)
  301.    AddCommand('CPU',Loc ExecCPU)
  302.    AddCommand('MATHCHIP',Loc ExecMathChip)
  303.    AddCommand('DISPLAY',Loc ExecDisplay)
  304.  
  305.    SortArrayLinked(LibProcList,LibList)
  306.  
  307. EndProc
  308.  
  309.