private object CreateNewObject(GOLD.Reduction r) { object result = null; int pointerCount; switch ((ProductionIndex)r.Parent.TableIndex()) { case ProductionIndex.Decls: // <Decls> ::= <Decl> <Decls> var declarationHead = r.GetData(0) as DeclarationStatement; var declarationTail = r.GetData(1) as List<DeclarationStatement>; declarationTail.InsertNotNull(0, declarationHead); return declarationTail; case ProductionIndex.Decls2: // <Decls> ::= return new List<DeclarationStatement>(); case ProductionIndex.Decl: // <Decl> ::= <Func Decl> return r.GetData(0); case ProductionIndex.Decl2: // <Decl> ::= <Func Proto> return r.GetData(0); case ProductionIndex.Decl3: // <Decl> ::= <Struct Decl> return r.GetData(0); case ProductionIndex.Decl4: // <Decl> ::= <Union Decl> return r.GetData(0); case ProductionIndex.Decl5: // <Decl> ::= <Enum Decl> return r.GetData(0); case ProductionIndex.Decl6: // <Decl> ::= <Var Decl> return r.GetData(0); case ProductionIndex.Decl7: // <Decl> ::= <Typedef Decl> return r.GetData(0); case ProductionIndex.Funcproto_Lparen_Rparen_Semi: // <Func Proto> ::= <Func ID> '(' <Types> ')' ';' break; case ProductionIndex.Funcproto_Lparen_Rparen_Semi2: // <Func Proto> ::= <Func ID> '(' <Params> ')' ';' break; case ProductionIndex.Funcproto_Lparen_Rparen_Semi3: // <Func Proto> ::= <Func ID> '(' ')' ';' break; case ProductionIndex.Funcdecl_Lparen_Rparen: // <Func Decl> ::= <Func ID> '(' <Params> ')' <Block> var function = r.GetData(0) as FunctionDeclaration; function.Parameters = r.GetData(2) as List<Parameter>; function.Block = r.GetData(4) as BlockStatement; return function; case ProductionIndex.Funcdecl_Lparen_Rparen2: // <Func Decl> ::= <Func ID> '(' <Id List> ')' <Struct Def> <Block> throw new NotImplementedException(); case ProductionIndex.Funcdecl_Lparen_Rparen3: // <Func Decl> ::= <Func ID> '(' ')' <Block> function = r.GetData(0) as FunctionDeclaration; function.Block = r.GetData(3) as BlockStatement; return function; case ProductionIndex.Params_Comma: // <Params> ::= <Param> ',' <Params> var paramHead = r.GetData(0) as Parameter; var paramTail = r.GetData(2) as List<Parameter>; paramTail.InsertNotNull(0,paramHead); return paramTail; case ProductionIndex.Params: // <Params> ::= <Param> return new List<Parameter>() { r.GetData(0) as Parameter }; case ProductionIndex.Param_Const_Id: // <Param> ::= const <Type> Id break; case ProductionIndex.Param_Id: // <Param> ::= <Type> Id return new Parameter(r.GetData(0) as IRType, r.GetData(1).ToString()); case ProductionIndex.Types_Comma: // <Types> ::= <Type> ',' <Types> var typeHead = r.GetData(0) as IRType; var typeTail = r.GetData(2) as List<IRType>; typeTail.InsertNotNull(0, typeHead); return typeTail; case ProductionIndex.Types: // <Types> ::= <Type> return new List<IRType> { r.GetData(0) as IRType}; case ProductionIndex.Idlist_Id_Comma: // <Id List> ::= Id ',' <Id List> var idHead = r.GetData(0).ToString(); var idTail = r.GetData(2) as List<string>; idTail.InsertNotNull(0, idHead); return idTail; case ProductionIndex.Idlist_Id: // <Id List> ::= Id var idList = r.GetData(0).ToString(); return new List<string>() { idList }; case ProductionIndex.Funcid_Id: // <Func ID> ::= <Type> Id return new FunctionDeclaration(r.GetData(0) as IRType, r.GetData(1).ToString()); case ProductionIndex.Funcid_Id2: // <Func ID> ::= Id //return new Function(r.GetData(0).ToString()); throw new NotImplementedException("<Func ID> ::= Id"); case ProductionIndex.Typedefdecl_Typedef_Id_Semi: // <Typedef Decl> ::= typedef <Type> Id ';' break; case ProductionIndex.Structdecl_Struct_Id_Lbrace_Rbrace_Semi: // <Struct Decl> ::= struct Id '{' <Struct Def> '}' ';' return new StructDeclaration(r.GetData(0).ToString(), r.GetData(3) as List<IdDeclarationStatement>); case ProductionIndex.Uniondecl_Union_Id_Lbrace_Rbrace_Semi: // <Union Decl> ::= union Id '{' <Struct Def> '}' ';' return new UnionDeclaration(r.GetData(1).ToString(), r.GetData(3) as List<IdDeclarationStatement>); case ProductionIndex.Structdef: // <Struct Def> ::= <Var Decl> <Struct Def> var declarationstm = r.GetData(0) as List<IdDeclarationStatement>; var structdeftail = r.GetData(1) as List<IdDeclarationStatement>; declarationstm.AddRange(structdeftail); return declarationstm; case ProductionIndex.Structdef2: // <Struct Def> ::= <Var Decl> declarationstm = r.GetData(0) as List<IdDeclarationStatement>; return declarationstm; case ProductionIndex.Vardecl_Semi: // <Var Decl> ::= <Mod> <Type> <Var> <Var List> ';' var baseType = r.GetData(1) as IRType; var partialDeclaration = r.GetData(2) as PartialIdDeclarationStatement; var varList = r.GetData(3) as List<VarItem>; var idDeclaration = partialDeclaration.DeclarationStatement; var partialType = baseType; if (partialDeclaration.ArrayType != null ) { partialDeclaration.ArrayType.Type = partialType; partialType = partialDeclaration.ArrayType; } idDeclaration.Type = partialType; idDeclaration.Modifier = r.GetData(0) as Modifier; var idDeclarationList = new List<IdDeclarationStatement>() { idDeclaration }; foreach (var varItem in varList) { IRType baseVarItemType = baseType; pointerCount = Convert.ToInt32(varItem.Pointers); for (int i = 0; i < pointerCount; i++) { baseVarItemType = new PointerType(baseVarItemType); } if (varItem.PartialIdDeclaration.ArrayType != null) { varItem.PartialIdDeclaration.ArrayType.Type = baseVarItemType; baseVarItemType = varItem.PartialIdDeclaration.ArrayType; } varItem.PartialIdDeclaration.DeclarationStatement.Type = baseVarItemType; idDeclarationList.Add(varItem.PartialIdDeclaration.DeclarationStatement); } return idDeclarationList; case ProductionIndex.Vardecl_Semi2: // <Var Decl> ::= <Type> <Var> <Var List> ';' baseType = r.GetData(0) as IRType; partialDeclaration = r.GetData(1) as PartialIdDeclarationStatement; varList = r.GetData(2) as List<VarItem>; idDeclaration = partialDeclaration.DeclarationStatement; partialType = baseType; if (partialDeclaration.ArrayType != null ) { partialDeclaration.ArrayType.Type = partialType; partialType = partialDeclaration.ArrayType; } idDeclaration.Type = partialType; idDeclarationList = new List<IdDeclarationStatement>() { idDeclaration }; foreach (var varItem in varList) { IRType baseVarItemType = baseType; pointerCount = Convert.ToInt32(varItem.Pointers); for (int i = 0; i < pointerCount; i++) { baseVarItemType = new PointerType(baseVarItemType); } if (varItem.PartialIdDeclaration.ArrayType != null) { varItem.PartialIdDeclaration.ArrayType.Type = baseVarItemType; baseVarItemType = varItem.PartialIdDeclaration.ArrayType; } varItem.PartialIdDeclaration.DeclarationStatement.Type = baseVarItemType; idDeclarationList.Add(varItem.PartialIdDeclaration.DeclarationStatement); } return idDeclarationList; case ProductionIndex.Vardecl_Semi3: // <Var Decl> ::= <Mod> <Var> <Var List> ';' throw new NotImplementedException("<Var Decl> ::= <Mod> <Var> <Var List> "); case ProductionIndex.Var_Id: // <Var> ::= Id <Array> var arrayType = r.GetData(1) as ArrayType; var id = r.GetData(0).ToString(); idDeclaration = new IdDeclarationStatement(id); partialDeclaration = new PartialIdDeclarationStatement(idDeclaration, arrayType); return partialDeclaration; case ProductionIndex.Var_Id_Eq: // <Var> ::= Id <Array> '=' <Op If> arrayType = r.GetData(1) as ArrayType; var assigment = r.GetData(3) as Expression; id = r.GetData(0).ToString(); idDeclaration = new IdDeclarationStatement(id,assigment); partialDeclaration = new PartialIdDeclarationStatement(idDeclaration, arrayType); return partialDeclaration; case ProductionIndex.Array_Lbracket_Rbracket: // <Array> ::= '[' <Expr> ']' var sizeExpression = r.GetData(1) as DecValue; return new ArrayType(Convert.ToInt64(sizeExpression.Value)); case ProductionIndex.Array_Lbracket_Rbracket2: // <Array> ::= '[' ']' return new ArrayType(); case ProductionIndex.Array: // <Array> ::= return null; case ProductionIndex.Varlist_Comma: // <Var List> ::= ',' <Var Item> <Var List> var varItemHead = r.GetData(1) as VarItem; var varItemTail = r.GetData(2) as List<VarItem>; varItemTail.InsertNotNull(0, varItemHead); return varItemTail; case ProductionIndex.Varlist: // <Var List> ::= return new List<VarItem>(); case ProductionIndex.Varitem: // <Var Item> ::= <Pointers> <Var> var pointers = Convert.ToInt32(r.GetData(0)); var var = r.GetData(1) as PartialIdDeclarationStatement; return new VarItem( pointers, var); case ProductionIndex.Mod_Extern: // <Mod> ::= extern no extern no break;//ver que pedo con la excepcion case ProductionIndex.Mod_Static: // <Mod> ::= static return new StaticModifier(); case ProductionIndex.Mod_Register: // <Mod> ::= register return new RegisterModifier(); case ProductionIndex.Mod_Auto: // <Mod> ::= auto return new AutoModifier(); case ProductionIndex.Mod_Volatile: // <Mod> ::= volatile no volatile no break; //ver que pedo con la excepcion case ProductionIndex.Mod_Const: // <Mod> ::= const return new ConstModifier(); case ProductionIndex.Enumdecl_Enum_Id_Lbrace_Rbrace_Semi: // <Enum Decl> ::= enum Id '{' <Enum Def> '}' ';' return new EnumDeclaration(r.GetData(1).ToString(), r.GetData(3) as List<EnumValue>); case ProductionIndex.Enumdef_Comma: // <Enum Def> ::= <Enum Val> ',' <Enum Def> var enumHead = r.GetData(0) as EnumValue; var enumTail = r.GetData(2) as List<EnumValue>; enumTail.InsertNotNull(0, enumHead); return enumTail; case ProductionIndex.Enumdef: // <Enum Def> ::= <Enum Val> return new List<EnumValue> {r.GetData(0) as EnumValue}; case ProductionIndex.Enumval_Id: // <Enum Val> ::= Id return r.GetData(0); case ProductionIndex.Enumval_Id_Eq_Octliteral: // <Enum Val> ::= Id '=' OctLiteral return new EnumValue(r.GetData(0).ToString(), Convert.ToInt32(r.GetData(2).ToString(), 8)); case ProductionIndex.Enumval_Id_Eq_Hexliteral: // <Enum Val> ::= Id '=' HexLiteral return new EnumValue(r.GetData(0).ToString(), Convert.ToInt32(r.GetData(2).ToString(), 16)); case ProductionIndex.Enumval_Id_Eq_Decliteral: // <Enum Val> ::= Id '=' DecLiteral return new EnumValue(r.GetData(0).ToString(), Convert.ToInt32(r.GetData(2).ToString(), 10)); case ProductionIndex.Type: // <Type> ::= <Base> <Pointers> baseType = r.GetData(0) as IRType; pointerCount = Convert.ToInt32(r.GetData(1)); for (int i = 0; i < pointerCount; i++) { baseType = new PointerType(baseType); } return baseType; case ProductionIndex.Base: // <Base> ::= <Sign> <Scalar> if (r.GetData(0).ToString() == "unsigned") { if ( r.GetData(1) is IntType ) { return new UnsignedIntType(); } else if (r.GetData(1) is ShortType) { return new UnsignedShortType(); } else if (r.GetData(1) is LongType) { return new UnsignedLongType(); } else if (r.GetData(1) is ShortIntType) { return new UnsignedShortIntType(); } else if (r.GetData(1) is FloatType) { return new UnsignedFloatType(); } else if (r.GetData(1) is LongIntType) { return new UnsignedLongIntType(); } else if (r.GetData(1) is DoubleType) { return new UnsignedDoubleType(); } } return r.GetData(1); case ProductionIndex.Base_Struct_Id: // <Base> ::= struct Id return new StructType(r.GetData(1).ToString());//Crear una clase para definir el tipo inferido del struct case ProductionIndex.Base_Struct_Lbrace_Rbrace: // <Base> ::= struct '{' <Struct Def> '}' return new StructType(r.GetData(2) as List<DeclarationStatement>); case ProductionIndex.Base_Union_Id: // <Base> ::= union Id return new UnionType(r.GetData(1).ToString());//Crear una clase para definir el tipo inferido del union case ProductionIndex.Base_Union_Lbrace_Rbrace: // <Base> ::= union '{' <Struct Def> '}' return new UnionType(r.GetData(2) as List<DeclarationStatement>); case ProductionIndex.Base_Enum_Id: // <Base> ::= enum Id return new EnumType(r.GetData(1).ToString()); case ProductionIndex.Sign_Signed: // <Sign> ::= signed return r.GetData(0); case ProductionIndex.Sign_Unsigned: // <Sign> ::= unsigned return r.GetData(0); case ProductionIndex.Sign: // <Sign> ::= return 0; case ProductionIndex.Scalar_Char: // <Scalar> ::= char return new CharType(); case ProductionIndex.Scalar_Int: // <Scalar> ::= int return new IntType(); case ProductionIndex.Scalar_Short: return new ShortType(); case ProductionIndex.Scalar_Long: // <Scalar> ::= long return new LongType(); case ProductionIndex.Scalar_Short_Int: //<Scalar> ::= short int return new ShortIntType(); case ProductionIndex.Scalar_Long_Int: return new LongIntType(); case ProductionIndex.Scalar_Float: return new FloatType(); case ProductionIndex.Scalar_Double: return new DoubleType(); case ProductionIndex.Scalar_Void: return new VoidType(); case ProductionIndex.Pointers_Times: // <Pointers> ::= '*' <Pointers> return Convert.ToInt32(r.GetData(1)) + 1; case ProductionIndex.Pointers: // <Pointers> ::= return 0; case ProductionIndex.Stm: // <Stm> ::= <Var Decl> return r.GetData(0); case ProductionIndex.Stm_Id_Colon: // <Stm> ::= Id ':' return r.GetData(0).ToString(); //labelstatement class missing case ProductionIndex.Stm_If_Lparen_Rparen: // <Stm> ::= if '(' <Expr> ')' <Stm> var ifDeclaration = new IfStatement(r.GetData(2) as Expression, r.GetData(4) as Statement); return ifDeclaration; case ProductionIndex.Stm_If_Lparen_Rparen_Else: // <Stm> ::= if '(' <Expr> ')' <Then Stm> else <Stm> ifDeclaration = new IfStatement(r.GetData(2) as Expression, r.GetData(4) as Statement, r.GetData(6) as Statement); return ifDeclaration; case ProductionIndex.Stm_While_Lparen_Rparen: // <Stm> ::= while '(' <Expr> ')' <Stm> var whileDeclaration = new WhileStatement(r.GetData(2) as Expression, r.GetData(4) as Statement); return whileDeclaration; case ProductionIndex.Stm_For_Lparen_Semi_Semi_Rparen: // <Stm> ::= for '(' <Arg> ';' <Arg> ';' <Arg> ')' <Stm> var forDeclaration = new ForStatement(r.GetData(2) as Expression, r.GetData(4) as Expression, r.GetData(6) as Expression, r.GetData(8) as Statement); return forDeclaration; case ProductionIndex.Stm2: // <Stm> ::= <Normal Stm> return r.GetData(0); case ProductionIndex.Thenstm_If_Lparen_Rparen_Else: // <Then Stm> ::= if '(' <Expr> ')' <Then Stm> else <Then Stm> ifDeclaration = new IfStatement(r.GetData(2) as Expression, r.GetData(4) as Statement, r.GetData(6) as Statement); return ifDeclaration; case ProductionIndex.Thenstm_While_Lparen_Rparen: // <Then Stm> ::= while '(' <Expr> ')' <Then Stm> whileDeclaration = new WhileStatement(r.GetData(2) as Expression, r.GetData(4) as Statement); return whileDeclaration; case ProductionIndex.Thenstm_For_Lparen_Semi_Semi_Rparen: // <Then Stm> ::= for '(' <Arg> ';' <Arg> ';' <Arg> ')' <Then Stm> forDeclaration = new ForStatement(r.GetData(2) as Expression, r.GetData(4) as Expression, r.GetData(6) as Expression, r.GetData(8) as Statement); return forDeclaration; case ProductionIndex.Thenstm: // <Then Stm> ::= <Normal Stm> return r.GetData(0); case ProductionIndex.Normalstm_Do_While_Lparen_Rparen: // <Normal Stm> ::= do <Stm> while '(' <Expr> ')' var doDeclaration = new DoStatement(r.GetData(1) as Statement, r.GetData(4) as Expression); return doDeclaration; case ProductionIndex.Normalstm_Switch_Lparen_Rparen_Lbrace_Rbrace: // <Normal Stm> ::= switch '(' <Expr> ')' '{' <Case Stms> '}' var switchDeclaration = new SwitchStatement(r.GetData(2) as Expression, r.GetData(5) as List<DefaultCaseStatement>); return switchDeclaration; case ProductionIndex.Normalstm: // <Normal Stm> ::= <Block> return r.GetData(0); case ProductionIndex.Normalstm_Semi: // <Normal Stm> ::= <Expr> ';' var expressionStatement = new ExpressionStatement(r.GetData(0) as Expression); return expressionStatement; case ProductionIndex.Normalstm_Goto_Id_Semi: // <Normal Stm> ::= goto Id ';' return new GoToIdStatement(); //guardar el id case ProductionIndex.Normalstm_Break_Semi: // <Normal Stm> ::= break ';' return new BreakStatement(); case ProductionIndex.Normalstm_Continue_Semi: // <Normal Stm> ::= continue ';' return new ContinueStatement(); case ProductionIndex.Normalstm_Return_Semi: // <Normal Stm> ::= return <Expr> ';' return new ReturnStatement(r.get_Data(1) as Expression); case ProductionIndex.Normalstm_Semi2: // <Normal Stm> ::= ';' return new NoOpExpression(); case ProductionIndex.Arg: // <Arg> ::= <Expr> return r.GetData(0); case ProductionIndex.Arg2: // <Arg> ::= return new NoOpExpression(); case ProductionIndex.Casestms_Case_Colon: // <Case Stms> ::= case <Value> ':' <Stm List> <Case Stms> var caseStatementHead = new CaseStatement(r.GetData(1) as ValueExpression, r.GetData(3) as List<Statement>); var caseStatementTail = r.GetData(4) as List<DefaultCaseStatement>; caseStatementTail.InsertNotNull(0, caseStatementHead); return caseStatementTail; case ProductionIndex.Casestms_Default_Colon: // <Case Stms> ::= default ':' <Stm List> return new List<DefaultCaseStatement>() { new DefaultCaseStatement(r.GetData(2) as List<Statement>) }; case ProductionIndex.Casestms: // <Case Stms> ::= return new List<DefaultCaseStatement>(); case ProductionIndex.Block_Lbrace_Rbrace: // <Block> ::= '{' <Stm List> '}' return new BlockStatement(r.GetData(1) as List<Statement>); case ProductionIndex.Stmlist: // <Stm List> ::= <Stm> <Stm List> var statemetListTail = r.GetData(1) as List<Statement>; var declList = r.GetData(0) as List<IdDeclarationStatement>; if (declList != null) { var statementList = new List<Statement>(); foreach (var dec in declList) { statementList.AddNotNull(dec); } foreach (var TailItem in statemetListTail) { statementList.AddNotNull(TailItem); } return statementList; } statemetListTail.InsertNotNull(0, r.GetData(0) as Statement); return statemetListTail; case ProductionIndex.Stmlist2: // <Stm List> ::= return new List<Statement>(); case ProductionIndex.Expr_Comma: // <Expr> ::= <Expr> ',' <Op Assign> var expr = r.GetData(0) as ExpressionList; if (expr != null) { return new ExpressionList(expr, r.GetData(2) as Expression); } else return new ExpressionList(r.GetData(0) as Expression, r.GetData(2) as Expression); case ProductionIndex.Expr: // <Expr> ::= <Op Assign> return r.GetData(0); case ProductionIndex.Opassign_Eq: // <Op Assign> ::= <Op If> '=' <Op Assign> return new AssignExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Pluseq: // <Op Assign> ::= <Op If> '+=' <Op Assign> return new AdditionAssignmentExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Minuseq: // <Op Assign> ::= <Op If> '-=' <Op Assign> return new SubtractionAsigExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Timeseq: // <Op Assign> ::= <Op If> '*=' <Op Assign> return new MultiplicationAsigExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Diveq: // <Op Assign> ::= <Op If> '/=' <Op Assign> return new DivisionAsigExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Careteq: // <Op Assign> ::= <Op If> '^=' <Op Assign> return new BitwiseXorAssignmentExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Ampeq: // <Op Assign> ::= <Op If> '&=' <Op Assign> return new BitwiseAndAssignExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Pipeeq: // <Op Assign> ::= <Op If> '|=' <Op Assign> return new BitwiseOrAssigExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Gtgteq: // <Op Assign> ::= <Op If> '>>=' <Op Assign> return new BitwiseRightShiftAssigExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign_Ltlteq: // <Op Assign> ::= <Op If> '<<=' <Op Assign> return new BitwiseLeftShiftAssigExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opassign: // <Op Assign> ::= <Op If> return r.get_Data(0); case ProductionIndex.Opif_Question_Colon: // <Op If> ::= <Op Or> '?' <Op If> ':' <Op If> return new TernaryConditional(r.GetData(0) as Expression, r.GetData(2) as Expression, r.GetData(4) as Expression); case ProductionIndex.Opif: // <Op If> ::= <Op Or> return r.get_Data(0); case ProductionIndex.Opor_Pipepipe: // <Op Or> ::= <Op Or> '||' <Op And> return new LogicalOrExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opor: // <Op Or> ::= <Op And> return r.get_Data(0); case ProductionIndex.Opand_Ampamp: // <Op And> ::= <Op And> '&&' <Op BinOR> return new LogicAndExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opand: // <Op And> ::= <Op BinOR> return r.get_Data(0); case ProductionIndex.Opbinor_Pipe: // <Op BinOR> ::= <Op BinOR> '|' <Op BinXOR> return new BitwiseOrExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opbinor: // <Op BinOR> ::= <Op BinXOR> return r.get_Data(0); case ProductionIndex.Opbinxor_Caret: // <Op BinXOR> ::= <Op BinXOR> '^' <Op BinAND> return new BitwiseXorExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opbinxor: // <Op BinXOR> ::= <Op BinAND> return r.get_Data(0); case ProductionIndex.Opbinand_Amp: // <Op BinAND> ::= <Op BinAND> '&' <Op Equate> return new BitwiseAndExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opbinand: // <Op BinAND> ::= <Op Equate> return r.get_Data(0); case ProductionIndex.Opequate_Eqeq: // <Op Equate> ::= <Op Equate> '==' <Op Compare> return new EqualsExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opequate_Exclameq: // <Op Equate> ::= <Op Equate> '!=' <Op Compare> return new NotEqualExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opequate: // <Op Equate> ::= <Op Compare> return r.get_Data(0); case ProductionIndex.Opcompare_Lt: // <Op Compare> ::= <Op Compare> '<' <Op Shift> return new LessThanExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opcompare_Gt: // <Op Compare> ::= <Op Compare> '>' <Op Shift> return new GreaterThanExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opcompare_Lteq: // <Op Compare> ::= <Op Compare> '<=' <Op Shift> return new LessOrEqualToExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opcompare_Gteq: // <Op Compare> ::= <Op Compare> '>=' <Op Shift> return new GreaterOrEqualExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opcompare: // <Op Compare> ::= <Op Shift> return r.get_Data(0); case ProductionIndex.Opshift_Ltlt: // <Op Shift> ::= <Op Shift> '<<' <Op Add> return new BitwiseLeftShiftExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opshift_Gtgt: return new BitwiseRightShiftExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opshift: // <Op Shift> ::= <Op Add> return r.get_Data(0); case ProductionIndex.Opadd_Plus: // <Op Add> ::= <Op Add> '+' <Op Mult> return new AddExpression(left: r.get_Data(0) as Expression, right: r.get_Data(2) as Expression); case ProductionIndex.Opadd_Minus: // <Op Add> ::= <Op Add> '-' <Op Mult> return new SubExpression(left: r.get_Data(0) as Expression, right: r.get_Data(2) as Expression); case ProductionIndex.Opadd: // <Op Add> ::= <Op Mult> return r.get_Data(0); case ProductionIndex.Opmult_Times: // <Op Mult> ::= <Op Mult> '*' <Op Unary> return new MulExpression(left: r.get_Data(0) as Expression, right: r.get_Data(2) as Expression); case ProductionIndex.Opmult_Div: // <Op Mult> ::= <Op Mult> '/' <Op Unary> return new DivisionExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opmult_Percent: // <Op Mult> ::= <Op Mult> '%' <Op Unary> return new ModExpression(left: r.GetData(0) as Expression, right: r.GetData(2) as Expression); case ProductionIndex.Opmult: // <Op Mult> ::= <Op Unary> return r.get_Data(0); case ProductionIndex.Opunary_Exclam: // <Op Unary> ::= '!' <Op Unary> return new NotEqualToExpression(r.GetData(1) as Expression); case ProductionIndex.Opunary_Tilde: // <Op Unary> ::= '~' <Op Unary> return new OneComplementExpression(r.get_Data(1) as Expression); case ProductionIndex.Opunary_Minus: // <Op Unary> ::= '-' <Op Unary> return new NegateExpression(r.get_Data(1) as Expression); case ProductionIndex.Opunary_Times: // <Op Unary> ::= '*' <Op Unary> return new PointerExpression(r.get_Data(1) as Expression); case ProductionIndex.Opunary_Amp: // <Op Unary> ::= '&' <Op Unary> return new ReferenceExpression(r.get_Data(1) as Expression); case ProductionIndex.Opunary_Plusplus: // <Op Unary> ::= '++' <Op Unary> return new PreIncrementExpression(r.get_Data(1) as Expression); case ProductionIndex.Opunary_Minusminus: // <Op Unary> ::= '--' <Op Unary> return new PreDecrementExpression(r.GetData(1) as Expression); case ProductionIndex.Opunary_Plusplus2: // <Op Unary> ::= <Op Pointer> '++' return new PostIncrementExpression(r.get_Data(0) as Expression); case ProductionIndex.Opunary_Minusminus2: // <Op Unary> ::= <Op Pointer> '--' return new PostDecrementExpression(r.GetData(0) as Expression); case ProductionIndex.Opunary_Lparen_Rparen: // <Op Unary> ::= '(' <Type> ')' <Op Unary> break; case ProductionIndex.Opunary_Sizeof_Lparen_Rparen: // <Op Unary> ::= sizeof '(' <Type> ')' break; case ProductionIndex.Opunary_Sizeof_Lparen_Id_Rparen: // <Op Unary> ::= sizeof '(' Id <Pointers> ')' break; case ProductionIndex.Opunary: // <Op Unary> ::= <Op Pointer> return r.get_Data(0); case ProductionIndex.Oppointer_Dot: // <Op Pointer> ::= <Op Pointer> '.' <Value> return new PointerReferenceAccessExpr(r.GetData(0) as Expression, r.GetData(2) as Expression); case ProductionIndex.Oppointer_Minusgt: // <Op Pointer> ::= <Op Pointer> '->' <Value> return new PointerAccessExpr(r.GetData(0) as Expression, r.GetData(2) as Expression); case ProductionIndex.Oppointer_Lbracket_Rbracket: // <Op Pointer> ::= <Op Pointer> '[' <Expr> ']' return new PointerArrayAccessExpr(r.GetData(0) as Expression, r.GetData(2) as Expression); case ProductionIndex.Oppointer: // <Op Pointer> ::= <Value> return r.get_Data(0); case ProductionIndex.Value_Octliteral: // <Value> ::= OctLiteral return new DecValue(Convert.ToInt32(r.get_Data(0).ToString(),8)); case ProductionIndex.Value_Hexliteral: // <Value> ::= HexLiteral return new DecValue(Convert.ToInt32(r.GetData(0).ToString(),16)); case ProductionIndex.Value_Decliteral: // <Value> ::= DecLiteral return new DecValue(Convert.ToInt32(r.get_Data(0))); case ProductionIndex.Value_Stringliteral: // <Value> ::= StringLiteral return new StringLiteral(r.GetData(0).ToString()); case ProductionIndex.Value_Charliteral: // <Value> ::= CharLiteral return new CharLiteral(Convert.ToByte(Convert.ToChar(r.GetData(0)))); case ProductionIndex.Value_Floatliteral: // <Value> ::= FloatLiteral return new FloatLiteral(Convert.ToDouble(r.GetData(0))); case ProductionIndex.Value_Id_Lparen_Rparen: // <Value> ::= Id '(' <Expr> ')' return new FunctionCallExpression(r.GetData(0).ToString(),r.GetData(2) as Expression); case ProductionIndex.Value_Id_Lparen_Rparen2: // <Value> ::= Id '(' ')' return new FunctionCallExpression(r.GetData(0).ToString()); case ProductionIndex.Value_Id: // <Value> ::= Id if (r.GetData(0).ToString() == "true") { return new DecValue(1); } else if (r.GetData(0).ToString() == "false") { return new DecValue(0); } else return new IdValue(r.GetData(0).ToString()); case ProductionIndex.Value_Lparen_Rparen: // <Value> ::= '(' <Expr> ')' return r.GetData(1) as Expression; } //switch return result; }
private void WriteIdDeclarationStatement(IdDeclarationStatement idDeclarationStatement, StringBuilder programBuilder) { var pos = registerFile.stack.Last().Value.positioninStack; if (idDeclarationStatement.InitializationExpression != null && !(idDeclarationStatement.InitializationExpression is AddExpression)) { registerFile.stackx86.idValue = idDeclarationStatement.InitializationExpression.ToString(); registerFile.stackx86.positioninStack = Convert.ToString(Convert.ToInt32(pos) + 4); savedValue = idDeclarationStatement.Id; registerFile.stack.Add(idDeclarationStatement.Id, registerFile.stackx86); } else if (idDeclarationStatement.InitializationExpression == null) { // registerFile.stackx86.idValue = null; registerFile.stackx86.positioninStack = Convert.ToString(Convert.ToInt32(pos) + 4); //registerFile.savedTemporals.Add(idDeclarationStatement.Id, true); registerFile.stack.Add(idDeclarationStatement.Id, registerFile.stackx86); } else { savedValue = idDeclarationStatement.Id; registerFile.savedTemporals.Add(savedValue, true); } WriteExpr(idDeclarationStatement.InitializationExpression, registerFile, programBuilder); }
private void WriteIdDeclarationStatement(IdDeclarationStatement idDeclarationStatement, StringBuilder programBuilder) { var reg = WriteExpr(idDeclarationStatement.InitializationExpression, registerFile, programBuilder); if (reg == "") { reg = registerFile.FirstAvailableSavedValue(); registerFile.stack1.value = "null";//guardar los valores en la pila registerFile.stack1.id = idDeclarationStatement.Id; registerFile.savedValuesList.Add(reg, registerFile.stack1); } else { registerFile.savedTemporals.Add(reg, idDeclarationStatement.Id); } }
public PartialIdDeclarationStatement(IdDeclarationStatement declarationStatement, ArrayType arrayType) { this.ArrayType = arrayType; this.DeclarationStatement = declarationStatement; }