public OpEqualStmtExp(Exp expLeft, Exp expRight, BinaryExp.BinaryOp op) { Debug.Assert(false, "OpEqualStmtExp is obsolete"); // m_op = op; m_eLeft = expLeft; m_expRight = expRight; }
//----------------------------------------------------------------------------- // Overload for binary & unary //----------------------------------------------------------------------------- public static SymbolErrorException NoAcceptableOperator( FileRange location, System.Type tLeft, System.Type tRight, BinaryExp.BinaryOp op ) { return new SymbolErrorException( Code.cNoAcceptableOperator, location, "No binary operator '" + op + "' that takes arguments '" + tLeft.ToString() + "' and '" + tRight.ToString() + "'."); }
// Helper for parsing it as left-associative. We get in our parent's left // exp, and we return the left-associative parse tree. private Exp ParseExp5_rest(Exp expParentLeft) { // E' -> + T E' // - T E' // {} Token t = m_lexer.PeekNextToken(); if (t.TokenType == Token.Type.cPlus || t.TokenType == Token.Type.cMinus) { ConsumeNextToken(); BinaryExp.BinaryOp op = ConvertToBinaryOp(t); Exp expRight = ParseExp6(); Exp expChildLeft = new BinaryExp(expParentLeft, expRight, op); return ParseExp5_rest(expChildLeft); } else { return expParentLeft; } }
//----------------------------------------------------------------------------- // Parse enum declaration // --> 'enum' id:name '{' enum_decl_list '}' //----------------------------------------------------------------------------- protected EnumDecl ParseEnum(Modifiers modsEnums) { ReadExpectedToken(Token.Type.cEnum); Identifier idName = ReadExpectedIdentifier(); FileRange f2 = this.BeginRange(); ReadExpectedToken(Token.Type.cLCurly); ArrayList a = new ArrayList(); // All enum fields are Static, Public, Literal // and have fieldtype set to type of the enum //Modifiers mods = new Modifiers(Modifiers.EFlags.Public | Modifiers.EFlags.Static); Modifiers mods = new Modifiers(); mods.SetPublic(); mods.SetStatic(); TypeSig tSig = new SimpleTypeSig(new SimpleObjExp(idName)); Identifier idPrev = null; Token t = m_lexer.PeekNextToken(); while(t.TokenType != Token.Type.cRCurly) { // Parse fields Identifier id = ReadExpectedIdentifier(); Exp expInit = null; t = m_lexer.PeekNextToken(); if (t.TokenType == Token.Type.cAssign) { ConsumeNextToken(); expInit = ParseExp(); } else { #if false // If no explicit assignment, then we must create one // first field -> '=0' if (idPrev == null) { expInit = new IntExp(0, id.Location); } // all other fields -> '= <prevfield> + '1' ' else { expInit = new BinaryExp( new SimpleObjExp(idPrev), new IntExp(1, id.Location), BinaryExp.BinaryOp.cAdd); } #endif } //EnumField e = new EnumField(id); FieldDecl e = new FieldDecl(id, tSig, mods, expInit); a.Add(e); // If no comma, then this had better be our last one t = m_lexer.PeekNextToken(); if (t.TokenType != Token.Type.cComma) { break; } ReadExpectedToken(Token.Type.cComma); idPrev = id; t = m_lexer.PeekNextToken(); } // while parsing fields ReadExpectedToken(Token.Type.cRCurly); // Convert array list to EnumField[] FieldDecl [] f = new FieldDecl[a.Count]; for(int i = 0; i < f.Length; i++) f[i] = (FieldDecl) a[i]; EnumDecl node = new EnumDecl(idName, f, modsEnums); node.SetLocation(this.EndRange(f2)); return node; }
// Helper for parsing it as left-associative. We get in our parent's left // exp, and we return the left-associative parse tree. private Exp ParseExp1_rest(Exp expParentLeft) { // E' -> && T E' // || T E' // {} Token t = m_lexer.PeekNextToken(); if (t.TokenType == Token.Type.cAnd || t.TokenType == Token.Type.cOr) { ConsumeNextToken(); BinaryExp.BinaryOp op = ConvertToBinaryOp(t); Exp expRight = ParseExp2(); Exp expChildLeft = new BinaryExp(expParentLeft, expRight, op); return ParseExp1_rest(expChildLeft); } else { return expParentLeft; } }