private IEXPR ParseExpr(bool isArith) { IEXPR r = null; if (Current.type == TokenType.String_Literal) { string val = Current.val.ToString(); StringLit s = new StringLit() { val = val }; r = s; } else if (Current.type == TokenType.Int_Literal) { int val = (int)Current.val; IntLit i = new IntLit() { val = val }; r = i; } else if (Current.type == TokenType.Double_Literal) { double val = (double)Current.val; DoubleLit d = new DoubleLit() { val = val }; r = d; } else if (Current.type == TokenType.Word && tokens[this.i + 1].val.ToString() == "(") { string name = Current.val.ToString(); i++; i++; FuncCall f = new FuncCall() { method = name, args = ParseArgs() }; r = f; } else if (Current.val.ToString() == "new") { i++; New n = new New() { from = Current.val.ToString() }; r = n; } else if (Current.type == TokenType.Bool_Literal) { BoolLit b = new BoolLit() { val = (bool)Current.val }; r = b; } else if (Current.type == TokenType.Word) { string name = Current.val as string; LoadVar v = new LoadVar() { name = name }; r = v; } if ((this.i + 1 < tokens.Length) && (isArith == false) && (tokens[this.i + 1].val.ToString() == "+" || tokens[this.i + 1].val.ToString() == "-" || tokens[this.i + 1].val.ToString() == "*" || tokens[this.i + 1].val.ToString() == "/" || tokens[this.i + 1].val.ToString() == "%" || tokens[this.i + 1].val.ToString() == "<" || tokens[this.i + 1].val.ToString() == "=" || tokens[this.i + 1].val.ToString() == ">" || Current.val.ToString() == "(")) { r = ParseAtrithExpr(r); i++; return r; } else { return r; } throw new Exception(); }
private IEXPR ParseExpr(bool isArith) { IEXPR r = null; if (Current.type == TokenType.String_Literal) { string val = Current.val.ToString(); StringLit s = new StringLit() { val = val }; r = s; } else if (Current.type == TokenType.Int_Literal) { int val = (int)Current.val; IntLit i = new IntLit() { val = val }; r = i; } else if (Current.type == TokenType.Double_Literal) { double val = (double)Current.val; DoubleLit d = new DoubleLit() { val = val }; r = d; } else if (Current.type == TokenType.Word && tokens[this.i + 1].val.ToString() == "(") { string name = Current.val.ToString(); i++; i++; FuncCall f = new FuncCall() { method = name, args = ParseArgs() }; r = f; } else if (Current.val.ToString() == "new") { i++; New n = new New() { from = Current.val.ToString() }; r = n; } else if (Current.type == TokenType.Bool_Literal) { BoolLit b = new BoolLit() { val = (bool)Current.val }; r = b; } else if (Current.type == TokenType.Word) { string name = Current.val as string; LoadVar v = new LoadVar() { name = name }; r = v; } if ((this.i + 1 < tokens.Length) && (isArith == false) && (tokens[this.i + 1].val.ToString() == "+" || tokens[this.i + 1].val.ToString() == "-" || tokens[this.i + 1].val.ToString() == "*" || tokens[this.i + 1].val.ToString() == "/" || tokens[this.i + 1].val.ToString() == "%" || tokens[this.i + 1].val.ToString() == "<" || tokens[this.i + 1].val.ToString() == "=" || tokens[this.i + 1].val.ToString() == ">" || Current.val.ToString() == "(")) { r = ParseAtrithExpr(r); i++; return(r); } else { return(r); } throw new Exception(); }