public void visit(BooleanExpression that) { that.Type = new BooleanType(that.Position); }
public void visit(BooleanExpression that) { Console.Write(that.Value ? "true" : "false"); }
private Declaration[] CreateStandardEnvironment(bool insert = false) { List<Declaration> result = new List<Declaration>(); // signal that the following symbols are part of the standard library Position position = new Position("(library)", 0, 0); Declaration declaration; Expression expression; // enter the predefined constant 'maxint' into the symbol table expression = new IntegerExpression(position, int.MaxValue); declaration = new ConstantDeclaration(position, "maxint", new IntegerType(position), expression); result.Add(declaration); // enter the predefined constants 'false' and 'true' into the symbol table expression = new BooleanExpression(position, false); declaration = new ConstantDeclaration(position, "false", new BooleanType(position), expression); result.Add(declaration); expression = new BooleanExpression(position, true); declaration = new ConstantDeclaration(position, "true", new BooleanType(position), expression); result.Add(declaration); // enter the predefined operators into the symbol table // ... the \ operator declaration = new FunctionDeclaration( position, "\\", new BooleanType(position), new ParameterDeclaration[] { new ParameterDeclaration(position, "value", new BooleanType(position)) }, null // note: the code generator must handle these predefined functions so no body is defined ); result.Add(declaration); // ... all Triangle operators of the form Boolean x Boolean -> Boolean string[] boolean_and_boolean_to_boolean_operators = { "/\\", "\\/", "=", "\\=" }; foreach (string @operator in boolean_and_boolean_to_boolean_operators) { declaration = new FunctionDeclaration( position, @operator, new BooleanType(position), new ParameterDeclaration[] { new ParameterDeclaration(position, "first", new BooleanType(position)), new ParameterDeclaration(position, "other", new BooleanType(position)) }, null // note: the code generator must handle these predefined functions so no body is defined ); result.Add(declaration); } // ... all Triangle operators of the form Integer x Integer -> Integer string[] integer_and_integer_to_integer_operators = { "+", "-", "*", "/", "//" }; foreach (string @operator in integer_and_integer_to_integer_operators) { declaration = new FunctionDeclaration( position, @operator, new IntegerType(position), new ParameterDeclaration[] { new ParameterDeclaration(position, "first", new IntegerType(position)), new ParameterDeclaration(position, "other", new IntegerType(position)) }, null // note: the code generator must handle these predefined functions so no body is defined ); result.Add(declaration); } // ... all Triangle operators of the form Integer x Integer -> Boolean string[] integer_and_integer_to_boolean_operators = { "<", "<=", ">", ">=", "=", "\\=" }; foreach (string @operator in integer_and_integer_to_boolean_operators) { declaration = new FunctionDeclaration( position, @operator, new BooleanType(position), new ParameterDeclaration[] { new ParameterDeclaration(position, "first", new IntegerType(position)), new ParameterDeclaration(position, "other", new IntegerType(position)) }, null // note: the code generator must handle these predefined functions so no body is defined ); result.Add(declaration); } // enter the predefined functions (getint and putint) into the symbol table declaration = new FunctionDeclaration( position, "getint", new IntegerType(position), #if false new ParameterDeclaration[] { new ParameterDeclaration(position, "value", new IntegerType(position))}, #else new ParameterDeclaration[0], #endif null // note: the code generator must handle these predefined functions so no body is defined ); result.Add(declaration); declaration = new FunctionDeclaration( position, "putint", new IntegerType(position), new ParameterDeclaration[] { new ParameterDeclaration(position, "value", new IntegerType(position))}, null // note: the code generator must handle these predefined functions so no body is defined ); result.Add(declaration); return result.ToArray(); }