home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / fp1os2.arj / OS2 / DATA / 49 / C / 0 / F_26836 / JScriptParser.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-15  |  17.3 KB  |  1,124 lines

  1. import java.io.PrintStream;
  2.  
  3. public class JScriptParser extends JSbxBase implements JScriptTokenInterface {
  4.    private JScriptTokenInterface aTokenInterface;
  5.    private JScriptCompiler aCompiler;
  6.    private JScriptExprParser aExprParser;
  7.    private JScriptErrorLog aErrorLog;
  8.    JSbxStack aStructLevelStack;
  9.    private JScriptCodeGenParam aCodeGenParam;
  10.    boolean bGenCode;
  11.    private JScriptModule aModule;
  12.    private JSbxVector aGlobalVarVector;
  13.    private JScriptCodeBlock aCodeBlock;
  14.    private boolean bEndOfStmtExpected;
  15.    private boolean bInFunction;
  16.    private JScriptMethod pFunctionObject;
  17.    private boolean bInEval;
  18.    private boolean bDebugCode;
  19.    private boolean bSourceAsPCode;
  20.    private boolean bDumpParsing;
  21.    private PrintStream aDebugOutStream;
  22.    private JScriptTokenPosition aActualTokenPos;
  23.    private JScriptTokenPosition aDebugStepPos;
  24.    private JScriptTokenPosition aStatementPos;
  25.    private String aSourceCodeStr;
  26.    private static final JSP_ClrExpStack aJSP_ClrExpStack = new JSP_ClrExpStack();
  27.    private static final JSP_EvalClrExpStack aJSP_EvalClrExpStack = new JSP_EvalClrExpStack();
  28.  
  29.    public void SetTokenInterface(JScriptTokenInterface var1) {
  30.       this.aTokenInterface = var1;
  31.    }
  32.  
  33.    public void SetErrorLog(JScriptErrorLog var1) {
  34.       this.aErrorLog = var1;
  35.    }
  36.  
  37.    JSbxStack GetStructLevelStack() {
  38.       return this.aStructLevelStack;
  39.    }
  40.  
  41.    private JScriptCodeGenParam GetCodeGenParam() {
  42.       return this.aCodeGenParam;
  43.    }
  44.  
  45.    public void SetGenCodeFlag(boolean var1) {
  46.       this.bGenCode = var1;
  47.       if (this.aCodeGenParam != null) {
  48.          this.aCodeGenParam.SetGenCodeFlag(var1);
  49.       }
  50.  
  51.    }
  52.  
  53.    private JScriptCodeBlock GetCodeBlock() {
  54.       return this.aCodeBlock;
  55.    }
  56.  
  57.    private void SetCodeBlock(JScriptCodeBlock var1) {
  58.       this.aCodeBlock = var1;
  59.       if (this.aCodeGenParam != null) {
  60.          this.aCodeGenParam.SetCodeBlock(var1);
  61.       }
  62.  
  63.    }
  64.  
  65.    public void SetDebug(boolean var1, boolean var2, PrintStream var3) {
  66.       this.bSourceAsPCode = var1;
  67.       this.bDebugCode = var2;
  68.       this.aDebugOutStream = var3;
  69.    }
  70.  
  71.    private void ClrSourceStr() {
  72.       this.aSourceCodeStr = "";
  73.       this.aStatementPos = null;
  74.    }
  75.  
  76.    private void AddSourceCode() {
  77.       if (this.bSourceAsPCode && this.bGenCode) {
  78.          this.ParserAddCode(new JSP_DebugSourceItem(this.aSourceCodeStr));
  79.          this.ClrSourceStr();
  80.       }
  81.  
  82.    }
  83.  
  84.    private void SetSourceCode(int var1) throws JSbxExceptionBase {
  85.       if (this.bSourceAsPCode && this.bGenCode && var1 >= 0) {
  86.          this.ParserSetCode(var1, new JSP_DebugSourceItem(this.aSourceCodeStr));
  87.          this.ClrSourceStr();
  88.       }
  89.  
  90.    }
  91.  
  92.    private int GetSourceCodePC() throws JSbxExceptionBase {
  93.       return this.bSourceAsPCode && this.bGenCode ? this.ParserAddCode((JScriptPCode)null) : -1;
  94.    }
  95.  
  96.    private void AddDebugStepCode() {
  97.       this.AddDebugStepCode(this.aDebugStepPos);
  98.       this.ClrDebugStepPos();
  99.    }
  100.  
  101.    private void AddDebugStepCode(JScriptTokenPosition var1) {
  102.       if (this.bDebugCode && this.bGenCode) {
  103.          this.ParserAddCode(new JSP_DebugStep(var1));
  104.       }
  105.  
  106.    }
  107.  
  108.    private void SetDebugStepCode(int var1) throws JSbxExceptionBase {
  109.       this.SetDebugStepCode(var1, this.aDebugStepPos);
  110.       this.ClrDebugStepPos();
  111.    }
  112.  
  113.    private void SetDebugStepCode(int var1, JScriptTokenPosition var2) throws JSbxExceptionBase {
  114.       if (this.bDebugCode && this.bGenCode) {
  115.          this.ParserSetCode(var1, new JSP_DebugStep(var2));
  116.       }
  117.  
  118.    }
  119.  
  120.    private int GetDebugStepPC() throws JSbxExceptionBase {
  121.       return this.bDebugCode && this.bGenCode ? this.ParserAddCode((JScriptPCode)null) : -1;
  122.    }
  123.  
  124.    private void ClrDebugStepPos() {
  125.       this.aDebugStepPos = null;
  126.    }
  127.  
  128.    private void GenClrExpStack() {
  129.       if (this.bInEval) {
  130.          this.ParserAddCode(aJSP_EvalClrExpStack);
  131.       } else {
  132.          this.ParserAddCode(aJSP_ClrExpStack);
  133.       }
  134.    }
  135.  
  136.    public JScriptParser(JScriptCompiler var1) {
  137.       this.Init();
  138.       this.aCompiler = var1;
  139.       this.aTokenInterface = this.aCompiler.GetTokenInterface();
  140.       this.aErrorLog = this.aCompiler.GetErrorLog();
  141.       this.bDumpParsing = false;
  142.    }
  143.  
  144.    private void Init() {
  145.       this.aCodeGenParam = new JScriptCodeGenParam();
  146.       this.aStructLevelStack = new JSbxStack(10);
  147.       this.aActualTokenPos = new JScriptTokenPosition();
  148.       this.aExprParser = new JScriptExprParser(this, this.aErrorLog);
  149.       this.bSourceAsPCode = false;
  150.       this.bDebugCode = false;
  151.       this.bDumpParsing = false;
  152.    }
  153.  
  154.    private void InitParsing() {
  155.       this.bEndOfStmtExpected = false;
  156.       this.pFunctionObject = null;
  157.       this.bInEval = false;
  158.       this.aDebugStepPos = null;
  159.       this.aStatementPos = null;
  160.       this.ClrSourceStr();
  161.       this.aModule = null;
  162.       this.aGlobalVarVector = null;
  163.    }
  164.  
  165.    void ParserError(JSbxExceptionBase var1) throws JScriptParserException {
  166.       String var2 = " --> Position:";
  167.       JScriptTokenPosition var3 = this.aActualTokenPos;
  168.       if (var1 instanceof JScriptTokenizerException) {
  169.          JScriptTokenizerException var4 = (JScriptTokenizerException)var1;
  170.          var3 = var4.GetErrorPosition();
  171.       }
  172.  
  173.       if (var3 != null) {
  174.          var2 = var2 + " line= " + var3.GetLine();
  175.          var2 = var2 + " col.= " + var3.GetCol();
  176.       } else {
  177.          var2 = var2 + " ???";
  178.       }
  179.  
  180.       this.aDebugOutStream.println(((Throwable)var1).getMessage() + var2);
  181.       if (!(var1 instanceof JScriptParserException)) {
  182.          throw new JScriptParserException(0, ((Throwable)var1).getMessage(), var3);
  183.       } else {
  184.          if (var1 instanceof JScriptTokenizerException) {
  185.             JScriptTokenizerException var7 = (JScriptTokenizerException)var1;
  186.             if (var7.GetErrorPosition() == null) {
  187.                var7.SetErrorPosition(this.aActualTokenPos);
  188.             }
  189.          }
  190.  
  191.          throw (JScriptParserException)var1;
  192.       }
  193.    }
  194.  
  195.    public int ParserAddCode(JScriptPCode var1) {
  196.       return this.bGenCode ? this.GetCodeBlock().AddCode(var1) : 0;
  197.    }
  198.  
  199.    public void ParserSetCode(int var1, JScriptPCode var2) throws JSbxExceptionBase {
  200.       if (this.bGenCode) {
  201.          this.GetCodeBlock().SetPCode(var1, var2);
  202.       }
  203.  
  204.    }
  205.  
  206.    public void ParseModule(JScriptModule var1, boolean var2) throws JScriptParserException {
  207.       this.InitParsing();
  208.       this.aModule = var1;
  209.       this.aGlobalVarVector = new JSbxVector();
  210.       this.SetCodeBlock(this.aModule.GetCodeBlock());
  211.       this.SetGenCodeFlag(var2);
  212.       this.ParseAll();
  213.       int var3 = this.aGlobalVarVector.GetSize();
  214.       if (var3 > 0) {
  215.          String[] var4 = new String[var3];
  216.  
  217.          for(int var5 = 0; var5 < var3; ++var5) {
  218.             String var6 = (String)this.aGlobalVarVector.Get(var5);
  219.             var4[var5] = var6;
  220.          }
  221.  
  222.          this.aModule.SetGlobalVarList(var4);
  223.       }
  224.  
  225.       this.aGlobalVarVector = null;
  226.    }
  227.  
  228.    public void RuntimeParse(JScriptModule var1, JScriptCodeBlock var2, JScriptMethod var3, boolean var4) throws JScriptParserException {
  229.       this.InitParsing();
  230.       this.aModule = var1;
  231.       JScriptMethod var5 = this.pFunctionObject;
  232.       boolean var6 = this.bInEval;
  233.       this.pFunctionObject = var3;
  234.       this.bInEval = var4;
  235.       this.SetCodeBlock(var2);
  236.       this.SetGenCodeFlag(true);
  237.       this.ParseAll();
  238.       if (this.pFunctionObject != null) {
  239.          this.pFunctionObject.LocalVarDefFinished();
  240.       }
  241.  
  242.       this.pFunctionObject = var5;
  243.       this.bInEval = var6;
  244.    }
  245.  
  246.    public void ParseAll() throws JScriptParserException {
  247.       try {
  248.          while(this.ParseStatement()) {
  249.          }
  250.  
  251.       } catch (JSbxExceptionBase var2) {
  252.          this.ParserError(var2);
  253.       }
  254.    }
  255.  
  256.    public boolean ParseStatement() throws JScriptParserException, JSbxExceptionBase {
  257.       boolean var1 = true;
  258.       this.ClrDebugStepPos();
  259.       JScriptToken var2 = this.PeekToken();
  260.       if (var2 == null) {
  261.          this.ParserAddCode(new JSP_Stop());
  262.          return false;
  263.       } else if (this.bEndOfStmtExpected) {
  264.          throw new JScriptParserException(2000, this.aActualTokenPos);
  265.       } else {
  266.          if (var2.GetType() != 2 || !var2.GetString().equalsIgnoreCase("print") && !var2.GetString().equalsIgnoreCase("nop")) {
  267.             if (var2.GetType() == 1 && var2.GetID() != 42 && var2.GetID() != 31) {
  268.                var1 = this.ParseKeywordStatement();
  269.                this.TestForEOS(false);
  270.             } else if (var2.GetType() == 5) {
  271.                if (var2.GetID() == 132) {
  272.                   try {
  273.                      this.NextToken();
  274.                   } catch (JScriptTokenizerException var4) {
  275.                   }
  276.                } else {
  277.                   if (var2.GetID() != 128) {
  278.                      throw new JScriptParserException(2019, this.aActualTokenPos);
  279.                   }
  280.  
  281.                   var1 = this.ParseBlock(false);
  282.                   this.TestForEOS(false);
  283.                }
  284.             } else {
  285.                this.bEndOfStmtExpected = true;
  286.                Object var8 = null;
  287.                JScriptParserExpression var9 = this.ParseExpression();
  288.                if (var9 == null) {
  289.                   throw new JScriptParserException(2001, this.aActualTokenPos);
  290.                }
  291.  
  292.                this.TestForEOS(false);
  293.                this.AddSourceCode();
  294.                this.AddDebugStepCode();
  295.                this.GetCodeGenParam().SetFlag_OptimizeIncDec(true);
  296.                var9.GenerateCode(this.GetCodeGenParam());
  297.                this.GetCodeGenParam().SetFlag_OptimizeIncDec(false);
  298.                this.GenClrExpStack();
  299.             }
  300.          } else {
  301.             if (var2.GetString().equalsIgnoreCase("print")) {
  302.                try {
  303.                   this.NextToken();
  304.                } catch (JScriptTokenizerException var6) {
  305.                }
  306.  
  307.                Object var3 = null;
  308.                JScriptParserExpression var7 = this.ParseExpression(true);
  309.                this.TestForEOS(false);
  310.                this.AddSourceCode();
  311.                this.AddDebugStepCode();
  312.                if (var7 != null) {
  313.                   var7.GenerateCode(this.GetCodeGenParam());
  314.                } else {
  315.                   this.ParserAddCode(new JSP_StringConst(""));
  316.                }
  317.  
  318.                this.ParserAddCode(new JSP_Print(this.aDebugOutStream));
  319.             }
  320.  
  321.             if (var2.GetString().equalsIgnoreCase("nop")) {
  322.                try {
  323.                   this.NextToken();
  324.                } catch (JScriptTokenizerException var5) {
  325.                }
  326.  
  327.                this.ParserAddCode(new JSP_Nop());
  328.             }
  329.          }
  330.  
  331.          return var1;
  332.       }
  333.    }
  334.  
  335.    private boolean ParseKeywordStatement() throws JSbxExceptionBase {
  336.       boolean var1 = true;
  337.       JScriptToken var2 = this.NextToken();
  338.       switch (var2.GetID()) {
  339.          case 3:
  340.             var1 = this.ParseBreak();
  341.             break;
  342.          case 10:
  343.             var1 = this.ParseContinue();
  344.             break;
  345.          case 14:
  346.             var1 = this.ParseElse();
  347.             break;
  348.          case 19:
  349.             var1 = this.ParseFor();
  350.             break;
  351.          case 20:
  352.             var1 = this.ParseFunction();
  353.             break;
  354.          case 22:
  355.             var1 = this.ParseIf();
  356.             break;
  357.          case 36:
  358.             var1 = this.ParseReturn();
  359.             break;
  360.          case 48:
  361.             var1 = this.ParseVar();
  362.             this.GenClrExpStack();
  363.             break;
  364.          case 50:
  365.             var1 = this.ParseWhile();
  366.             break;
  367.          case 51:
  368.             var1 = this.ParseWith();
  369.             break;
  370.          case 52:
  371.             var1 = this.ParseDelete();
  372.             break;
  373.          default:
  374.             throw new JScriptParserException(2004, this.aActualTokenPos);
  375.       }
  376.  
  377.       return var1;
  378.    }
  379.  
  380.    private boolean ParseBreak() throws JSbxExceptionBase {
  381.       this.AddSourceCode();
  382.       this.AddDebugStepCode();
  383.       if (this.bDumpParsing) {
  384.          this.aDebugOutStream.println("ParseBreak()");
  385.       }
  386.  
  387.       JScriptParserStructItem var1 = (JScriptParserStructItem)this.GetStructLevelStack().Peek();
  388.       if (var1 == null) {
  389.          throw new JScriptParserException(2005, this.aActualTokenPos);
  390.       } else {
  391.          int var2 = this.ParserAddCode((JScriptPCode)null);
  392.          var1.AddBreak(var2);
  393.          return true;
  394.       }
  395.    }
  396.  
  397.    private boolean ParseContinue() throws JSbxExceptionBase {
  398.       this.AddSourceCode();
  399.       this.AddDebugStepCode();
  400.       if (this.bDumpParsing) {
  401.          this.aDebugOutStream.println("ParseContinue()");
  402.       }
  403.  
  404.       JScriptParserStructItem var1 = (JScriptParserStructItem)this.GetStructLevelStack().Peek();
  405.       if (var1 == null) {
  406.          throw new JScriptParserException(2003, this.aActualTokenPos);
  407.       } else {
  408.          int var2 = this.ParserAddCode((JScriptPCode)null);
  409.          var1.AddContinue(var2);
  410.          return true;
  411.       }
  412.    }
  413.  
  414.    private boolean ParseDelete() throws JSbxExceptionBase {
  415.       int var1 = this.GetSourceCodePC();
  416.       int var2 = this.GetDebugStepPC();
  417.       JScriptParserExpression var3 = null;
  418.       this.bEndOfStmtExpected = true;
  419.       this.TestForEOS(false);
  420.       if (this.bEndOfStmtExpected) {
  421.          var3 = this.ParseExpression();
  422.       }
  423.  
  424.       if (var3 != null) {
  425.          var3.GenerateCode(this.GetCodeGenParam());
  426.          this.ParserAddCode(new JSP_Delete());
  427.          this.SetSourceCode(var1);
  428.          this.SetDebugStepCode(var2);
  429.          return true;
  430.       } else {
  431.          throw new JScriptParserException(2019, this.aActualTokenPos);
  432.       }
  433.    }
  434.  
  435.    private boolean ParseElse() throws JSbxExceptionBase {
  436.       throw new JScriptParserException(2002, this.aActualTokenPos);
  437.    }
  438.  
  439.    private boolean ParseFor() throws JSbxExceptionBase {
  440.       if (this.bDumpParsing) {
  441.          this.aDebugOutStream.println("ParseFor()");
  442.       }
  443.  
  444.       this.TestForLParam(true);
  445.       Object var1 = null;
  446.       JScriptParserExpression var2 = null;
  447.       Object var3 = null;
  448.       int var7 = this.GetSourceCodePC();
  449.       JScriptToken var8 = this.PeekToken();
  450.       Object var9 = null;
  451.       boolean var10 = false;
  452.       if (var8 != null && var8.GetID() == 48) {
  453.          this.NextToken();
  454.          this.ParseVar();
  455.          var10 = true;
  456.       } else {
  457.          JScriptParserExpression var18 = this.ParseExpression();
  458.          if (var18 != null) {
  459.             this.AddDebugStepCode();
  460.             this.GetCodeGenParam().SetFlag_ExpressionInForInStatement(true);
  461.             var18.GenerateCode(this.GetCodeGenParam());
  462.             this.GetCodeGenParam().SetFlag_ExpressionInForInStatement(false);
  463.             var10 = true;
  464.          }
  465.       }
  466.  
  467.       var8 = this.NextToken();
  468.       if (var8 == null) {
  469.          throw new JScriptParserException(2006, this.aActualTokenPos);
  470.       } else {
  471.          this.ClrDebugStepPos();
  472.          JScriptTokenPosition var11 = null;
  473.          boolean var12 = false;
  474.          JScriptParserStructItem var4;
  475.          int var5;
  476.          if (var8.GetID() == 25) {
  477.             var12 = true;
  478.             if (!var10) {
  479.                throw new JScriptParserException(2007, this.aActualTokenPos);
  480.             }
  481.  
  482.             JScriptParserExpression var16 = this.ParseExpression();
  483.             if (var16 == null) {
  484.                throw new JScriptParserException(2007, this.aActualTokenPos);
  485.             }
  486.  
  487.             var16.GenerateCode(this.GetCodeGenParam());
  488.             this.ParserAddCode(new JSP_InitForIn());
  489.             var5 = this.GetCodeBlock().GetNextCodePos();
  490.             var4 = new JScriptParserStructItem((short)25);
  491.             this.AddDebugStepCode();
  492.             this.ParserAddCode(new JSP_NextForIn());
  493.          } else {
  494.             if (var8.GetID() != 132) {
  495.                throw new JScriptParserException(2008, this.aActualTokenPos);
  496.             }
  497.  
  498.             if (var10) {
  499.                this.GenClrExpStack();
  500.             }
  501.  
  502.             var5 = this.GetCodeBlock().GetNextCodePos();
  503.             var4 = new JScriptParserStructItem((short)19);
  504.             JScriptParserExpression var15 = this.ParseExpression();
  505.             this.TestForEOS(true);
  506.             this.AddDebugStepCode();
  507.             if (var15 != null) {
  508.                var15.GenerateCode(this.GetCodeGenParam(), true);
  509.             } else {
  510.                this.ParserAddCode(new JSP_BoolConst(true));
  511.             }
  512.  
  513.             var2 = this.ParseExpression();
  514.             if (this.aDebugStepPos != null) {
  515.                var11 = (JScriptTokenPosition)this.aDebugStepPos.clone();
  516.             }
  517.          }
  518.  
  519.          this.TestForRParam(true);
  520.          this.SetSourceCode(var7);
  521.          this.GetStructLevelStack().Push(var4);
  522.          int var13 = this.ParserAddCode((JScriptPCode)null);
  523.          this.ParseStatement();
  524.          int var6;
  525.          if (var2 != null) {
  526.             if (var11 != null) {
  527.                this.AddDebugStepCode(var11);
  528.             }
  529.  
  530.             var6 = this.GetCodeBlock().GetNextCodePos();
  531.             this.GetCodeGenParam().SetFlag_OptimizeIncDec(true);
  532.             var2.GenerateCode(this.GetCodeGenParam());
  533.             this.GetCodeGenParam().SetFlag_OptimizeIncDec(false);
  534.             this.GenClrExpStack();
  535.          } else {
  536.             var6 = var5;
  537.          }
  538.  
  539.          this.ParserAddCode(new JSP_Jmp(var5));
  540.          int var14 = this.GetCodeBlock().GetNextCodePos();
  541.          var4.GenBreakJumps(this.GetCodeBlock(), var14);
  542.          var4.GenContinueJumps(this.GetCodeBlock(), var6);
  543.          this.GetCodeBlock().SetPCode(var13, new JSP_JmpIfFalse(var14));
  544.          if (var12) {
  545.             this.ParserAddCode(new JSP_ClrForIn());
  546.          }
  547.  
  548.          this.GetStructLevelStack().Pop();
  549.          return true;
  550.       }
  551.    }
  552.  
  553.    private boolean ParseFunction() throws JSbxExceptionBase {
  554.       if (this.pFunctionObject != null) {
  555.          throw new JScriptParserException(2009, this.aActualTokenPos);
  556.       } else {
  557.          JScriptTokenPosition var1 = (JScriptTokenPosition)this.aActualTokenPos.clone();
  558.          JScriptParserIdentifier var2 = this.ParseIdentifier();
  559.          if (var2 == null) {
  560.             throw new JScriptParserException(2010, this.aActualTokenPos);
  561.          } else {
  562.             String var3 = var2.aIdentifierName;
  563.             JScriptMethod var4 = new JScriptMethod(this.aModule, var3);
  564.             this.pFunctionObject = var4;
  565.             JScriptCodeBlock var5 = this.GetCodeBlock();
  566.             this.SetCodeBlock(var4.GetCodeBlock());
  567.             this.TestForLParam(true);
  568.             JSbxVector var6 = new JSbxVector();
  569.             boolean var7 = true;
  570.  
  571.             while(var7 && (var2 = this.ParseIdentifier()) != null) {
  572.                var6.Add(var2);
  573.                JScriptToken var8 = this.PeekToken();
  574.                var7 = false;
  575.                if (var8 != null && var8.GetID() == 94) {
  576.                   this.NextToken();
  577.                   var7 = true;
  578.                }
  579.             }
  580.  
  581.             int var14 = var6.GetSize();
  582.             if (var14 > 0) {
  583.                String[] var9 = new String[var14];
  584.  
  585.                for(int var10 = 0; var10 < var14; ++var10) {
  586.                   JScriptParserIdentifier var11 = (JScriptParserIdentifier)var6.Get(var10);
  587.                   var9[var10] = var11.aIdentifierName;
  588.                }
  589.  
  590.                var4.SetParameterList(var9);
  591.             }
  592.  
  593.             this.TestForRParam(true);
  594.             this.AddSourceCode();
  595.             this.AddDebugStepCode();
  596.             this.ParseBlock(true);
  597.             this.ParserAddCode(new JSP_Stop());
  598.             var1.SetEndPos(this.aActualTokenPos.GetEndPos());
  599.             var4.SetSourceCodePos(var1);
  600.             var4.LocalVarDefFinished();
  601.             this.pFunctionObject = null;
  602.  
  603.             try {
  604.                this.aModule.AddFunction(var4);
  605.             } catch (JSbxException var12) {
  606.             }
  607.  
  608.             this.SetCodeBlock(var5);
  609.             return true;
  610.          }
  611.       }
  612.    }
  613.  
  614.    private boolean ParseIf() throws JSbxExceptionBase {
  615.       if (this.bDumpParsing) {
  616.          this.aDebugOutStream.println("ParseIf()");
  617.       }
  618.  
  619.       int var1 = this.GetSourceCodePC();
  620.       int var2 = this.GetDebugStepPC();
  621.       this.TestForLParam(true);
  622.       JScriptParserExpression var3 = this.ParseExpression();
  623.       if (var3 == null) {
  624.          throw new JScriptParserException(2007, this.aActualTokenPos);
  625.       } else {
  626.          this.TestForRParam(true);
  627.          this.SetSourceCode(var1);
  628.          this.SetDebugStepCode(var2);
  629.          var3.GenerateCode(this.GetCodeGenParam(), true);
  630.          int var4 = this.ParserAddCode((JScriptPCode)null);
  631.          boolean var5 = this.ParseStatement();
  632.          int var6 = this.GetCodeBlock().GetNextCodePos();
  633.          JScriptToken var7 = this.PeekToken();
  634.          if (var7 != null && var7.GetID() == 14) {
  635.             int var8 = this.ParserAddCode((JScriptPCode)null);
  636.             this.NextToken();
  637.             this.AddSourceCode();
  638.             var6 = this.GetCodeBlock().GetNextCodePos();
  639.             var5 = this.ParseStatement();
  640.             int var9 = this.GetCodeBlock().GetNextCodePos();
  641.             this.GetCodeBlock().SetPCode(var8, new JSP_Jmp(var9));
  642.          }
  643.  
  644.          this.GetCodeBlock().SetPCode(var4, new JSP_JmpIfFalse(var6));
  645.          return true;
  646.       }
  647.    }
  648.  
  649.    private boolean ParseReturn() throws JSbxExceptionBase {
  650.       int var1 = this.GetSourceCodePC();
  651.       int var2 = this.GetDebugStepPC();
  652.       JScriptParserExpression var3 = null;
  653.       this.bEndOfStmtExpected = true;
  654.       this.TestForEOS(false);
  655.       if (this.bEndOfStmtExpected) {
  656.          var3 = this.ParseExpression();
  657.       }
  658.  
  659.       if (var3 != null) {
  660.          var3.GenerateCode(this.GetCodeGenParam());
  661.          this.ParserAddCode(new JSP_Return());
  662.       } else {
  663.          this.ParserAddCode(new JSP_Stop());
  664.       }
  665.  
  666.       this.SetSourceCode(var1);
  667.       this.SetDebugStepCode(var2);
  668.       return true;
  669.    }
  670.  
  671.    private boolean ParseVar() throws JSbxExceptionBase {
  672.       int var1 = this.GetSourceCodePC();
  673.  
  674.       boolean var3;
  675.       do {
  676.          JScriptParserIdentifier var4 = this.ParseIdentifier();
  677.          if (var4 == null) {
  678.             throw new JScriptParserException(2012, this.aActualTokenPos);
  679.          }
  680.  
  681.          String var5 = var4.aIdentifierName;
  682.          JScriptToken var6 = this.PeekToken();
  683.          JScriptParserExpression var2 = null;
  684.          if (var6 != null && var6.GetID() == 105) {
  685.             this.NextToken();
  686.             var2 = this.ParseExpression(true);
  687.             if (var2 == null) {
  688.                throw new JScriptParserException(2007, this.aActualTokenPos);
  689.             }
  690.  
  691.             var6 = this.PeekToken();
  692.          }
  693.  
  694.          this.AddDebugStepCode();
  695.          var3 = false;
  696.          if (var6 != null && var6.GetID() == 94) {
  697.             this.NextToken();
  698.             var3 = true;
  699.          }
  700.  
  701.          if (this.pFunctionObject != null) {
  702.             this.pFunctionObject.GetLocalVarVector().Add(var5);
  703.             this.ParserAddCode(new JSP_CreateLocal(var5, -1));
  704.          } else {
  705.             this.ParserAddCode(new JSP_CreateGlobal(var5, -1));
  706.             if (this.aGlobalVarVector != null) {
  707.                this.aGlobalVarVector.Add(var5);
  708.             }
  709.          }
  710.  
  711.          if (var2 != null) {
  712.             var2.GenerateCode(this.GetCodeGenParam());
  713.             this.ParserAddCode(new JSP_StoreIn(var5));
  714.          } else {
  715.             this.ParserAddCode(new JSP_Find(var5));
  716.          }
  717.  
  718.          if (var3) {
  719.             this.GenClrExpStack();
  720.          }
  721.       } while(var3);
  722.  
  723.       this.SetSourceCode(var1);
  724.       return true;
  725.    }
  726.  
  727.    private boolean ParseWhile() throws JSbxExceptionBase {
  728.       if (this.bDumpParsing) {
  729.          this.aDebugOutStream.println("ParseWhile()");
  730.       }
  731.  
  732.       int var1 = this.GetSourceCodePC();
  733.       this.TestForLParam(true);
  734.       JScriptParserExpression var2 = this.ParseExpression();
  735.       if (var2 == null) {
  736.          throw new JScriptParserException(2007, this.aActualTokenPos);
  737.       } else {
  738.          this.TestForRParam(true);
  739.          this.SetSourceCode(var1);
  740.          int var3 = this.GetCodeBlock().GetNextCodePos();
  741.          this.AddDebugStepCode();
  742.          JScriptParserStructItem var5 = new JScriptParserStructItem((short)50);
  743.          this.GetStructLevelStack().Push(var5);
  744.          var2.GenerateCode(this.GetCodeGenParam(), true);
  745.          int var6 = this.ParserAddCode((JScriptPCode)null);
  746.          this.ParseStatement();
  747.          this.ParserAddCode(new JSP_Jmp(var3));
  748.          int var7 = this.GetCodeBlock().GetNextCodePos();
  749.          var5.GenBreakJumps(this.GetCodeBlock(), var7);
  750.          var5.GenContinueJumps(this.GetCodeBlock(), var3);
  751.          this.GetCodeBlock().SetPCode(var6, new JSP_JmpIfFalse(var7));
  752.          this.GetStructLevelStack().Pop();
  753.          return true;
  754.       }
  755.    }
  756.  
  757.    private boolean ParseWith() throws JSbxExceptionBase {
  758.       if (this.bDumpParsing) {
  759.          this.aDebugOutStream.println("ParseWith()");
  760.       }
  761.  
  762.       int var1 = this.GetSourceCodePC();
  763.       this.TestForLParam(true);
  764.       JScriptParserExpression var2 = this.ParseExpression();
  765.       if (var2 == null) {
  766.          throw new JScriptParserException(2007, this.aActualTokenPos);
  767.       } else {
  768.          this.TestForRParam(true);
  769.          this.SetSourceCode(var1);
  770.          this.AddDebugStepCode();
  771.          var2.GenerateCode(this.GetCodeGenParam());
  772.          this.ParserAddCode(new JSP_PushWith());
  773.          this.ParseStatement();
  774.          this.ParserAddCode(new JSP_PopWith());
  775.          return true;
  776.       }
  777.    }
  778.  
  779.    private boolean ParseBlock(boolean var1) throws JSbxExceptionBase {
  780.       if (this.bDumpParsing) {
  781.          this.aDebugOutStream.println("ParseBlock()");
  782.       }
  783.  
  784.       this.bEndOfStmtExpected = false;
  785.       JScriptToken var2 = this.PeekToken();
  786.       if (var2 == null) {
  787.          return false;
  788.       } else {
  789.          boolean var3 = false;
  790.          if (var2.GetID() == 128) {
  791.             var3 = true;
  792.             this.NextToken();
  793.             this.AddSourceCode();
  794.             boolean var4 = false;
  795.  
  796.             do {
  797.                var2 = this.PeekToken();
  798.                if (var2 == null) {
  799.                   throw new JScriptParserException(2006, this.aActualTokenPos);
  800.                }
  801.  
  802.                short var5 = var2.GetID();
  803.                if (var5 == 129) {
  804.                   var4 = true;
  805.                   this.NextToken();
  806.                   this.AddSourceCode();
  807.                } else {
  808.                   this.ParseStatement();
  809.                }
  810.             } while(!var4);
  811.  
  812.             this.bEndOfStmtExpected = false;
  813.             return true;
  814.          } else if (var1) {
  815.             throw new JScriptParserException(2006, this.aActualTokenPos);
  816.          } else {
  817.             return this.ParseStatement();
  818.          }
  819.       }
  820.    }
  821.  
  822.    public JScriptParserTerm ParseTerm() throws JSbxExceptionBase {
  823.       return this.ParseTerm(false);
  824.    }
  825.  
  826.    public JScriptParserTerm ParseTerm(boolean var1) throws JSbxExceptionBase {
  827.       if (this.bDumpParsing) {
  828.          this.aDebugOutStream.println("ParseTerm()");
  829.       }
  830.  
  831.       Object var2 = null;
  832.       JScriptParserTerm var11 = new JScriptParserTerm();
  833.       boolean var4 = false;
  834.       JScriptToken var5 = this.PeekToken();
  835.       if (var5 != null && var5.GetID() == 31) {
  836.          this.NextToken();
  837.          var4 = true;
  838.          var11.bUsedForNew = true;
  839.       }
  840.  
  841.       boolean var6 = true;
  842.  
  843.       JScriptParserSubTerm var3;
  844.       while((var3 = this.ParseSubTerm(var6, var1)) != null) {
  845.          var6 = false;
  846.          var11.AddSubTerm(var3);
  847.          var5 = this.PeekToken();
  848.          if (var5 == null || var5.GetID() != 133) {
  849.             break;
  850.          }
  851.  
  852.          this.NextToken();
  853.       }
  854.  
  855.       if (var11.GetSubTermCount() == 0) {
  856.          var11 = null;
  857.       } else if (var4) {
  858.          boolean var7 = false;
  859.          JScriptParserSubTerm var8 = var11.GetSubTerm(var11.GetSubTermCount() - 1);
  860.          int var9 = var8.GetNumberOfCallOrIndex();
  861.          if (var9 == 0) {
  862.             var7 = true;
  863.          } else {
  864.             JSbxBase var10 = var8.GetCallOrIndex(var9 - 1);
  865.             if (!(var10 instanceof JScriptParserParamList)) {
  866.                var7 = true;
  867.             }
  868.          }
  869.  
  870.          if (var7) {
  871.             var8.AddCall(new JScriptParserParamList());
  872.          }
  873.       }
  874.  
  875.       if (this.bDumpParsing) {
  876.          if (var11 == null) {
  877.             this.aDebugOutStream.println("returns null");
  878.          } else {
  879.             this.aDebugOutStream.println("returns SubTerm");
  880.          }
  881.       }
  882.  
  883.       return var11;
  884.    }
  885.  
  886.    private JScriptParserSubTerm ParseSubTerm(boolean var1, boolean var2) throws JSbxExceptionBase {
  887.       if (this.bDumpParsing) {
  888.          this.aDebugOutStream.println("ParseSubTerm()");
  889.       }
  890.  
  891.       JScriptParserSubTerm var3 = null;
  892.       if (var1) {
  893.          if (var2) {
  894.             var3 = new JScriptParserSubTerm();
  895.             var3.bStartsAsExpression = true;
  896.          } else {
  897.             JScriptToken var4 = this.PeekToken();
  898.             if (var4 != null) {
  899.                if (var4.GetID() == 42) {
  900.                   this.NextToken();
  901.                   var3 = new JScriptParserSubTerm();
  902.                   var3.bThis = true;
  903.                } else if (var4.GetType() == 3) {
  904.                   JSbxValue var5 = var4.GetValue();
  905.                   if (var5.GetType() == 4) {
  906.                      this.NextToken();
  907.                      var3 = new JScriptParserSubTerm();
  908.                      var3.aStaticStr = var5.GetString();
  909.                   }
  910.                }
  911.             }
  912.          }
  913.       }
  914.  
  915.       if (var3 == null) {
  916.          JScriptParserIdentifier var8 = this.ParseIdentifier();
  917.          if (var8 != null) {
  918.             var3 = new JScriptParserSubTerm();
  919.             var3.aIdentifier = var8;
  920.          }
  921.       }
  922.  
  923.       if (var3 != null) {
  924.          JScriptTokenPosition var9 = new JScriptTokenPosition();
  925.  
  926.          boolean var10;
  927.          do {
  928.             var10 = false;
  929.             JScriptToken var6 = this.PeekToken();
  930.             if (var6 != null) {
  931.                if (var6.GetID() == 130) {
  932.                   if (this.bDumpParsing) {
  933.                      this.aDebugOutStream.println("Index gefunden");
  934.                   }
  935.  
  936.                   this.NextToken(var9);
  937.                   var10 = true;
  938.                   JScriptParserExpression var7 = this.ParseExpression();
  939.                   if (var7 == null) {
  940.                      throw new JScriptParserException(2015, this.aActualTokenPos);
  941.                   }
  942.  
  943.                   var6 = this.NextToken(var9);
  944.                   if (var6.GetID() != 131) {
  945.                      throw new JScriptParserException(2016, this.aActualTokenPos);
  946.                   }
  947.  
  948.                   var3.AddIndex(var7);
  949.                } else if (var6.GetID() == 87) {
  950.                   if (this.bDumpParsing) {
  951.                      this.aDebugOutStream.println("Call gefunden");
  952.                   }
  953.  
  954.                   this.NextToken();
  955.                   var10 = true;
  956.                   JScriptParserParamList var13 = this.ParseCall();
  957.                   var6 = this.NextToken(var9);
  958.                   if (var6.GetID() != 88) {
  959.                      throw new JScriptParserException(2017, this.aActualTokenPos);
  960.                   }
  961.  
  962.                   var3.AddCall(var13);
  963.                }
  964.             }
  965.          } while(var10);
  966.       }
  967.  
  968.       if (this.bDumpParsing) {
  969.          if (var3 == null) {
  970.             this.aDebugOutStream.println("returns null");
  971.          } else {
  972.             this.aDebugOutStream.println("returns SubTerm");
  973.          }
  974.       }
  975.  
  976.       return var3;
  977.    }
  978.  
  979.    private JScriptParserIdentifier ParseIdentifier() throws JSbxExceptionBase {
  980.       if (this.bDumpParsing) {
  981.          this.aDebugOutStream.println("ParseIdentifier()");
  982.       }
  983.  
  984.       JScriptParserIdentifier var1 = null;
  985.       JScriptToken var2 = this.PeekToken();
  986.       if (var2 != null && var2.GetType() == 2) {
  987.          this.NextToken();
  988.          var1 = new JScriptParserIdentifier(var2.GetString());
  989.       }
  990.  
  991.       if (this.bDumpParsing) {
  992.          if (var1 == null) {
  993.             this.aDebugOutStream.println("returns null");
  994.          } else {
  995.             this.aDebugOutStream.println("returns " + var1.aIdentifierName);
  996.          }
  997.       }
  998.  
  999.       return var1;
  1000.    }
  1001.  
  1002.    private JScriptParserParamList ParseCall() throws JSbxExceptionBase {
  1003.       JScriptParserParamList var1 = new JScriptParserParamList();
  1004.       boolean var3 = true;
  1005.  
  1006.       JScriptParserExpression var2;
  1007.       while(var3 && (var2 = this.ParseExpression(true)) != null) {
  1008.          var1.AddExpression(var2);
  1009.          JScriptToken var4 = this.PeekToken();
  1010.          var3 = false;
  1011.          if (var4 != null && var4.GetID() == 94) {
  1012.             this.NextToken();
  1013.             var3 = true;
  1014.          }
  1015.       }
  1016.  
  1017.       return var1;
  1018.    }
  1019.  
  1020.    public JScriptParserExpression ParseExpression() throws JSbxExceptionBase {
  1021.       return this.ParseExpression(false);
  1022.    }
  1023.  
  1024.    private JScriptParserExpression ParseExpression(boolean var1) throws JSbxExceptionBase {
  1025.       return this.aExprParser != null ? this.aExprParser.ParseIt(var1) : null;
  1026.    }
  1027.  
  1028.    private boolean TestForLParam(boolean var1) throws JSbxExceptionBase {
  1029.       JScriptToken var2 = this.NextToken();
  1030.       if (var2 != null && var2.GetID() == 87) {
  1031.          return true;
  1032.       } else if (var1) {
  1033.          throw new JScriptParserException(2018, this.aActualTokenPos);
  1034.       } else {
  1035.          return false;
  1036.       }
  1037.    }
  1038.  
  1039.    private boolean TestForRParam(boolean var1) throws JSbxExceptionBase {
  1040.       JScriptToken var2 = this.NextToken();
  1041.       if (var2 != null && var2.GetID() == 88) {
  1042.          return true;
  1043.       } else if (var1) {
  1044.          throw new JScriptParserException(2017, this.aActualTokenPos);
  1045.       } else {
  1046.          return false;
  1047.       }
  1048.    }
  1049.  
  1050.    private boolean TestForEOS(boolean var1) throws JSbxExceptionBase {
  1051.       JScriptToken var2 = this.PeekToken();
  1052.       if (var2 != null && var2.GetID() == 132) {
  1053.          this.NextToken();
  1054.          this.bEndOfStmtExpected = false;
  1055.       } else if (var1) {
  1056.          throw new JScriptParserException(2008, this.aActualTokenPos);
  1057.       }
  1058.  
  1059.       return true;
  1060.    }
  1061.  
  1062.    public JScriptToken NextToken(JScriptTokenPosition var1) throws JScriptTokenizerException {
  1063.       JScriptToken var2 = this.ImpGetNextTokenButEOL((JScriptTokenPosition)null);
  1064.       this.aTokenInterface.NextToken(this.aActualTokenPos);
  1065.       if (var1 != null) {
  1066.          var1.Set(this.aActualTokenPos);
  1067.       }
  1068.  
  1069.       if (this.aDebugStepPos == null) {
  1070.          this.aDebugStepPos = (JScriptTokenPosition)this.aActualTokenPos.clone();
  1071.       } else {
  1072.          this.aDebugStepPos.SetEndPos(this.aActualTokenPos.GetEndPos());
  1073.       }
  1074.  
  1075.       if (this.aStatementPos == null) {
  1076.          this.aStatementPos = (JScriptTokenPosition)this.aActualTokenPos.clone();
  1077.       } else {
  1078.          this.aStatementPos.SetEndPos(this.aActualTokenPos.GetEndPos());
  1079.       }
  1080.  
  1081.       if (this.bSourceAsPCode) {
  1082.          if (var2.GetType() == 3 && var2.GetValue().GetType() == 4) {
  1083.             String var3 = this.aSourceCodeStr;
  1084.             this.aSourceCodeStr = var3 + "\"" + var2.GetString() + "\" ";
  1085.          } else {
  1086.             String var10001 = this.aSourceCodeStr;
  1087.             this.aSourceCodeStr = var10001 + var2.GetString() + " ";
  1088.          }
  1089.       }
  1090.  
  1091.       return var2;
  1092.    }
  1093.  
  1094.    public JScriptToken NextToken() throws JScriptTokenizerException {
  1095.       return this.NextToken((JScriptTokenPosition)null);
  1096.    }
  1097.  
  1098.    public JScriptToken PeekToken(JScriptTokenPosition var1) throws JScriptTokenizerException {
  1099.       return this.ImpGetNextTokenButEOL(var1);
  1100.    }
  1101.  
  1102.    public JScriptToken PeekToken() throws JScriptTokenizerException {
  1103.       return this.ImpGetNextTokenButEOL((JScriptTokenPosition)null);
  1104.    }
  1105.  
  1106.    private JScriptToken ImpGetNextTokenButEOL(JScriptTokenPosition var1) throws JScriptTokenizerException {
  1107.       JScriptToken var2;
  1108.       for(var2 = this.aTokenInterface.PeekToken(var1); var2 != null && var2.GetID() == 134; var2 = this.aTokenInterface.PeekToken(var1)) {
  1109.          this.aTokenInterface.NextToken((JScriptTokenPosition)null);
  1110.          this.bEndOfStmtExpected = false;
  1111.       }
  1112.  
  1113.       return var2;
  1114.    }
  1115.  
  1116.    public JScriptToken LastToken() {
  1117.       return this.aTokenInterface.LastToken();
  1118.    }
  1119.  
  1120.    public JScriptToken GetLastTokenForExpParser() {
  1121.       return this.aTokenInterface.LastToken();
  1122.    }
  1123. }
  1124.